|
@ -105,33 +105,28 @@ void _LP_sendqueueadd(int32_t sock,uint8_t *msg,int32_t msglen,int32_t peerind) |
|
|
|
|
|
|
|
|
void queue_loop(void *ignore) |
|
|
void queue_loop(void *ignore) |
|
|
{ |
|
|
{ |
|
|
struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,duplicate; |
|
|
struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; |
|
|
while ( 1 ) |
|
|
while ( 1 ) |
|
|
{ |
|
|
{ |
|
|
nonz = 0; |
|
|
nonz = 0; |
|
|
portable_mutex_lock(&LP_networkmutex); |
|
|
portable_mutex_lock(&LP_networkmutex); |
|
|
printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0); |
|
|
//printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0);
|
|
|
|
|
|
n = 0; |
|
|
DL_FOREACH_SAFE(LP_Q,ptr,tmp) |
|
|
DL_FOREACH_SAFE(LP_Q,ptr,tmp) |
|
|
{ |
|
|
{ |
|
|
|
|
|
n++; |
|
|
|
|
|
flag = 0; |
|
|
if ( ptr->sock >= 0 ) |
|
|
if ( ptr->sock >= 0 ) |
|
|
{ |
|
|
{ |
|
|
if ( LP_sockcheck(ptr->sock) > 0 ) |
|
|
if ( LP_sockcheck(ptr->sock) > 0 ) |
|
|
{ |
|
|
{ |
|
|
nonz++; |
|
|
|
|
|
if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) |
|
|
if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) |
|
|
printf("LP_send sent %d instead of %d\n",sentbytes,ptr->msglen); |
|
|
printf("LP_send sent %d instead of %d\n",sentbytes,ptr->msglen); |
|
|
//else printf("qsent %u msglen.%d\n",ptr->crc32,ptr->msglen);
|
|
|
else printf("%p qsent %u msglen.%d\n",ptr,ptr->crc32,ptr->msglen); |
|
|
ptr->sock = -1; |
|
|
ptr->sock = -1; |
|
|
if ( ptr->peerind > 0 ) |
|
|
if ( ptr->peerind > 0 ) |
|
|
ptr->starttime = (uint32_t)time(NULL); |
|
|
ptr->starttime = (uint32_t)time(NULL); |
|
|
else |
|
|
else flag = 1; |
|
|
{ |
|
|
|
|
|
nonz++; |
|
|
|
|
|
DL_DELETE(LP_Q,ptr); |
|
|
|
|
|
LP_Qdequeued++; |
|
|
|
|
|
free(ptr); |
|
|
|
|
|
ptr = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if ( time(NULL) > ptr->starttime+LP_HTTP_TIMEOUT ) |
|
|
else if ( time(NULL) > ptr->starttime+LP_HTTP_TIMEOUT ) |
|
@ -139,27 +134,27 @@ void queue_loop(void *ignore) |
|
|
LP_crc32find(&duplicate,-1,ptr->crc32); |
|
|
LP_crc32find(&duplicate,-1,ptr->crc32); |
|
|
if ( duplicate > 0 ) |
|
|
if ( duplicate > 0 ) |
|
|
{ |
|
|
{ |
|
|
nonz++; |
|
|
|
|
|
printf("found crc32.%u\n",ptr->crc32); |
|
|
printf("found crc32.%u\n",ptr->crc32); |
|
|
LP_Qdequeued++; |
|
|
flag = 1; |
|
|
DL_DELETE(LP_Q,ptr); |
|
|
|
|
|
free(ptr); |
|
|
|
|
|
ptr = 0; |
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
ptr->peerind++; |
|
|
ptr->peerind++; |
|
|
if ( (ptr->sock= LP_peerindsock(&ptr->peerind)) < 0 ) |
|
|
if ( (ptr->sock= LP_peerindsock(&ptr->peerind)) < 0 ) |
|
|
{ |
|
|
{ |
|
|
nonz++; |
|
|
|
|
|
printf("no more peers to try at peerind.%d %p Q_LP.%p\n",ptr->peerind,ptr,LP_Q); |
|
|
printf("no more peers to try at peerind.%d %p Q_LP.%p\n",ptr->peerind,ptr,LP_Q); |
|
|
LP_Qdequeued++; |
|
|
flag = 1; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if ( flag != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
nonz++; |
|
|
DL_DELETE(LP_Q,ptr); |
|
|
DL_DELETE(LP_Q,ptr); |
|
|
|
|
|
LP_Qdequeued++; |
|
|
free(ptr); |
|
|
free(ptr); |
|
|
ptr = 0; |
|
|
ptr = 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
/*if ( ptr != 0 )
|
|
|
/*if ( ptr != 0 )
|
|
|
{ |
|
|
{ |
|
|
printf("reQ.%p: %u msglen.%d (+%d, -%d) -> %d\n",ptr,ptr->crc32,ptr->msglen,LP_Qenqueued,LP_Qdequeued,LP_Qenqueued-LP_Qdequeued); |
|
|
printf("reQ.%p: %u msglen.%d (+%d, -%d) -> %d\n",ptr,ptr->crc32,ptr->msglen,LP_Qenqueued,LP_Qdequeued,LP_Qenqueued-LP_Qdequeued); |
|
@ -168,6 +163,7 @@ void queue_loop(void *ignore) |
|
|
}*/ |
|
|
}*/ |
|
|
} |
|
|
} |
|
|
portable_mutex_unlock(&LP_networkmutex); |
|
|
portable_mutex_unlock(&LP_networkmutex); |
|
|
|
|
|
printf("LP_Q.[%d]\n",n); |
|
|
if ( nonz == 0 ) |
|
|
if ( nonz == 0 ) |
|
|
usleep(10000); |
|
|
usleep(10000); |
|
|
} |
|
|
} |
|
|