From d750b1bfc3ab42abf1984a8d5b080a1be3af8dcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 8 Jul 2017 21:45:05 +0300 Subject: [PATCH] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- iguana/exchanges/LP_swap.c | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 85f3e05d2..33b80a63f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -349,7 +349,7 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L int32_t LP_nanobind(void *ctx,char *pairstr) { - int32_t i,timeout,r,pairsock = -1; uint16_t mypullport; char bindaddr[128]; + int32_t i,r,pairsock = -1; uint16_t mypullport; char bindaddr[128]; if ( LP_canbind != 0 ) { if ( (pairsock= nn_socket(AF_SP,NN_PAIR)) < 0 ) @@ -428,7 +428,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t timeout,pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,LP_mypub25519) != 0 ) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index e32d6e275..e282d8cc0 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -400,18 +400,24 @@ int32_t LP_mostprivs_verify(struct basilisk_swap *swap,uint8_t *data,int32_t dat int32_t LP_waitfor(int32_t pairsock,struct basilisk_swap *swap,int32_t timeout,int32_t (*verify)(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)) { - void *data; int32_t datalen,retval = -1; uint32_t expiration = (uint32_t)time(NULL) + timeout; + struct nn_pollfd pfd; void *data; int32_t datalen,retval = -1; uint32_t expiration = (uint32_t)time(NULL) + timeout; while ( time(NULL) < expiration ) { - //printf("start wait\n"); - if ( (datalen= nn_recv(pairsock,&data,NN_MSG,0)) >= 0 ) + memset(&pfd,0,sizeof(pfd)); + pfd.fd = pairsock; + pfd.events = NN_POLLIN; + if ( nn_poll(&pfd,1,1) > 0 ) { - //printf("wait for got.%d\n",datalen); - retval = (*verify)(swap,data,datalen); - nn_freemsg(data); - //printf("retval.%d\n",retval); - return(retval); - } // else printf("error nn_recv\n"); + //printf("start wait\n"); + if ( (datalen= nn_recv(pairsock,&data,NN_MSG,0)) >= 0 ) + { + //printf("wait for got.%d\n",datalen); + retval = (*verify)(swap,data,datalen); + nn_freemsg(data); + //printf("retval.%d\n",retval); + return(retval); + } // else printf("error nn_recv\n"); + } } printf("waitfor timedout\n"); return(retval); @@ -419,13 +425,13 @@ int32_t LP_waitfor(int32_t pairsock,struct basilisk_swap *swap,int32_t timeout,i int32_t swap_nn_send(int32_t sock,uint8_t *data,int32_t datalen,uint32_t flags,int32_t timeout) { - struct nn_pollfd pfd; //int32_t i; - //for (i=0; i 0 ) + pfd.events = NN_POLLOUT; + if ( nn_poll(&pfd,1,1) > 0 ) return(nn_send(sock,data,datalen,flags)); usleep(1000); }