|
@ -50,27 +50,31 @@ char *LP_lookup(bits256 pubkey) |
|
|
|
|
|
|
|
|
int32_t LP_pushsock_create(char *pushaddr) |
|
|
int32_t LP_pushsock_create(char *pushaddr) |
|
|
{ |
|
|
{ |
|
|
int32_t pushsock,timeout,i; struct nn_pollfd pfd; |
|
|
int32_t pushsock,timeout,i,n=1000; struct nn_pollfd pfd; |
|
|
if ( (pushsock= nn_socket(AF_SP,NN_PUSH)) < 0 ) |
|
|
if ( (pushsock= nn_socket(AF_SP,NN_PUSH)) < 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("LP_pushsock_create couldnt allocate socket for %s\n",pushaddr); |
|
|
return(-1); |
|
|
return(-1); |
|
|
|
|
|
} |
|
|
else if ( nn_connect(pushsock,pushaddr) < 0 ) |
|
|
else if ( nn_connect(pushsock,pushaddr) < 0 ) |
|
|
{ |
|
|
{ |
|
|
nn_close(pushsock); |
|
|
nn_close(pushsock); |
|
|
|
|
|
printf("LP_pushsock_create couldnt connect to %s\n",pushaddr); |
|
|
return(-1); |
|
|
return(-1); |
|
|
} |
|
|
} |
|
|
timeout = 1; |
|
|
timeout = 1; |
|
|
nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|
|
nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|
|
pfd.fd = pushsock; |
|
|
pfd.fd = pushsock; |
|
|
pfd.events = NN_POLLOUT; |
|
|
pfd.events = NN_POLLOUT; |
|
|
for (i=0; i<1000; i++) |
|
|
for (i=0; i<n; i++) |
|
|
{ |
|
|
{ |
|
|
if ( nn_poll(&pfd,1,1) > 0 ) |
|
|
if ( nn_poll(&pfd,1,1) > 0 ) |
|
|
{ |
|
|
{ |
|
|
printf("HELLO sent.%d bytes\n",LP_send(pushsock,"{\"method\":\"hello\"}",0)); |
|
|
printf("HELLO sent.%d bytes to %s\n",LP_send(pushsock,"{\"method\":\"hello\"}",0),pushaddr); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if ( i == 100 ) |
|
|
if ( i == n ) |
|
|
printf("%d iterations on nn_poll and %s pushsock still not ready\n",i,pushaddr); |
|
|
printf("%d iterations on nn_poll and %s pushsock still not ready\n",i,pushaddr); |
|
|
return(pushsock); |
|
|
return(pushsock); |
|
|
} |
|
|
} |
|
|