c - CZMQ "zsocket_new" router creation always NULL? -


i'm trying create c-zeromq router, seems there problem way i'm making it. router seems initialized null, causes rest of client code fail. tips on why appreciated.

my program based off czmq file transfer model 3 code, when run on system find zsocket_new function create "router" doesn't seem creating "router," when assert(router) program crashes.

i discovered when program started crashing @ zsocket_set_hwm() function few lines later. investigated checking logs , discovered program stopped before managing complete "assert router":

 : zmq: attempting open target file  : zmq: asserting ctx...  : zmq: asserted ctx...  : zmq: router value = 6  : zmq: created router  : zmq: asserting router...... 

next loaded program in gdb , found router keeps initialized 0x0.

(gdb) print ctx $1 = <optimized out> (gdb) print router $2 = (void *) 0x0 (gdb) print complete_address $3 = 0x7fffe80009a0 "tcp://127.0.0.1:6000" 

it seems there's issue declaring router, possibly going wrong code? i'm using corresponding client program reports no problems @ (here's bit of it):

zctx_t *ctx = zctx_new (); void *dealer = zsocket_new (ctx, zmq_dealer);  fprintf(fp_srv_log, "%s : %s\n", time_str, "zmq client thread launched successfully");  zsocket_bind (dealer, "tcp://*:6000");  fprintf(fp_srv_log, "%s : %s\n", time_str, "client: bound tcp://*:6000"); 

and here's offending code, server:

int send_file( void *args, zctx_t *ctx, void *pipe ) {    time_t raw_time;    struct tm* timeinfo;     struct arg_struct *input = (struct arg_struct *)args;    const char *fp = input->file_name;     time( &raw_time );    timeinfo = localtime( &raw_time );    char * time_str = asctime( timeinfo );    char * complete_address = "tcp://127.0.0.1:6000";    file *fp_clnt_log = fopen( "/var/log/mylog.log", "w" );      int chunknum = 0;    fprintf( fp_clnt_log, "%s : zmq: attempting open target file \n", time_str );    file *file_to_xfer = fopen( fp, "r" );    assert( file_to_xfer );     time_str = asctime( timeinfo );     fprintf( fp_clnt_log, "%s : zmq: asserting ctx...\n", time_str );    assert( ctx );    fprintf( fp_clnt_log, "%s : zmq: asserted ctx...\n", time_str );    fprintf( fp_clnt_log, "%s : zmq: router value = %d\n", time_str, zmq_router );    void *router = zsocket_new (ctx, zmq_router);    fprintf( fp_clnt_log, "%s : zmq: created router\n", time_str );    fprintf( fp_clnt_log, "%s : zmq: asserting router......\n", time_str );    assert( router );    fprintf( fp_clnt_log, "%s : zmq: asserted router successfully.\n", time_str );     //two parts per msg hwm size pipeline * 2    zsocket_set_hwm (router, pipeline * 2);    fprintf( fp_clnt_log, "%s : zmq: set hwm complete\n", time_str );     fprintf( fp_clnt_log, "%s : zmq: attempting connect %s\n", time_str, complete_address );    if( 0 == zsocket_connect (router, complete_address ) )    {        fprintf( fp_clnt_log, "%s : zmq: connected %s\n", time_str, complete_address );    }    else    {        fprintf( fp_clnt_log, "%s : zmq: failed connect %s\n", time_str, complete_address );    }    while (true)    {        time( &raw_time );    timeinfo = localtime( &raw_time );    time_str = asctime( timeinfo );     //first frame in each message sender identity    fprintf( fp_clnt_log, "%s : zmq:frame 1\n", time_str );    zframe_t *identity = zframe_recv( router );    fprintf( fp_clnt_log, "%s : zmq clnt: checking identity...\n", time_str );    if (!identity)    {        fprintf( fp_clnt_log, "%s : zmq clnt: no identity, breaking.\n", time_str );        break; //shut down , quit    }     fprintf( fp_clnt_log, "%s : zmq:frame 2\n", time_str );    //second frame 'fetch' command    char *command = zstr_recv (router);    assert (streq (command, "fetch"));    free (command);     fprintf( fp_clnt_log, "%s : zmq:frame 3\n", time_str );    //third frame chunk offset in file    char *offset_str = zstr_recv (router);    size_t offset = atoi (offset_str);    free (offset_str);     fprintf( fp_clnt_log, "%s : zmq:frame 4\n", time_str );    //fourth frame max chunk size    char *chunksz_str = zstr_recv (router);    size_t chunksz = atoi (chunksz_str);    free (chunksz_str);     fprintf( fp_clnt_log, "%s : zmq: reading chunk\n", time_str );    //read chunk of data file    fseek (file_to_xfer, offset, seek_set);    byte *data = malloc (chunksz);    assert (data);     fprintf( fp_clnt_log, "%s : zmq: sending chunk\n", time_str );    //send resulting chunk client    size_t size = fread (data, 1, chunksz, file_to_xfer);    zframe_t *chunk = zframe_new (data, size);    zframe_send (&identity, router, zframe_more);    zframe_send (&chunk, router, 0);    //printf("server: sending chunk %d\n", chunknum);    chunknum++;    }     time( &raw_time );    timeinfo = localtime( &raw_time );    time_str = asctime( timeinfo );     fprintf( fp_clnt_log, "%s : closing file\n", time_str );    fclose( file_to_xfer );    fclose( fp_clnt_log );     return 0;  } 

try checking value of errno or zmq_errno() , use zmq_strerror()

from docs, if socket creation fails null returned , errno set 1 of following :

einval - requested socket type invalid. efault - provided context invalid. emfile - limit on total number of open Ømq sockets has been reached. eterm  - context specified terminated.  

i'd guess scenario context passed send_file invalid.


Comments