diff --git a/lib/include/lpeer.h b/lib/include/lpeer.h index 3fcc6ac..6571f20 100644 --- a/lib/include/lpeer.h +++ b/lib/include/lpeer.h @@ -56,7 +56,6 @@ struct sLaika_peer { OSTYPE osType; int outStart; /* index of pktID for out packet */ int inStart; /* index of pktID for in packet */ - bool setPollOut; /* is EPOLLOUT/POLLOUT is set on sock's pollfd ? */ bool useSecure; /* if true, peer will transmit/receive encrypted data using inKey & outKey */ }; diff --git a/lib/include/lsocket.h b/lib/include/lsocket.h index 5748d42..fbc15f0 100644 --- a/lib/include/lsocket.h +++ b/lib/include/lsocket.h @@ -77,6 +77,7 @@ struct sLaika_socket { int outCap; int inCap; bool flipEndian; + bool setPollOut; /* is EPOLLOUT/POLLOUT is set on sock's pollfd ? */ }; #define laikaS_isAlive(arg) (arg->sock != INVALID_SOCKET) diff --git a/lib/src/lpeer.c b/lib/src/lpeer.c index 0e02c34..ceb986a 100644 --- a/lib/src/lpeer.c +++ b/lib/src/lpeer.c @@ -13,7 +13,6 @@ struct sLaika_peer *laikaS_newPeer(struct sLaika_peerPacketInfo *pktTbl, struct peer->type = PEER_UNKNWN; peer->osType = OS_UNKNWN; peer->pktID = LAIKAPKT_MAXNONE; - peer->setPollOut = false; peer->outStart = -1; peer->inStart = -1; peer->useSecure = false; @@ -238,16 +237,14 @@ bool laikaS_handlePeerOut(struct sLaika_socket *sock) { switch (laikaS_rawSend(&peer->sock, peer->sock.outCount, &sent)) { case RAWSOCK_OK: /* we're ok! */ - if (peer->setPollOut) { /* if POLLOUT was set, unset it */ - laikaP_rmvPollOut(peer->pList, &peer->sock); - peer->setPollOut = false; - } + /* if POLLOUT was set, unset it */ + laikaP_rmvPollOut(peer->pList, &peer->sock); + return true; case RAWSOCK_POLL: /* we've been asked to set the POLLOUT flag */ - if (!peer->setPollOut) { /* if POLLOUT wasn't set, set it so we'll be notified whenever the kernel has room :) */ - laikaP_addPollOut(peer->pList, &peer->sock); - peer->setPollOut = true; - } + /* if POLLOUT wasn't set, set it so we'll be notified whenever the kernel has room :) */ + laikaP_addPollOut(peer->pList, &peer->sock); + return true; default: /* panic! */ case RAWSOCK_CLOSED: diff --git a/lib/src/lpolllist.c b/lib/src/lpolllist.c index 5ebd585..b54e089 100644 --- a/lib/src/lpolllist.c +++ b/lib/src/lpolllist.c @@ -109,6 +109,9 @@ void laikaP_rmvSock(struct sLaika_pollList *pList, struct sLaika_socket *sock) { } void laikaP_addPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock) { + if (sock->setPollOut) + return; + #ifdef LAIKA_USE_EPOLL pList->ev.events = EPOLLIN | EPOLLOUT; pList->ev.data.ptr = (void*)sock; @@ -127,9 +130,14 @@ void laikaP_addPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock } } #endif + + sock->setPollOut = true; } void laikaP_rmvPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock) { + if (!sock->setPollOut) + return; + #ifdef LAIKA_USE_EPOLL pList->ev.events = EPOLLIN; pList->ev.data.ptr = (void*)sock; @@ -148,6 +156,8 @@ void laikaP_rmvPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock } } #endif + + sock->setPollOut = false; } void laikaP_pushOutQueue(struct sLaika_pollList *pList, struct sLaika_socket *sock) { diff --git a/lib/src/lsocket.c b/lib/src/lsocket.c index f080dcc..2a0680f 100644 --- a/lib/src/lsocket.c +++ b/lib/src/lsocket.c @@ -50,6 +50,7 @@ void laikaS_initSocket(struct sLaika_socket *sock, pollEvent onPollIn, pollEvent sock->outCap = ARRAY_START; sock->outCount = 0; sock->flipEndian = false; + sock->setPollOut = false; laikaS_init(); }