Esempio n. 1
0
static void database_cache_try_connect(void) {

        memset( &memcached_data, 0, sizeof(memcached_data) );

        memcached_data.mc = mc_new();

        if ( memcached_data.mc ) {
            if ( !mc_server_add(memcached_data.mc, db_server_host, db_server_port) ) {
                memcached_data.active = 1;
            }
        }

        if ( memcached_data.active==0 ) {
            cw_log(LOG_WARNING,"Cannot initialize memcache for server %s:%s.\n", db_server_host, db_server_port);
            if ( memcached_data.mc )
                mc_free(memcached_data.mc);
        }
        else
        {
            cw_log(LOG_NOTICE,"Memcache INITIALIZED\n");
        }


        memcached_data.ctx = mc_global_ctxt();
        mcm_err_filter_del(memcached_data.ctx, MCM_ERR_LVL_INFO);
        mcm_err_filter_del(memcached_data.ctx, MCM_ERR_LVL_NOTICE);
        
        memcached_data.ctx->mcErr = database_cache_error_handler;
        //ctxt->mcHashKey = hash_key;
        //ctxt->mcServerFind = server_find;

        memcached_data.has_error = 0;

}
Esempio n. 2
0
File: Odin.cpp Progetto: llnek/elmo
owner<OdinIO*> reifyJoinRequest(const sstr &room,
    const sstr &user, const sstr &pwd) {
  auto w= mc_new(OdinIO);
  w->setRoomId(room);
  w->setUser(user);
  w->setPasswd(pwd);
  return w;
}
Esempio n. 3
0
File: Odin.cpp Progetto: llnek/elmo
owner<OdinIO*> reifyPlayRequest(const sstr &game,
    const sstr &user, const sstr &pwd) {
  auto w= mc_new(OdinIO);
  w->setGameId(game);
  w->setUser(user);
  w->setPasswd(pwd);
  return w;
}
Esempio n. 4
0
File: Odin.cpp Progetto: llnek/elmo
//////////////////////////////////////////////////////////////////////////////
// Connect to this url and request a websocket upgrade
//
n::WebSocket* connect(not_null<OdinIO*> wss, const sstr &url) {
  auto ws= mc_new(n::WebSocket);
  if (!ws->init(*wss, url)) {
    mc_del_ptr(ws);
  } else {
      wss->setSocket(ws);
  }
  return ws;
}
Esempio n. 5
0
File: Odin.cpp Progetto: llnek/elmo
owner<OdinEvent*> json_decode(const n::WebSocket::Data &e) {

  OdinEvent *evt= mc_new(OdinEvent);
  assert(!e.isBinary);

  try {
    j::json msg;
    msg.parse(e.bytes);
    evt= mc_new1(OdinEvent,msg);
  } catch (...) {
    CCLOGERROR("failed to parse json: %s", "");
  }

  return evt;
}
Esempio n. 6
0
File: day.c Progetto: Zhanyin/taomee
int
main ( int argc, char *argv[] )
{
	struct memcache *mc= mc_new();
	uint32_t value;
	char key[100];
	FILE *fp=fopen("a.txt","r");
	mc_server_add4(mc, "localhost:11211");
	while(feof(fp )){
		fscanf(fp, "%s %d", key, &value );
		DEBUG_LOG("%s",key);
	    mc_set(mc,key, strlen(key), &value , sizeof(value) ,0,0 );
	}
	return 0;
}				/* ----------  end of function main  ---------- */
Esempio n. 7
0
static int l_sipmemcache_new(lua_State *L)
{
  struct sipmemcache *o;

  o = lua_newuserdata(L, sizeof(*o));
  memset(o, '\0', sizeof(*o));
  luaL_getmetatable(L, "siplua.memcache");
  lua_setmetatable(L, -2);
  o->mc = mc_new();
  if (!o->mc)
    {
      lua_remove(L, -1);
      lua_pushnil(L);
    }
  mcErrSetup(sipmemcache_error);
  coin = o;
  return 1;
}
Esempio n. 8
0
int
main(int argc, char *argv[]) {
  struct memcache *mc = NULL;
  int i, ret;
  u_int32_t hash_pre, hash_post;
  void *v;

  mc = mc_new();
  if (mc == NULL)
    err(EX_OSERR, "Unable to allocate a new memcache object");

  mc_server_add4(mc, "localhost:11211");
  warnx("mc_add");

  mc_err_filter_del(MCM_ERR_LVL_INFO);
  mc_err_filter_del(MCM_ERR_LVL_NOTICE);

  ret = mc_add(mc, key, strlen(key), val, strlen(val), 0, 0);
  printf("add %d\n", ret);

  ret = mc_set(mc, key, strlen(key), val, strlen(val), 0, 0);
  hash_pre = mc_hash_key(val, strlen(val));
  printf("set %d\n", ret);

  for (i = 0; i < 10000; i++) {
    v = mc_aget(mc, key, strlen(key));
    if (v != NULL) {
      hash_post = mc_hash_key(v, strlen(v));
      if (hash_post != hash_pre) {
	printf("Hash pre (%u) != post (%u)\n", hash_pre, hash_post);
      }
      free(v);
    } else {
      printf("Return value null on iteration %d\n", i);
    }
  }

  mc_free(mc);

  return EX_OK;
}
Esempio n. 9
0
int
main(int argc, char *argv[]) {
  struct memcache *mc = NULL;
  u_int32_t num_tests = 0, valsize = 0;
  u_int32_t i;
  struct timeval t1, t2;
  const char *key;
  char *tests = NULL;
  char *val;
  u_int32_t keylen;
  double addtime, deltime;
  const char fmt[] = "%s\t%f\t%f\t%f\n";
  struct memcache_req *req;
  struct memcache_res *res;

  if (argc > 1)
    num_tests = strtol(argv[1], NULL, 10);

  if (num_tests == 0)
    num_tests = 10;

  if (argc > 2)
    valsize = strtol(argv[2], NULL, 10);

  if (argc > 3)
    tests = strdup(argv[3]);

  if (tests == NULL)
    tests = strdup("adgs");

  if (valsize == 0)
    valsize = 50;

  val = (char *)malloc(valsize + 1);
  memset(val, 69, valsize);
  val[valsize] = '\0';

  /* XXX I should add a min/max time value for each request */
  printf("Value size:\t%d\n", valsize);
  printf("Num tests:\t%d\n", num_tests);
  printf("Test\tOps per second\tTotal Time\tTime per Request\n");

  key = "bench_key";
  keylen = strlen(key);

  mc = mc_new();
  if (mc == NULL)
    err(EX_OSERR, "Unable to allocate a new memcache object");

  mc_err_filter_del(MCM_ERR_LVL_INFO);
  mc_err_filter_del(MCM_ERR_LVL_NOTICE);

  mc_server_add4(mc, "localhost:11211");

  /* Establish a connection */
  mc_set(mc, key, keylen, val, valsize, 0, 0);

  /* BEGIN set test, if specified */
  if (strchr(tests, (int)'s') != NULL) {
    if (gettimeofday(&t1, NULL) != 0)
      err(EX_OSERR, "gettimeofday(2)");

    for (i = 0; i < num_tests; i++) {
      mc_set(mc, key, keylen, val, valsize, 0, 0);
    }

    if (gettimeofday(&t2, NULL) != 0)
      err(EX_OSERR, "gettimeofday(2)");
    /* END set test */
    printf(fmt, "set", num_tests / tt(&t1, &t2), tt(&t1, &t2), tt(&t1, &t2) / num_tests);
  }


  if (strchr(tests, (int)'g') != NULL) {
    /* BEGIN get request */
    req = mc_req_new();
    res = mc_req_add(req, key, keylen);
    res->size = valsize;
    res->val = malloc(res->size);
    mc_res_free_on_delete(res, 1);

    if (gettimeofday(&t1, NULL) != 0)
      err(EX_OSERR, "gettimeofday(2)");

    for (i = 0; i < num_tests; i++) {
      mc_get(mc, req);
    }

    if (gettimeofday(&t2, NULL) != 0)
      err(EX_OSERR, "gettimeofday(2)");

    mc_req_free(req);
    /* END get test */
    printf(fmt, "get", num_tests / tt(&t1, &t2), tt(&t1, &t2), tt(&t1, &t2) / num_tests);
  }



  if (strchr(tests, 'a') != NULL || strchr(tests, 'd') != NULL) {
    /* Run the add/delete test */
    mc_delete(mc, key, keylen, 0);
    addtime = deltime = 0.0;
    for (i = 0; i < num_tests; i++) {
      /* BEGIN add test */
      if (strchr(tests, 'a') != NULL) {
	if (gettimeofday(&t1, NULL) != 0)
	  err(EX_OSERR, "gettimeofday(2)");

	mc_add(mc, key, keylen, val, valsize, 0, 0);

	if (gettimeofday(&t2, NULL) != 0)
	  err(EX_OSERR, "gettimeofday(2)");

	addtime += tt(&t1, &t2);
	/* END add test */
      }

      /* BEGIN delete test */
      if (strchr(tests, 'd') != NULL) {
	if (gettimeofday(&t1, NULL) != 0)
	  err(EX_OSERR, "gettimeofday(2)");

	mc_delete(mc, key, keylen, 0);

	if (gettimeofday(&t2, NULL) != 0)
	  err(EX_OSERR, "gettimeofday(2)");

	deltime += tt(&t1, &t2);
	/* END delete test */
      }
    }

    if (strchr(tests, 'a') != NULL)
      printf(fmt, "add",    num_tests / addtime, addtime, addtime / num_tests);

    if (strchr(tests, 'd') != NULL)
      printf(fmt, "delete", num_tests / deltime, deltime, deltime / num_tests);
  }


  free(tests);
  free(val);
  mc_free(mc);

  return EX_OK;
}