Ejemplo n.º 1
0
static void zeromq_beacon_fd_callback(int zeromq_fd, void* datas )
{
//    cloneclient_t* cc = (cloneclient_t*)datas;

//    printf("zeromq_beacon_fd_callback(top)\n");
    
    int opt = 0;
    size_t optsz = sizeof(int);
    zmq_getsockopt( zbeacon_socket (client_beacon), ZMQ_EVENTS, &opt, &optsz );
//    printf("zeromq_beacon_fd_callback(2) opt:%d\n", opt );

    if( opt & ZMQ_POLLIN )
    {
//	printf("zeromq_beacon_fd_callback() have message!\n");

	while( 1 )
	{
	    char *ipaddress = zstr_recv_nowait (zbeacon_socket (client_beacon));
//	    printf("zeromq_beacon_fd_callback() have data? p:%p\n", ipaddress );
	    if( ipaddress )
	    {
//		printf("zeromq_beacon_fd_callback() have message! ip:%s\n", ipaddress );
		zframe_t *content = zframe_recv_nowait (zbeacon_socket (client_beacon));
		if( content )
		{
		    beacon_announce_t* ba = (beacon_announce_t*)zframe_data(content);
//		    printf("uuid:%s\n", ba->uuid );
//		    printf("user:%s\n", ba->username );
//		    printf("mach:%s\n", ba->machinename );

//		    if( ba->version >= 2 && ff_uuid_isValid(ba->uuid) ) {
//			printf("have a beacon back for xuid:%s\n", ba->uuid );
//		    }
		    
		    beacon_announce_t* copy = g_malloc( sizeof(beacon_announce_t));
		    memcpy( copy, ba, sizeof(beacon_announce_t));
		    copy->last_msg_from_peer_time = time(0);
		    copy->port = ntohs( copy->port );
		    strncpy( copy->ip, ipaddress, beacon_announce_ip_sz );
		    g_hash_table_replace( peers, copy->uuid, copy );
		    zframe_destroy (&content);
		}
		free (ipaddress);
	    }
	    else
		break;
	}
    }
    zeromq_beacon_show_peers(0);
}
Ejemplo n.º 2
0
Archivo: zmsg.c Proyecto: jemc/czmq
zmsg_t *
zmsg_recv_nowait (void *source)
{
    assert (source);
    zmsg_t *self = zmsg_new ();
    if (!self)
        return NULL;

    while (true) {
        zframe_t *frame = zframe_recv_nowait (source);
        if (!frame) {
            zmsg_destroy (&self);
            break;              //  Interrupted or terminated
        }
        if (zmsg_append (self, &frame)) {
            zmsg_destroy (&self);
            break;
        }
        if (!zsock_rcvmore (source))
            break;              //  Last message frame
    }
    return self;
}
Ejemplo n.º 3
0
void
worker_fn (void *arg, zctx_t * ctx, void *pipe)
{
  int rc;
  worker_args_t *args = (worker_args_t *) arg;

//connect 
  void *pull = zsocket_new (ctx, ZMQ_PULL);
  rc = zsocket_connect (pull, "inproc://bind_point");

//connect 
  void *sub = zsocket_new (ctx, ZMQ_SUB);
  rc = zsocket_connect (sub, "inproc://pub_point");

//connect 
  void *dealer = zsocket_new (ctx, ZMQ_DEALER);
  rc = zsocket_connect (dealer, "inproc://response_point");

//subscribing to all messages
  zsocket_set_subscribe (sub, "");


  unsigned int counter = 0;
  size_t vallen;
  char *errptr;
  int stop = 0;
  int timeout = 0;


  zmq_pollitem_t pollitem[] = {
    {pull, 0, ZMQ_POLLIN, 0},
    {sub, 0, ZMQ_POLLIN, 0},
  };

  while (1)
    {
      rc = zmq_poll (pollitem, 2, timeout);
      assert (rc != -1);


      if (pollitem[0].revents & ZMQ_POLLIN)
	{
	  unsigned int key;
	  zframe_t *frame = zframe_recv_nowait (pull);
	  memcpy (&key, zframe_data (frame), 4);
	  zframe_destroy (&frame);

	  free (leveldb_get (*(args->db),
			     args->readoptions,
			     (const char *) &key, 4, &vallen, &errptr));
	  counter++;
	}
      else
	{
	  if (stop)
	    {
	      zframe_t *frame = zframe_new (&counter, 4);
	      zframe_send (&frame, dealer, 0);
	      counter = 0;
	      stop = 0;
	    }
	  else
	    {
	      //request more
	      zframe_t *frame = zframe_new ("m", strlen ("m"));
	      zframe_send (&frame, dealer, 0);
              zclock_sleep(1);
	    }
	}

      if (pollitem[1].revents & ZMQ_POLLIN)
	{
	  zframe_t *frame = zframe_recv_nowait (sub);
	  memcpy (&stop, zframe_data (frame), 4);
	  zframe_destroy (&frame);

	}



    }
}
Ejemplo n.º 4
0
void
benchmark_tree (void *push, void *pub, void *router, unsigned int N_KEYS,
		unsigned int *keys, struct dbkey_rb_t dbkey_rb,int N_THREADS
		)
{

/*cleaning cache   */
  system ("./script.sh");



  float stat;
  int64_t diff = zclock_time ();
  unsigned int iter;
  int stop;
  unsigned int counter = 0;
  int more_requested = 0;


  iter = 0;
  while (iter < N_KEYS)
    {
      dbkey_t *dbkey;
      size_t vallen;

      int64_t diff2 = zclock_time ();
      while (1)
	{
          if(zclock_time()-diff2>1){
	  zframe_t *frame = zframe_recv_nowait (router);
	  if (frame != NULL)
	    {
	      zframe_destroy (&frame);
	      frame = zframe_recv_nowait (router);
              
	      if (zframe_size (frame) == strlen ("m"))
		{
	          zframe_destroy (&frame);
		  break;
		}
	    }
            diff2=zclock_time();
          }





	  dbkey = (dbkey_t *) malloc (sizeof (dbkey_t));
	  dbkey->key = keys[iter];


	  RB_INSERT (dbkey_rb_t, &dbkey_rb, dbkey);



	  if (iter == N_KEYS - 1)
	    {
	      iter++;
	      break;
	    }
	  else
	    {

	      iter++;
	    }
	}

      dbkey_t *tr_iter = RB_MIN (dbkey_rb_t, &dbkey_rb);

      while (tr_iter)
	{

	  zframe_t *frame = zframe_new (&(tr_iter->key), 4);
	  zframe_send (&frame, push, 0);


	  dbkey_t *temp = tr_iter;
	  tr_iter = RB_NEXT (dbkey_rb_t, &dbkey_rb, tr_iter);

	  RB_REMOVE (dbkey_rb_t, &dbkey_rb, temp);
	  free (temp);
	}


    }

  stop = 1;
  zframe_t *frame = zframe_new (&stop, 4);
  zframe_send (&frame, pub, 0);

  iter = 0;
  while (iter < N_THREADS)
    {
      unsigned int temp;
      zmsg_t *msg = zmsg_recv (router);
      zframe_t *frame = zmsg_unwrap (msg);
      zframe_destroy (&frame);
      frame=zmsg_first (msg);
      if (zframe_size (frame) == strlen ("m"))
	{
	}
      else
	{
	  memcpy (&temp, zframe_data (frame), 4);
	  counter = counter + temp;
	  iter++;
	}
      zmsg_destroy (&msg);
    }

  printf ("\nkeys processed:%u", counter);

  diff = zclock_time () - diff;

  stat = ((float) counter * 1000) / (float) diff;
  printf ("\nrandom read with an rb_tree:  %f keys per sec\n", stat);

}