static void ramcloudRead(void *item, void *data) { wstr i = *(wstr*)item; struct ramcloudData *d = data; uint32_t actual_len; uint64_t version; uint64_t len = RAMCLOUD_DEFAULT_VALUE_LEN; wheatLog(WHEAT_DEBUG, "%s read key %s", __func__, i); wstr val = wstrNewLen(NULL, len); Status s = rc_read(global.client, d->table_id, i, wstrlen(i), NULL, &version, val, len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", i, statusToString(s)); } wstrFree(val); return ; } while (actual_len > len) { wstrFree(val); len = actual_len; val = wstrNewLen(NULL, actual_len); if (val == NULL) { wheatLog(WHEAT_WARNING, " failed to alloc memory"); return ; } s = rc_read(global.client, d->table_id, i, wstrlen(i), NULL, &version, val, len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", i, statusToString(s)); } wstrFree(val); return ; } } d->retrieval_len += actual_len; arrayPush(d->retrievals, &val); struct slice ss = {(uint8_t*)(i), wstrlen(i)}; arrayPush(d->retrievals_keys, &ss); ss.data = (uint8_t*)val; ss.len = actual_len - FLAG_SIZE; arrayPush(d->retrievals_vals, &ss); arrayPush(d->retrievals_flags, &val[actual_len-FLAG_SIZE]); arrayPush(d->retrievals_versions, &version); }
int initRamcloud(struct protocol *p) { char *locator; char *cluster_name; struct configuration *conf; conf = getConfiguration("ramcloud-server-locator"); locator = conf->target.ptr; conf = getConfiguration("ramcloud-cluster-name"); cluster_name = conf->target.ptr; if (!locator || !cluster_name) { wheatLog(WHEAT_WARNING, "%s lack of necessary config", __func__); goto err; } Status s = rc_connect(locator, cluster_name, &global.client); if (s != STATUS_OK) { wheatLog(WHEAT_WARNING, "%s connect to %s: %s", __func__, locator, statusToString(s)); goto err; } global.tables = dictCreate(&intDictType); ASSERT(gethostname(hostname, 255)); wheatLog(WHEAT_NOTICE, "%s hostname is %s", __func__, hostname); return WHEAT_OK; err: return WHEAT_WRONG; }
static int ProcessRequest(lua_State *L, ModbusUserData* pModbusUserData, uint8_t isCustom) { uint8_t* pBuffer = NULL; uint16_t bufferLength = 0; SerialStatus status; if (isCustom) { status = MODBUS_SER_CreateCustomRequest(&(pModbusUserData->serializer), &(pModbusUserData->request)); } else { status = MODBUS_SER_CreateRequest(&(pModbusUserData->serializer), &(pModbusUserData->request)); } if (status != SERIAL_STATUS_OK) { if (pModbusUserData->allocated != NULL) { free(pModbusUserData->allocated); pModbusUserData->allocated = NULL; } lua_pushnil(L); lua_pushstring(L, statusToString(status)); return 2; } else { MODBUS_SER_GetRequestPDU(&(pModbusUserData->serializer), &pBuffer, &bufferLength); lua_pushlstring(L, (const char*) pBuffer, (size_t) bufferLength); lua_pushinteger(L, MODBUS_SER_GetExpectedResponseLength(&(pModbusUserData->serializer))); return 2; } }
QString ChatClient::statusType() const { if (clientPresence().type() == QXmppPresence::Available) return statusToString(clientPresence().availableStatusType()); else return "offline"; }
std::string TaskDeadline::taskDetailsToString() { std::ostringstream output; output << getTaskDesc() << std::endl; output << dateTimeToString() << std::endl; output << statusToString() << std::endl; return output.str(); }
static void ramcloudSet(struct ramcloudData *d, wstr key, struct array *vals, uint32_t vlen, uint16_t flag, struct RejectRules *rule) { wheatLog(WHEAT_DEBUG, "%s set key %s", __func__, key); uint64_t version; int i = 0; struct slice *slice; wstr val = wstrNewLen(NULL, vlen+sizeof(flag)); while (i < narray(vals)) { slice = arrayIndex(vals, i); val = wstrCatLen(val, (char*)slice->data, slice->len); ++i; } val = wstrCatLen(val, (char*)&flag, FLAG_SIZE); Status s = rc_write(global.client, d->table_id, key, wstrlen(key), val, wstrlen(val), rule, &version); wstrFree(val); if (s != STATUS_OK) { // cas command if (rule->versionNeGiven) { if (s == STATUS_WRONG_VERSION) sliceTo(&d->storage_response, (uint8_t*)EXISTS, sizeof(EXISTS)-1); else if (s == STATUS_OBJECT_DOESNT_EXIST) sliceTo(&d->storage_response, (uint8_t*)NOT_FOUND, sizeof(NOT_FOUND)-1); } else if ((rule->doesntExist && s == STATUS_OBJECT_DOESNT_EXIST) || (rule->exists && s == STATUS_OBJECT_EXISTS)) { sliceTo(&d->storage_response, (uint8_t*)NOT_STORED, sizeof(NOT_STORED)-1); } else { wheatLog(WHEAT_WARNING, "%s failed to set %s: %s", __func__, key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); } } else { sliceTo(&d->storage_response, (uint8_t*)STORED, sizeof(STORED)-1); } }
std::string TaskDeadline::outputToString() { std::ostringstream output; output << getTaskType() << "<>"; output << getTaskDesc() << "<>"; output << _deadline.dateToString(true) << " " << _deadline.timeToString() << "<>"; output << statusToString() << std::endl; return output.str(); }
string Task::toString(){ string outputString; //outputString = TYPE_KEY_WORD + typeToString() + NEW_LINE; outputString = TITLE_KEY_WORD + _title + NEW_LINE; outputString += STATUS_KEY_WORD + statusToString() + NEW_LINE; outputString += START_KEY_WORD + startToString() + NEW_LINE; outputString += END_KEY_WORD + endToString() + NEW_LINE; outputString += COMMENT_KEY_WORD + _comment; return outputString; }
vector<string> Task::toStringVector(){ vector<string> stringVector; string s[6] = {"Type: " + typeToString(), "Title: " + _title, "Status: " + statusToString(), "Start: " + startToString(), "End: " + endToString(), "Comment: " + _comment}; for(unsigned int i = 0; i < 6; i++){ stringVector.push_back(s[i]); } return stringVector; }
std::string errorTypeToString( uChar errorType ) { // Bottom two bits are the same as status stringstream ss; ss << statusToString( errorType && 0x03 ); if ( errorType & ERROR_TYPE_NO_LONGER_RELEVANT_MASK ) { ss << " (no longer relevant)"; } else { ss << " (still relevant)"; } return ss.str(); }
static void ramcloudDelete(struct ramcloudData* d, wstr key, struct RejectRules *rule) { wheatLog(WHEAT_DEBUG, "%s delete key %s", __func__, key); uint64_t version; Status s = rc_remove(global.client, d->table_id, key, wstrlen(key), rule, &version); if (s != STATUS_OK) { if (s == STATUS_OBJECT_DOESNT_EXIST) { sliceTo(&d->storage_response, (uint8_t*)NOT_FOUND, sizeof(NOT_FOUND)-1); } else { wheatLog(WHEAT_WARNING, "%s failed to remove %s: %s", __func__, key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); } } else { sliceTo(&d->storage_response, (uint8_t*)DELETED, sizeof(DELETED)-1); } }
void ImageListModelProxy::add(ImageListItem item) { QList<QStandardItem*> list = createRow(); QStringList strList; strList << item.name() << item.path() << item.size() << statusToString(m_initStatus); qDebug() << strList; for(int i = 0; i < c_columnCount; ++i) { list.at(i)->setText(strList.at(i)); } if(m_model == NULL) { qDebug() << "Internal Error#m_model is NULL."; return; } m_model->appendRow(list); }
static int l_MODBUS_InitContext(lua_State *L) { SerialStatus status = SERIAL_STATUS_UNEXPECTED_ERROR; ModbusRequestMode mode = MODBUS_RTU; // store a modbuscontext address ModbusUserData* pModbusUserData = (ModbusUserData*) lua_newuserdata(L, sizeof(ModbusUserData)); memset(pModbusUserData, 0, sizeof(ModbusUserData)); // set its metatable luaL_getmetatable(L, MODULE_NAME); lua_setmetatable(L, -2); if (!lua_isnil(L, 1)) { if (!lua_isstring(L, 1)) { luaL_error(L, "'mode' should be 'RTU', 'ASCII' or 'TCP'\n"); } else { const char* strMode = lua_tostring(L, 1); if (strcmp(strMode, MODE_RTU) == 0) { mode = MODBUS_RTU; } else if (strcmp(strMode, MODE_ASCII) == 0) { mode = MODBUS_ASCII; } else if (strcmp(strMode, MODE_TCP) == 0) { mode = MODBUS_TCP; } else { luaL_error(L, "'mode' should be 'RTU', 'ASCII' or 'TCP'\n"); } } } status = MODBUS_SER_InitSerializer(&(pModbusUserData->serializer), (void*)mode); if (status != SERIAL_STATUS_OK) { MODBUS_SER_ReleaseSerializer(&(pModbusUserData->serializer)); lua_pushnil(L); lua_pushstring(L, statusToString(status)); return 2; } else { return 1; } }
/*! \qmlproperty string NetworkInfo::networkStatus Returns this NetworkInfo's network status. */ QString QDeclarativeNetworkInfo::networkStatus() { return statusToString(QSystemNetworkInfo::networkStatus(m_mode)); }
/*! \internal This function is called when the client connects from the networkSignalStrengthChanged() notification. \sa connectNotify() */ void QDeclarativeNetworkInfo::networkStatusChanged(QSystemNetworkInfo::NetworkMode mode, QSystemNetworkInfo::NetworkStatus status) { if(mode == m_mode) { Q_EMIT statusChanged(statusToString(status)); } }
static int l_MODBUS_ReceiveResponse(lua_State *L) { char charTab[80] = { 0 }; uint8_t n = 0; size_t bufferLength = 0; ModbusUserData* pModbusUserData = (ModbusUserData *) luaL_checkudata(L, 1, MODULE_NAME); const char* buffer = luaL_checklstring(L, 2, &bufferLength); ModbusSpecifics *pSpecifics = (ModbusSpecifics*)pModbusUserData->serializer.pSpecifics; // copy to response buffer memset(pModbusUserData->serializer.pResponseBuffer, 0, pModbusUserData->serializer.responseBufferLength * sizeof(uint8_t)); memcpy(pModbusUserData->serializer.pResponseBuffer, buffer, bufferLength); pModbusUserData->serializer.responseBufferLength = bufferLength; // extract data from response SerialStatus status = MODBUS_SER_AnalyzeResponse(&(pModbusUserData->serializer), MODBUS_SER_CheckResponse(&(pModbusUserData->serializer))); // push results switch (status) { case SERIAL_STATUS_OK: if (pSpecifics->isCustom) { lua_pushlstring(L, pSpecifics->response.value.pValues, pSpecifics->response.byteCount); n = 1; break; } switch (pSpecifics->response.function) { case MODBUS_FUNC_READ_COILS: case MODBUS_FUNC_READ_DISCRETE_INPUTS: case MODBUS_FUNC_READ_HOLDING_REGISTERS: case MODBUS_FUNC_READ_INPUT_REGISTERS: case MODBUS_FUNC_SEND_RAW_DATA: // push read result lua_pushlstring(L, pSpecifics->response.value.pValues, pSpecifics->response.byteCount); n = 1; break; case MODBUS_FUNC_WRITE_SINGLE_COIL: case MODBUS_FUNC_WRITE_SINGLE_REGISTER: case MODBUS_FUNC_WRITE_MULTIPLE_COILS: case MODBUS_FUNC_WRITE_MULTIPLE_REGISTERS: // push status lua_pushstring(L, "ok"); n = 1; break; default: // push nil lua_pushnil(L); // push error string lua_pushstring(L, "modbus response error unhandled function"); n = 2; break; } break; case SERIAL_STATUS_RESPONSE_EXCEPTION: // push nil lua_pushnil(L); // push error string sprintf(charTab, "%s - %s", statusToString(status), MODBUS_SER_GetExceptionString(pSpecifics->response.exception)); lua_pushstring(L, charTab); n = 2; break; default: // push nil lua_pushnil(L); // push error string lua_pushstring(L, statusToString(status)); n = 2; break; } // free value if (pModbusUserData->allocated != NULL) { free(pModbusUserData->allocated); pModbusUserData->allocated = NULL; } return n; }
// 该函数由主线程中的定时器调用 void ServerManager::buildStatus() { // 因为在子线程中也会读取 json_ 对象,所以对单例成员变量 // json_ 进行加锁保护,为了防止主线程被长期阻塞在锁上,所以 // 采用了尝试加锁方式 if (lock_.try_lock() == false) return; json_.reset(); xml_.reset(); acl::json_node& json_servers = json_.create_array(); json_.get_root().add_child("server", json_servers); acl::xml_node& xml_servers = xml_.create_node("server"); xml_.get_root().add_child(xml_servers); long long total_conns = 0, total_used = 0, total_qlen = 0; long long total_max_threads = 0, total_curr_threads = 0; long long total_busy_threads = 0; acl::string load_s; (void) sysload::get_load(&load_s); // 获得当前系统的负载 std::vector<ServerConnection*>::const_iterator cit = conns_.begin(); for (; cit != conns_.end(); ++cit) { total_conns += (*cit)->get_conns(); total_used += (*cit)->get_used(); total_qlen += (*cit)->get_qlen(); total_max_threads += (*cit)->get_max_threads(); total_curr_threads += (*cit)->get_curr_threads(); total_busy_threads += (*cit)->get_busy_threads(); acl::json_node& json_server = json_.create_node(); json_server.add_number("conns", (*cit)->get_conns()) .add_number("used", (*cit)->get_used()) .add_number("pid", (*cit)->get_pid()) .add_number("max_threads", (*cit)->get_max_threads()) .add_number("curr_threads", (*cit)->get_curr_threads()) .add_number("busy_threads", (*cit)->get_busy_threads()) .add_number("qlen", (*cit)->get_qlen()) .add_text("type", (*cit)->get_type()); json_servers.add_child(json_server); xml_servers.add_child("proc", true) .add_child("conns", (long long int) (*cit)->get_conns()) .add_child("used", (long long int) (*cit)->get_used()) .add_child("pid", (long long int) (*cit)->get_pid()) .add_child("max_threads", (long long int) (*cit)->get_max_threads()) .add_child("curr_threads", (long long int) (*cit)->get_curr_threads()) .add_child("busy_threads", (long long int) (*cit)->get_busy_threads()) .add_child("qlen", (long long int) (*cit)->get_qlen()) .add_child("type", (*cit)->get_type().c_str()); } json_.get_root().add_number("conns", total_conns) .add_number("used", total_used) .add_number("qlen", total_qlen) .add_number("max_threads", total_max_threads) .add_number("curr_threads", total_curr_threads) .add_number("busy_threads", total_busy_threads) .add_text("addr", var_cfg_local_addr.c_str()) .add_text("load", load_s.c_str()); xml_servers.add_attr("conns", total_conns) .add_attr("used", total_used) .add_attr("qlen", total_qlen) .add_attr("max_threads", total_max_threads) .add_attr("curr_threads", total_curr_threads) .add_attr("busy_threads", total_busy_threads) .add_attr("addr", var_cfg_local_addr.c_str()) .add_attr("load", load_s.c_str()); #if 0 acl::json_node& n = json_.create_node(); n.add_number("conns", 1).add_number("used", 2) .add_number("pid", 1).add_number("max_threads", 10) .add_number("curr_threads", 1).add_number("busy_threads", 2) .add_number("qlen", 0).add_text("type", "default"); servers.add_child(n); acl::json_node& m = json_.create_node(); m.add_number("conns", 2).add_number("used", 3) .add_number("pid", 2).add_number("max_threads", 10) .add_number("curr_threads", 2).add_number("busy_threads", 1) .add_number("qlen", 0).add_text("type", "default"); servers.add_child(m); acl::string buf; statusToString(buf); printf(">>>buf: %s\r\n", buf.c_str()); #endif lock_.unlock(); }
static int getTableId(int owner, uint64_t *table_id) { struct dictEntry *entry = dictFind(global.tables, (void*)(intptr_t)owner); if (entry) { *table_id = dictGetUnsignedIntegerVal(entry); return WHEAT_OK; } else { char name[256]; int l = sprintf(name, "%s_%d", hostname, owner); name[l] = '\0'; Status s = rc_getTableId(global.client, name, table_id); if (s != STATUS_OK) { if (s == STATUS_TABLE_DOESNT_EXIST) { wheatLog(WHEAT_DEBUG, "%s table %s not exists, create it, s", __func__, name); s = rc_createTable(global.client, name, 1); if (s != STATUS_OK) { wheatLog(WHEAT_WARNING, "%s failed to create table %s: %s", __func__, name, statusToString(s)); return WHEAT_WRONG; } s = rc_getTableId(global.client, name, table_id); } if (s != STATUS_OK) { wheatLog(WHEAT_WARNING, "%s failed to get table %s: %s", __func__, name, statusToString(s)); return WHEAT_WRONG; } } dictAdd(global.tables, name, (void*)(intptr_t)(*table_id)); return WHEAT_OK; } }
void QPkBackend::slotUpdateProgress() { Q_EMIT progress(statusToString(m_t->status()), m_t->percentage()); }
static void ramcloudAppend(struct ramcloudData *d, wstr key, struct array *vals, uint32_t vlen, uint16_t flag, int append) { uint32_t actual_len; uint64_t version; uint64_t len = RAMCLOUD_DEFAULT_VALUE_LEN; again: wheatLog(WHEAT_DEBUG, "%s read key %s", __func__, key); wstr origin_val = wstrNewLen(NULL, len); wstr val; Status s = rc_read(global.client, d->table_id, key, wstrlen(key), NULL, &version, origin_val, len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); } else { sliceTo(&d->storage_response, (uint8_t*)NOT_STORED, sizeof(NOT_STORED)-1); } wstrFree(origin_val); return ; } while (actual_len > len) { wstrFree(origin_val); len = actual_len; origin_val = wstrNewLen(NULL, actual_len); if (origin_val == NULL) { sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); wheatLog(WHEAT_WARNING, " failed to alloc memory"); return ; } s = rc_read(global.client, d->table_id, key, wstrlen(key), NULL, &version, origin_val, len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); } else { sliceTo(&d->storage_response, (uint8_t*)NOT_STORED, sizeof(NOT_STORED)-1); } wstrFree(origin_val); return ; } } wstrupdatelen(origin_val, actual_len-FLAG_SIZE); if (append) { val = origin_val; // reduce flag size } else { val = wstrNewLen(NULL, vlen); } int i = 0; while (i < narray(vals)) { struct slice *slice; slice = arrayIndex(vals, i); val = wstrCatLen(val, (char*)slice->data, slice->len); len += slice->len; ++i; } if (!append) { val = wstrCatLen(val, origin_val, wstrlen(origin_val)); wstrFree(origin_val); } val = wstrCatLen(val, (char*)&flag, FLAG_SIZE); struct RejectRules rule; memset(&rule, 0, sizeof(rule)); rule.doesntExist = 1; rule.versionNeGiven = 1; rule.givenVersion = version; s = rc_write(global.client, d->table_id, key, wstrlen(key), val, wstrlen(val), &rule, NULL); wstrFree(val); if (s != STATUS_OK) { if (s == STATUS_OBJECT_DOESNT_EXIST) { sliceTo(&d->storage_response, (uint8_t*)NOT_STORED, sizeof(NOT_STORED)-1); return ; } else if (s == STATUS_WRONG_VERSION) { goto again; } wheatLog(WHEAT_WARNING, " failed to write %s: %s", key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); return ; } sliceTo(&d->storage_response, (uint8_t*)STORED, sizeof(STORED)-1); }
bool GetParameterIn::operator()(void) { if (m_parameter.compare("hello") == 0) { m_response = "Welcome to SAN node terminal"; return true; } if (m_parameter.compare("hostname") == 0) { m_response = m_node.getNodeName(); return true; } if (m_parameter.compare("uptime") == 0) { unsigned long uptimeSec = m_node.getUptimeSec(); unsigned long uptimeDays = (uptimeSec - (uptimeSec % 86400)) / 86400; uptimeSec %= 86400; unsigned long uptimeHours = (uptimeSec - (uptimeSec % 3600)) / 3600; uptimeSec %= 3600; unsigned long uptimeMin = (uptimeSec - (uptimeSec % 60)) / 60; uptimeSec %= 60; std::string tmp; tmp = San2::Utils::CStringUtils::ulongToString(uptimeDays) + "d " + San2::Utils::CStringUtils::ulongToString(uptimeHours) + "h " + San2::Utils::CStringUtils::ulongToString(uptimeMin) + "m " + San2::Utils::CStringUtils::ulongToString(uptimeSec) + "s"; m_response = tmp; return true; } if (m_parameter.compare("version") == 0) { m_response = "SAN Node v1.0"; return true; } if (m_parameter.compare("peers") == 0) { std::set<std::shared_ptr<San2::Network::CNetInterface> > ifaces = m_node.getInterfaces(); m_response = ""; for(auto s: ifaces) { m_response += "IFACE status RX:"; m_response += statusToString(s->getRXstate()); m_response += " TX:"; m_response += statusToString(s->getTXstate()); m_response += "\n>> iadr: "; m_response += San2::Utils::address2string(s->getInterfaceAddress()).c_str(); m_response += "\n>> peer: "; m_response += San2::Utils::address2string(s->getPeerAddress()).c_str(); m_response += "\n\n"; } return true; } m_response = "Unknown parameter " + m_parameter; return true; }
String MoveWithResult::toString() const { return format(_T("{%-5s}:%s"), setToString(*m_move).cstr(), statusToString(m_status).cstr()); }
static void ramcloudIncr(struct ramcloudData *d, wstr key, uint64_t num, int positive) { if (num > INT64_MAX) { wheatLog(WHEAT_WARNING, "%s num %ld can't larger than %ld", __func__, num, INT64_MAX); sliceTo(&d->storage_response, (uint8_t*)CLIENT_ERROR, sizeof(CLIENT_ERROR)-1); return ; } static int max_len = 100; char value[max_len]; uint32_t actual_len; uint64_t version; uint16_t flag; again: wheatLog(WHEAT_DEBUG, "%s incr key %s %ld", __func__, key, num); Status s = rc_read(global.client, d->table_id, key, wstrlen(key), NULL, &version, value, max_len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); } else { sliceTo(&d->storage_response, (uint8_t*)NOT_FOUND, sizeof(NOT_FOUND)-1); } return ; } if (actual_len > max_len) { sliceTo(&d->storage_response, (uint8_t*)CLIENT_ERROR, sizeof(CLIENT_ERROR)-1); return ; } flag = *(uint16_t*)&value[actual_len-FLAG_SIZE]; value[actual_len-FLAG_SIZE] = '\0'; long long n = atoll(value); if (n == 0) { if (value[0] != '0') { sliceTo(&d->storage_response, (uint8_t*)CLIENT_ERROR, sizeof(CLIENT_ERROR)-1); return ; } } if (positive) { n += num; } else { if (num > n) n = 0; else n -= num; } int l = sprintf(value, "%llu", n); memcpy(&value[l], &flag, FLAG_SIZE); struct RejectRules rule; memset(&rule, 0, sizeof(rule)); rule.doesntExist = 1; rule.versionNeGiven = 1; rule.givenVersion = version; s = rc_write(global.client, d->table_id, key, wstrlen(key), value, l+FLAG_SIZE, &rule, &version); if (s != STATUS_OK) { if (s == STATUS_WRONG_VERSION) { goto again; } if (s == STATUS_OBJECT_DOESNT_EXIST) { sliceTo(&d->storage_response, (uint8_t*)NOT_FOUND, sizeof(NOT_FOUND)-1); return ; } sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); wheatLog(WHEAT_WARNING, "%s failed to incr %s: %s", __func__, key, statusToString(s)); return ; } else { l = sprintf(value, "%llu\r\n", n); d->retrieval_response = wstrNewLen(value, l); sliceTo(&d->storage_response, (uint8_t*)d->retrieval_response, wstrlen(d->retrieval_response)); } }