diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-14 09:24:10 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-14 09:24:10 +0200 |
commit | 12b41ea402aef5b932eb0ba2c123ecd94b48f44f (patch) | |
tree | 7397930967105dd55cb10f05e61dcc1cb7a8fe04 /src/master.c | |
parent | 5257e805a9499229af234180a9d68104a563cf80 (diff) | |
download | biruda-12b41ea402aef5b932eb0ba2c123ecd94b48f44f.tar.gz biruda-12b41ea402aef5b932eb0ba2c123ecd94b48f44f.tar.bz2 |
got a primitive discovery test running
Diffstat (limited to 'src/master.c')
-rw-r--r-- | src/master.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/master.c b/src/master.c index 3deba9e..80ce1a5 100644 --- a/src/master.c +++ b/src/master.c @@ -23,18 +23,25 @@ static void *master_func( void *thread_data ) (void)nn_bind( master_sock, control ); + printf( "master connected to %s\n", control ); + + sleep( 1 ); + + json_object *obj = json_object_new_object( ); + json_object *op = json_object_new_string( "discover" ); + json_object_object_add( obj, "op", op ); + const char *msg = json_object_to_json_string( obj ); + int msg_size = strlen( msg ) + 1; + printf( "master send: %s\n", msg ); + int bytes = nn_send( master_sock, msg, msg_size, 0 ); + if( bytes != msg_size ) { + fprintf( stderr, "ERROR: truncated message!" ); + } + json_object_put( obj ); + while( !master_terminate ) { - json_object *obj = json_object_new_object( ); - json_object *op = json_object_new_string( "discover" ); - json_object_object_add( obj, "op", op ); - const char *msg = json_object_to_json_string( obj ); - int msg_size = strlen( msg ) + 1; - printf( "master send: %s\n", msg ); - int bytes = nn_send( master_sock, msg, msg_size, 0 ); - if( bytes != msg_size ) { - fprintf( stderr, "ERROR: truncated message!" ); - } - json_object_put( obj ); + + printf( "master idle: %d\n", master_terminate ); sleep( 1 ); @@ -42,7 +49,7 @@ static void *master_func( void *thread_data ) bytes = nn_recv( master_sock, &answer, NN_MSG, 0 ); if( bytes == ETIMEDOUT ) continue; if( bytes >= 0 ) { - printf( "master recevied: %s\n", answer ); + printf( "master received: %s\n", answer ); nn_freemsg( answer ); } } |