1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-10-03 23:00:18 +00:00

Added new sLaika_peer member, 'uData'

- pktHandler was updated to pass 'uData'
This commit is contained in:
2022-01-24 20:57:54 -06:00
parent ed3efdaf11
commit 0dee6fe3fc
3 changed files with 15 additions and 11 deletions

View File

@@ -9,14 +9,15 @@
struct sLaika_peer {
struct sLaika_socket sock; /* DO NOT MOVE THIS. this member HAS TO BE FIRST so that typecasting sLaika_peer* to sLaika_sock* works as intended */
struct sLaika_pollList *pList; /* pollList we're active in */
void (*pktHandler)(struct sLaika_peer *peer, LAIKAPKT_ID id);
void (*pktHandler)(struct sLaika_peer *peer, LAIKAPKT_ID id, void *uData);
void *uData; /* data to be passed to pktHandler */
size_t *pktSizeTable; /* const table to pull pkt size data from */
size_t pktSize; /* current pkt size */
LAIKAPKT_ID pktID; /* current pkt ID */
size_t *pktSizeTable; /* const table to pull pkt size data from */
bool setPollOut; /* is EPOLLOUT/POLLOUT is set on sock's pollfd ? */
};
struct sLaika_peer *laikaS_newPeer(void (*pktHandler)(struct sLaika_peer *peer, LAIKAPKT_ID id), size_t *pktSizeTable, struct sLaika_pollList *pList);
struct sLaika_peer *laikaS_newPeer(void (*pktHandler)(struct sLaika_peer *peer, LAIKAPKT_ID id, void *uData), size_t *pktSizeTable, struct sLaika_pollList *pList, void *uData);
void laikaS_freePeer(struct sLaika_peer *peer);
bool laikaS_handlePeerIn(struct sLaika_peer *peer);

View File

@@ -2,13 +2,14 @@
#include "lmem.h"
#include "lpeer.h"
struct sLaika_peer *laikaS_newPeer(void (*pktHandler)(struct sLaika_peer *peer, LAIKAPKT_ID id), size_t *pktSizeTable, struct sLaika_pollList *pList) {
struct sLaika_peer *laikaS_newPeer(void (*pktHandler)(struct sLaika_peer *peer, LAIKAPKT_ID id, void *uData), size_t *pktSizeTable, struct sLaika_pollList *pList, void *uData) {
struct sLaika_peer *peer = laikaM_malloc(sizeof(struct sLaika_peer));
laikaS_initSocket(&peer->sock);
peer->pktHandler = pktHandler;
peer->pList = pList;
peer->pktSizeTable = pktSizeTable;
peer->pList = pList;
peer->uData = uData;
peer->pktSize = 0;
peer->pktID = LAIKAPKT_MAXNONE;
peer->setPollOut = false;
@@ -45,7 +46,7 @@ bool laikaS_handlePeerIn(struct sLaika_peer *peer) {
/* have we received the full packet? */
if (peer->pktSize == peer->sock.inCount) {
peer->pktHandler(peer, peer->pktID); /* dispatch to packet handler */
peer->pktHandler(peer, peer->pktID, peer->uData); /* dispatch to packet handler */
/* reset */
peer->sock.inCount = 0;