mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-22 04:50:06 +00:00
Moved setPollIn flag to sLaika_socket from sLaika_peer
This commit is contained in:
parent
e2e25f5a49
commit
5ece351025
@ -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 */
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 */
|
||||
/* if POLLOUT was set, unset it */
|
||||
laikaP_rmvPollOut(peer->pList, &peer->sock);
|
||||
peer->setPollOut = false;
|
||||
}
|
||||
|
||||
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 :) */
|
||||
/* 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;
|
||||
}
|
||||
|
||||
return true;
|
||||
default: /* panic! */
|
||||
case RAWSOCK_CLOSED:
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user