Exemplo n.º 1
0
void* collabclient_new( char* address, int port )
{
#ifdef BUILD_COLLAB

    printf("collabclient_new() address:%s port:%d\n", address, port );
    
    cloneclient_t *cc = 0;
    cc = (cloneclient_t *) zmalloc (sizeof (cloneclient_t));
    cc->magic_number = MAGIC_VALUE;
    cc->ctx   = obtainMainZMQContext();
    cc->loop  = 0;
    cc->address = copy( address );
    cc->port  = port;
    cc->kvmap = zhash_new();
    cc->publisher_sendseq = 1;
    cc->sequence = 0;
    cc->preserveUndo = 0;
    cc->roundTripTimerWaitingSeq = 0;
    collabclient_remakeSockets( cc );

    int32 roundTripTimerMS = pref_collab_roundTripTimerMS;
    cc->roundTripTimer = BackgroundTimer_new( roundTripTimerMS, 
					      collabclient_roundTripTimer,
					      cc );
    
    return cc;

#endif

    return 0;
}
Exemplo n.º 2
0
void
collabclient_closeLocalServer( int port )
{
#ifdef BUILD_COLLAB

    collabclient_sniffForLocalServer_t* cc = &collabclient_sniffForLocalServer_singleton;
    zctx_t* ctx = obtainMainZMQContext();
    int beacon_port = port;
    if( !port )
	port = collabclient_getDefaultBasePort();

    printf("collabclient_closeLocalServer() port:%d\n", port);
    void* socket = zsocket_new ( ctx, ZMQ_REQ );
    zsocket_connect ( socket,
        "tcp://localhost:%d", port+socket_offset_ping);
    zstr_send( socket, "quit" );
    cc->haveServer = 0;

    if( beacon_port )
    {
	g_hash_table_remove_all( peers );
    }
    collabclient_sniffForLocalServer();
    
#endif
}
Exemplo n.º 3
0
void
collabclient_sniffForLocalServer( void )
{
#ifdef BUILD_COLLAB

    memset( &collabclient_sniffForLocalServer_singleton, 0,
	    sizeof(collabclient_sniffForLocalServer_t));
    collabclient_sniffForLocalServer_t* cc = &collabclient_sniffForLocalServer_singleton;

    zctx_t* ctx = obtainMainZMQContext();
    int port_default = collabclient_getDefaultBasePort();

    cc->socket = zsocket_new ( ctx, ZMQ_REQ );
    zsocket_connect (cc->socket,
        "tcp://localhost:%d", port_default+socket_offset_ping);
    cc->timer = BackgroundTimer_new( 1000, collabclient_sniffForLocalServer_timer, cc );
    zstr_send  (cc->socket, "ping");

#endif
}
Exemplo n.º 4
0
void
collabclient_ensureClientBeacon(void)
{
    if( client_beacon )
	return;
    
    peers = g_hash_table_new_full( g_str_hash, g_str_equal, 0, g_free );
    client_beacon_timerID = 0;
    
    
    client_beacon = zbeacon_new( obtainMainZMQContext(), 5670 );
    DEBUG("client beacon address: %s\n", zbeacon_hostname(client_beacon));
    zbeacon_subscribe (client_beacon, NULL, 0);
    zsocket_set_rcvtimeo (zbeacon_socket (client_beacon), 100);
    int fd = 0;
    size_t fdsz = sizeof(fd);
    int rc = zmq_getsockopt( zbeacon_socket(client_beacon), ZMQ_FD, &fd, &fdsz );
//    printf("beacon rc:%d fd:%d\n", rc, fd );
//    GDrawAddReadFD( 0, fd, cc, zeromq_beacon_fd_callback );
    client_beacon_timerID = BackgroundTimer_new( 1000, zeromq_beacon_timer_callback, 0 );
}