mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-21 20:40:05 +00:00
Switched Shell & Bot to use laikaP_flushOutQueue()
- they both now have handlers for onPollFail
This commit is contained in:
parent
7baced7b8f
commit
541e75f183
@ -33,6 +33,14 @@ struct sLaika_peerPacketInfo laikaB_pktTbl[LAIKAPKT_MAXNONE] = {
|
|||||||
true),
|
true),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* socket event */
|
||||||
|
void laikaB_onPollFail(struct sLaika_socket *sock, void *uData) {
|
||||||
|
struct sLaika_peer *peer = (struct sLaika_peer*)sock;
|
||||||
|
struct sLaika_bot *bot = (struct sLaika_bot*)uData;
|
||||||
|
|
||||||
|
laikaS_kill(&bot->peer->sock);
|
||||||
|
}
|
||||||
|
|
||||||
/* ==================================================[[ Bot ]]=================================================== */
|
/* ==================================================[[ Bot ]]=================================================== */
|
||||||
|
|
||||||
struct sLaika_bot *laikaB_newBot(void) {
|
struct sLaika_bot *laikaB_newBot(void) {
|
||||||
@ -47,8 +55,8 @@ struct sLaika_bot *laikaB_newBot(void) {
|
|||||||
bot->peer = laikaS_newPeer(
|
bot->peer = laikaS_newPeer(
|
||||||
laikaB_pktTbl,
|
laikaB_pktTbl,
|
||||||
&bot->pList,
|
&bot->pList,
|
||||||
NULL,
|
laikaB_onPollFail,
|
||||||
NULL,
|
(void*)bot,
|
||||||
(void*)bot
|
(void*)bot
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -128,31 +136,20 @@ void laikaB_connectToCNC(struct sLaika_bot *bot, char *ip, char *port) {
|
|||||||
LAIKA_ERROR("failed to gen session key!\n");
|
LAIKA_ERROR("failed to gen session key!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void laikaB_flushQueue(struct sLaika_bot *bot) {
|
|
||||||
/* flush pList's outQueue */
|
|
||||||
if (bot->pList.outCount > 0) {
|
|
||||||
if (!laikaS_handlePeerOut(&bot->peer->sock))
|
|
||||||
laikaS_kill(&bot->peer->sock);
|
|
||||||
|
|
||||||
laikaP_resetOutQueue(&bot->pList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool laikaB_poll(struct sLaika_bot *bot, int timeout) {
|
bool laikaB_poll(struct sLaika_bot *bot, int timeout) {
|
||||||
struct sLaika_pollEvent *evnt;
|
struct sLaika_pollEvent *evnt;
|
||||||
int numEvents;
|
int numEvents;
|
||||||
|
|
||||||
/* flush any events prior (eg. made by a task) */
|
/* flush any events prior (eg. made by a task) */
|
||||||
laikaB_flushQueue(bot);
|
laikaP_flushOutQueue(&bot->pList);
|
||||||
evnt = laikaP_poll(&bot->pList, timeout, &numEvents);
|
evnt = laikaP_poll(&bot->pList, timeout, &numEvents);
|
||||||
|
|
||||||
if (numEvents == 0) /* no events? timeout was reached */
|
if (numEvents == 0) /* no events? timeout was reached */
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!laikaP_handleEvent(evnt))
|
laikaP_handleEvent(evnt);
|
||||||
laikaS_kill(&bot->peer->sock);
|
|
||||||
|
|
||||||
/* flush any events after (eg. made by a packet handler) */
|
/* flush any events after (eg. made by a packet handler) */
|
||||||
laikaB_flushQueue(bot);
|
laikaP_flushOutQueue(&bot->pList);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -135,6 +135,14 @@ struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = {
|
|||||||
true),
|
true),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* socket event */
|
||||||
|
void shellC_onPollFail(struct sLaika_socket *sock, void *uData) {
|
||||||
|
struct sLaika_peer *peer = (struct sLaika_peer*)sock;
|
||||||
|
struct sShell_client *client = (struct sShell_client*)uData;
|
||||||
|
|
||||||
|
laikaS_kill(&client->peer->sock);
|
||||||
|
}
|
||||||
|
|
||||||
/* ===============================================[[ Client API ]]=============================================== */
|
/* ===============================================[[ Client API ]]=============================================== */
|
||||||
|
|
||||||
void shellC_init(tShell_client *client) {
|
void shellC_init(tShell_client *client) {
|
||||||
@ -142,8 +150,8 @@ void shellC_init(tShell_client *client) {
|
|||||||
client->peer = laikaS_newPeer(
|
client->peer = laikaS_newPeer(
|
||||||
shellC_pktTbl,
|
shellC_pktTbl,
|
||||||
&client->pList,
|
&client->pList,
|
||||||
NULL,
|
shellC_onPollFail,
|
||||||
NULL,
|
(void*)client,
|
||||||
(void*)client
|
(void*)client
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -222,22 +230,12 @@ void shellC_connectToCNC(tShell_client *client, char *ip, char *port) {
|
|||||||
/* the handshake requests will be sent on the next call to shellC_poll */
|
/* the handshake requests will be sent on the next call to shellC_poll */
|
||||||
}
|
}
|
||||||
|
|
||||||
void shellC_flushQueue(tShell_client *client) {
|
|
||||||
/* flush pList's outQueue */
|
|
||||||
if (client->pList.outCount > 0) {
|
|
||||||
if (!laikaS_handlePeerOut(&client->peer->sock))
|
|
||||||
laikaS_kill(&client->peer->sock);
|
|
||||||
|
|
||||||
laikaP_resetOutQueue(&client->pList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool shellC_poll(tShell_client *client, int timeout) {
|
bool shellC_poll(tShell_client *client, int timeout) {
|
||||||
struct sLaika_pollEvent *evnt;
|
struct sLaika_pollEvent *evnt;
|
||||||
int numEvents;
|
int numEvents;
|
||||||
|
|
||||||
/* flush any events prior (eg. made by a command handler) */
|
/* flush any events prior (eg. made by a command handler) */
|
||||||
shellC_flushQueue(client);
|
laikaP_flushOutQueue(&client->pList);
|
||||||
evnt = laikaP_poll(&client->pList, timeout, &numEvents);
|
evnt = laikaP_poll(&client->pList, timeout, &numEvents);
|
||||||
|
|
||||||
if (numEvents == 0) /* no events? timeout was reached */
|
if (numEvents == 0) /* no events? timeout was reached */
|
||||||
@ -247,7 +245,7 @@ bool shellC_poll(tShell_client *client, int timeout) {
|
|||||||
laikaS_kill(&client->peer->sock);
|
laikaS_kill(&client->peer->sock);
|
||||||
|
|
||||||
/* flush any events after (eg. made by a packet handler) */
|
/* flush any events after (eg. made by a packet handler) */
|
||||||
shellC_flushQueue(client);
|
laikaP_flushOutQueue(&client->pList);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,10 +170,11 @@ void shellS_runCmd(tShell_client *client, char *cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* run command */
|
/* run command */
|
||||||
shellT_printf("\n");
|
shellT_printf("\n\n");
|
||||||
if (setjmp(cmdE_err) == 0) {
|
if (setjmp(cmdE_err) == 0) {
|
||||||
cmdDef->callback(client, args, argc);
|
cmdDef->callback(client, args, argc);
|
||||||
}
|
}
|
||||||
|
shellT_printf("\n");
|
||||||
|
|
||||||
/* free our argument buffer */
|
/* free our argument buffer */
|
||||||
laikaM_free(argc);
|
laikaM_free(argc);
|
||||||
|
Loading…
Reference in New Issue
Block a user