2 #include <dragontype/number.h>
10 #include "recv_thread.h"
12 void *dragonnet_peer_recv_thread(void *g_peer)
14 DragonnetPeer *p = (DragonnetPeer *) g_peer;
16 pthread_rwlock_wrlock(&p->mu);
17 assert(p->state == DRAGONNET_PEER_CREATED);
19 pthread_rwlock_unlock(&p->mu);
24 pthread_rwlock_rdlock(&p->mu);
25 ssize_t len = recv(p->sock, &msg, sizeof msg, MSG_WAITALL);
26 pthread_rwlock_unlock(&p->mu);
28 if (len < 0 && errno != EWOULDBLOCK) {
30 dragonnet_peer_delete(p);
35 if ((len >= 0 && len != sizeof msg) || errno == EWOULDBLOCK) {
36 pthread_rwlock_wrlock(&p->mu);
42 pthread_rwlock_unlock(&p->mu);