|
|
@ -50,27 +50,31 @@ char *LP_lookup(bits256 pubkey) |
|
|
|
|
|
|
|
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 ) |
|
|
|
{ |
|
|
|
printf("LP_pushsock_create couldnt allocate socket for %s\n",pushaddr); |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
else if ( nn_connect(pushsock,pushaddr) < 0 ) |
|
|
|
{ |
|
|
|
nn_close(pushsock); |
|
|
|
printf("LP_pushsock_create couldnt connect to %s\n",pushaddr); |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
timeout = 1; |
|
|
|
nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|
|
|
pfd.fd = pushsock; |
|
|
|
pfd.events = NN_POLLOUT; |
|
|
|
for (i=0; i<1000; i++) |
|
|
|
for (i=0; i<n; i++) |
|
|
|
{ |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( i == 100 ) |
|
|
|
if ( i == n ) |
|
|
|
printf("%d iterations on nn_poll and %s pushsock still not ready\n",i,pushaddr); |
|
|
|
return(pushsock); |
|
|
|
} |
|
|
|