void ssl_scache_shmht_status(server_rec *s, pool *p, void (*func)(char *, void *), void *arg) { SSLModConfigRec *mc = myModConfig(); void *vpKey; void *vpData; int nKey; int nData; int nElem; int nSize; int nAverage; nElem = 0; nSize = 0; ssl_mutex_on(s); if (table_first(mc->tSessionCacheDataTable, &vpKey, &nKey, &vpData, &nData) == TABLE_ERROR_NONE) { do { if (vpKey == NULL || vpData == NULL) continue; nElem += 1; nSize += nData; } while (table_next(mc->tSessionCacheDataTable, &vpKey, &nKey, &vpData, &nData) == TABLE_ERROR_NONE); } ssl_mutex_off(s); if (nSize > 0 && nElem > 0) nAverage = nSize / nElem; else nAverage = 0; func(ap_psprintf(p, "cache type: <b>SHMHT</b>, maximum size: <b>%d</b> bytes<br>", mc->nSessionCacheDataSize), arg); func(ap_psprintf(p, "current sessions: <b>%d</b>, current size: <b>%d</b> bytes<br>", nElem, nSize), arg); func(ap_psprintf(p, "average session size: <b>%d</b> bytes<br>", nAverage), arg); return; }
static int sse50etf_exec(void *data, void *data2) { RAII_VAR(struct msg *, msg, (struct msg *)data, msg_decr); Quote *quote = (Quote *)msg->data; struct wp *wp; NOT_USED(data2); if (isnan(cru) || isnan(ecc)) { xcb_log(XCB_LOG_WARNING, "No valid value for CRU or ECC"); goto end; } table_lock(contracts); if ((wp = table_get_value(contracts, quote->thyquote.m_cHYDM)) && (isnan(wp->price) || fabs(wp->price - quote->thyquote.m_dZXJ) > 0.000001)) { table_iter_t iter; table_node_t node; double sum = 0.0; time_t t = (time_t)quote->thyquote.m_nTime; struct tm lt; char datestr[64], res[512]; if (wp->type == 2) { table_unlock(contracts); goto end; } wp->price = quote->thyquote.m_dZXJ; iter = table_iter_new(contracts); while ((node = table_next(iter))) { wp = table_node_value(node); if (isnan(wp->price)) { xcb_log(XCB_LOG_WARNING, "No price info for '%s'", table_node_key(node)); table_iter_free(&iter); table_unlock(contracts); goto end; } sum += wp->weight * wp->price; } table_iter_free(&iter); strftime(datestr, sizeof datestr, "%F %T", localtime_r(&t, <)); snprintf(res, sizeof res, "SSE50ETF,%s.%03d|%f", datestr, quote->m_nMSec, (sum + ecc) / cru); out2rmp(res); } table_unlock(contracts); end: return 0; }
/* * dump the table to stdout */ static void dump_table(table_t *tab_p) { int ret, entry_c; long *data_p, *key_p; for (ret = table_first(tab_p, (void **)&key_p, NULL, (void **)&data_p, NULL), entry_c = 0; ret == TABLE_ERROR_NONE; ret = table_next(tab_p, (void **)&key_p, NULL, (void **)&data_p, NULL), entry_c++) { (void)printf("%d: key %ld, data %ld\n", entry_c, *key_p, *data_p); } if (ret != TABLE_ERROR_NOT_FOUND) { (void)fprintf(stderr, "ERROR: first or next key in table: %s\n", table_strerror(ret)); } }
/* * compare the keys in two tables. returns 1 if equal else 0 */ static int test_eq(table_t *tab1_p, table_t *tab2_p, const int verb_b) { int ret, eq = 1, key_size, data1_size, data2_size; void *key_p, *data1_p, *data2_p; /* test the table entries */ for (ret = table_first(tab1_p, (void **)&key_p, &key_size, (void **)&data1_p, &data1_size); ret == TABLE_ERROR_NONE; ret = table_next(tab1_p, (void **)&key_p, &key_size, (void **)&data1_p, &data1_size)) { ret = table_retrieve(tab2_p, key_p, key_size, (void **)&data2_p, &data2_size); if (ret != TABLE_ERROR_NONE) { (void)fprintf(stderr, "could not find key of %d bytes: %s\n", key_size, table_strerror(ret)); eq = 0; } else if (data1_size == data2_size && memcmp(data1_p, data2_p, data1_size) == 0) { if (verb_b) { (void)printf("key of %d bytes, data of %d bytes\n", key_size, data1_size); fflush(stdout); } } else { (void)fprintf(stderr, "ERROR: key of %d bytes: data (size %d) != other " "(size %d)\n", key_size, data1_size, data2_size); eq = 0; } } if (ret != TABLE_ERROR_NOT_FOUND) { eq = 0; } return eq; }
void LuaEngine::loadAllTable() { lua_State *L; char *k=nullptr; char *v=nullptr; std::string path = FileUtils::getInstance()->fullPathForFilename("configure.lua") ; L = luaL_newstate(); luaL_openlibs(L); luaL_dofile(L,path.c_str()); lua_pcall(L,0,0,0); lua_getglobal(L,"hero"); lua_pushnil(L); while (table_next(L,1,&k,&v)!= 0) { log("key is :%s ==== Value is %s",k,v); } lua_close(L); }
/* * try ITERN random program iterations. */ static void stress(table_t *tab_p, const int iter_n, const int mmaping_b) { void *data, *key; int which = 0, mode, weight_total; int iter_c, pnt_c, free_c, ret, ksize, dsize; entry_t *grid, *free_p, *grid_p, *last_p; int linear_b = 0, linear_eof_b = 0; (void)printf("Performing stress tests with %d iterations:\n", iter_n); (void)fflush(stdout); grid = malloc(sizeof(entry_t) * MAX_ENTRIES); if (grid == NULL) { (void)printf("problems allocating space for %d entries.\n", MAX_ENTRIES); exit(1); } /* initialize free list */ free_p = grid; for (grid_p = grid; grid_p < grid + MAX_ENTRIES; grid_p++) { grid_p->en_free_b = 1; grid_p->en_key = NULL; grid_p->en_key_size = 0; grid_p->en_data = NULL; grid_p->en_data_size = 0; grid_p->en_next_p = grid_p + 1; } /* redo the last next pointer */ (grid_p - 1)->en_next_p = NULL; free_c = MAX_ENTRIES; #if 0 /* load the list */ if (mmaping_b) { for (ret = table_first(tab_p, (void **)&key_p, NULL, (void **)&data_p, NULL); ret == TABLE_ERROR_NONE; ret = table_next(tab_p, (void **)&key_p, NULL, (void **)&data_p, NULL)) { } } #endif /* total the weights */ weight_total = 0; for (mode = 0; mode < MODE_MAX; mode++) { weight_total += mode_weights[mode]; } for (iter_c = 0; iter_c < iter_n;) { int weight; /* decide what to do */ weight = RANDOM_VALUE(weight_total) + 1; for (mode = 0; mode < MODE_MAX; mode++) { weight -= mode_weights[mode]; if (weight <= 0) { break; } } /* out of bounds */ if (mode >= MODE_MAX) { continue; } switch (mode) { case MODE_CLEAR: if (mmaping_b || large_b) { continue; } call_c++; table_clear(tab_p); /* re-init free list */ free_p = grid; for (grid_p = grid; grid_p < grid + MAX_ENTRIES; grid_p++) { if (! grid_p->en_free_b) { if (grid_p->en_key != NULL) { free(grid_p->en_key); } if (grid_p->en_data != NULL) { free(grid_p->en_data); } } grid_p->en_free_b = 1; grid_p->en_next_p = grid_p + 1; } /* redo the last next pointer */ (grid_p - 1)->en_next_p = NULL; free_c = MAX_ENTRIES; linear_b = 0; linear_eof_b = 0; iter_c++; if (verbose_b) { (void)printf("table cleared.\n"); fflush(stdout); } break; case MODE_INSERT: if (mmaping_b) { continue; } if (free_c > 0) { which = RANDOM_VALUE(free_c); last_p = NULL; grid_p = free_p; for (pnt_c = 0; pnt_c < which && grid_p != NULL; pnt_c++) { last_p = grid_p; grid_p = grid_p->en_next_p; } if (grid_p == NULL) { (void)printf("reached end of free list prematurely\n"); exit(1); } do { key = random_block(&ksize); } while (key == NULL); data = random_block(&dsize); call_c++; ret = table_insert(tab_p, key, ksize, data, dsize, NULL, 0); if (ret == TABLE_ERROR_NONE) { if (verbose_b) { (void)printf("stored in pos %d: %d, %d bytes of key, data\n", grid_p - grid, ksize, dsize); fflush(stdout); } grid_p->en_free_b = 0; grid_p->en_key = key; grid_p->en_key_size = ksize; grid_p->en_data = data; grid_p->en_data_size = dsize; /* shift free list */ if (last_p == NULL) { free_p = grid_p->en_next_p; } else { last_p->en_next_p = grid_p->en_next_p; } grid_p->en_next_p = NULL; free_c--; iter_c++; } else { for (grid_p = grid; grid_p < grid + MAX_ENTRIES; grid_p++) { if (grid_p->en_free_b) { continue; } if (grid_p->en_key_size == ksize && memcmp(grid_p->en_key, key, ksize) == 0) { break; } } /* if we did not store it then error */ if (grid_p >= grid + MAX_ENTRIES) { (void)fprintf(stderr, "ERROR storing #%d: %s\n", which, table_strerror(ret)); } if (key != NULL) { free(key); } if (data != NULL) { free(data); } } } break; case MODE_OVERWRITE: if (mmaping_b) { continue; } if (free_c < MAX_ENTRIES) { which = RANDOM_VALUE(MAX_ENTRIES); if (grid[which].en_free_b) { continue; } data = random_block(&dsize); call_c++; ret = table_insert(tab_p, grid[which].en_key, grid[which].en_key_size, data, dsize, NULL, 1); if (ret == TABLE_ERROR_NONE) { if (verbose_b) { (void)printf("overwrite pos %d with data of %d bytes\n", which, dsize); fflush(stdout); } grid[which].en_free_b = 0; if (grid[which].en_data != NULL) { free(grid[which].en_data); } grid[which].en_data = data; grid[which].en_data_size = dsize; grid[which].en_next_p = NULL; free_c--; iter_c++; } else { (void)fprintf(stderr, "ERROR overwriting #%d: %s\n", which, table_strerror(ret)); free(data); } } break; case MODE_RETRIEVE: if (free_c < MAX_ENTRIES) { which = RANDOM_VALUE(MAX_ENTRIES); if (grid[which].en_free_b) { continue; } call_c++; ret = table_retrieve(tab_p, grid[which].en_key, grid[which].en_key_size, (void **)&data, &dsize); if (ret == TABLE_ERROR_NONE) { if (grid[which].en_data_size == dsize && memcmp(grid[which].en_data, data, dsize) == 0) { if (verbose_b) { (void)printf("retrieved key #%d, got data of %d bytes\n", which, dsize); fflush(stdout); } } else { (void)fprintf(stderr, "ERROR: retrieve key #%d: data (%d bytes) didn't " "match table (%d bytes)\n", which, grid[which].en_data_size, dsize); } iter_c++; } else { (void)fprintf(stderr, "error retrieving key #%d: %s\n", which, table_strerror(ret)); } } break; case MODE_DELETE: if (mmaping_b) { continue; } if (free_c >= MAX_ENTRIES) { continue; } which = RANDOM_VALUE(MAX_ENTRIES); if (grid[which].en_free_b) { continue; } call_c++; ret = table_delete(tab_p, grid[which].en_key, grid[which].en_key_size, (void **)&data, &dsize); if (ret == TABLE_ERROR_NONE) { if (grid[which].en_data_size == dsize && memcmp(grid[which].en_data, data, dsize) == 0) { if (verbose_b) { (void)printf("deleted key #%d, got data of %d bytes\n", which, dsize); fflush(stdout); } } else { (void)fprintf(stderr, "ERROR deleting key #%d: data didn't match table\n", which); } grid[which].en_free_b = 1; if (grid[which].en_key != NULL) { free(grid[which].en_key); } if (grid[which].en_data != NULL) { free(grid[which].en_data); } grid[which].en_next_p = free_p; free_p = grid + which; free_c++; if (free_c == MAX_ENTRIES) { linear_b = 0; linear_eof_b = 0; } iter_c++; if (data != NULL) { free(data); } } else { (void)fprintf(stderr, "ERROR deleting key %d: %s\n", which, table_strerror(ret)); } break; case MODE_DELETE_FIRST: /* * We have a problem here. This is the only action routine * which modifies the table and is not key based. We don't have * a way of looking up the key in our local data structure. */ break; case MODE_FIRST: call_c++; ret = table_first(tab_p, (void **)&key, &ksize, (void **)&data, &dsize); if (ret == TABLE_ERROR_NONE) { linear_b = 1; linear_eof_b = 0; if (verbose_b) { (void)printf("first entry has key, data of %d, %d bytes\n", ksize, dsize); fflush(stdout); } iter_c++; } else if (free_c == MAX_ENTRIES) { if (verbose_b) { (void)printf("no first in table\n"); fflush(stdout); } } else { (void)fprintf(stderr, "ERROR: first in table: %s\n", table_strerror(ret)); } break; case MODE_NEXT: call_c++; ret = table_next(tab_p, (void **)&key, &ksize, (void **)&data, &dsize); if (ret == TABLE_ERROR_NONE) { if (verbose_b) { (void)printf("next entry has key, data of %d, %d\n", ksize, dsize); fflush(stdout); } iter_c++; } else if (ret == TABLE_ERROR_LINEAR && (! linear_b)) { if (verbose_b) { (void)printf("no first command run yet\n"); fflush(stdout); } } else if (ret == TABLE_ERROR_NOT_FOUND) { if (verbose_b) { (void)printf("reached EOF with next in table: %s\n", table_strerror(ret)); fflush(stdout); } linear_b = 0; linear_eof_b = 1; } else { (void)fprintf(stderr, "ERROR: table_next reports: %s\n", table_strerror(ret)); linear_b = 0; linear_eof_b = 0; } break; case MODE_THIS: call_c++; ret = table_this(tab_p, (void **)&key, &ksize, (void **)&data, &dsize); if (ret == TABLE_ERROR_NONE) { if (verbose_b) { (void)printf("this entry has key,data of %d, %d bytes\n", ksize, dsize); fflush(stdout); } iter_c++; } else if (ret == TABLE_ERROR_LINEAR && (! linear_b)) { if (verbose_b) { (void)printf("no first command run yet\n"); fflush(stdout); } } else if (ret == TABLE_ERROR_NOT_FOUND || linear_eof_b) { if (verbose_b) { (void)printf("table linear already reached EOF\n"); fflush(stdout); } } else { (void)fprintf(stderr, "ERROR: this table: %s\n", table_strerror(ret)); linear_b = 0; linear_eof_b = 0; } break; case MODE_INFO: { int buckets, entries; call_c++; ret = table_info(tab_p, &buckets, &entries); if (ret == TABLE_ERROR_NONE) { if (verbose_b) { (void)printf("table has %d buckets, %d entries\n", buckets, entries); fflush(stdout); } iter_c++; } else { (void)fprintf(stderr, "ERROR: table info: %s\n", table_strerror(ret)); } } break; case MODE_ADJUST: { int buckets, entries; if (mmaping_b || auto_adjust_b || large_b) { continue; } call_c++; ret = table_info(tab_p, &buckets, &entries); if (ret == TABLE_ERROR_NONE) { if (entries == 0) { if (verbose_b) { (void)printf("cannot adjusted table, %d entries\n", entries); fflush(stdout); } } else if (buckets == entries) { if (verbose_b) { (void)printf("no need to adjust table, %d buckets and entries\n", buckets); fflush(stdout); } } else { ret = table_adjust(tab_p, entries); if (ret == TABLE_ERROR_NONE) { (void)printf("adjusted table from %d to %d buckets\n", buckets, entries); iter_c++; } else { (void)printf("ERROR: table adjust to %d buckets: %s\n", entries, table_strerror(ret)); } } } else { (void)fprintf(stderr, "ERROR: table info: %s\n", table_strerror(ret)); } } break; default: (void)printf("unknown mode %d\n", which); break; } } /* run through the grid and free the entries */ for (grid_p = grid; grid_p < grid + MAX_ENTRIES; grid_p++) { if (! grid_p->en_free_b) { if (grid_p->en_key != NULL) { free(grid_p->en_key); } if (grid_p->en_data != NULL) { free(grid_p->en_data); } } } /* free used pointers */ free(grid); }