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

First actual runnable version

- many warnings & bug fixes
- added bot/ source
This commit is contained in:
2022-01-24 21:46:29 -06:00
parent 0dee6fe3fc
commit 1bccc78117
17 changed files with 196 additions and 41 deletions

View File

@@ -10,4 +10,13 @@
#define ARRAY_START 4
/* for intellisense */
#ifndef LIB_VERSION_MAJOR
#define LIB_VERSION_MAJOR 0
#endif
#ifndef LIB_VERSION_MINOR
#define LIB_VERSION_MINOR 0
#endif
#endif

View File

@@ -11,7 +11,7 @@
#define laikaM_growarray(type, buf, count, capacity) \
if (count >= capacity || buf == NULL) { \
capacity *= GROW_FACTOR; \
buf = (type*)cosmoM_realloc(buf, sizeof(type)*capacity); \
buf = (type*)laikaM_realloc(buf, sizeof(type)*capacity); \
}
/* moves array elements above indx down by numElem, removing numElem elements at indx */

View File

@@ -4,10 +4,10 @@
#define LAIKA_MAGIC "LAI\x12"
#define LAIKA_MAGICLEN 4
typedef enum {
enum {
LAIKAPKT_HANDSHAKE_REQ,
LAIKAPKT_HANDSHAKE_RES,
LAIKAPKT_MAXNONE
} LAIKAPKT_ID;
};
#endif

View File

@@ -9,15 +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 *uData);
void (*pktHandler)(struct sLaika_peer *peer, uint8_t 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 */
uint8_t pktID; /* current pkt ID */
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, void *uData), size_t *pktSizeTable, struct sLaika_pollList *pList, void *uData);
struct sLaika_peer *laikaS_newPeer(void (*pktHandler)(struct sLaika_peer *peer, uint8_t 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

@@ -1,3 +1,7 @@
#ifndef LAIKA_SOCKET_H
#define LAIKA_SOCKET_H
/* socket/winsock headers */
#ifdef _WIN32
/* windows */
@@ -62,7 +66,7 @@ struct sLaika_socket {
int inCount;
int outCap;
int inCap;
bool flipEndian
bool flipEndian;
};
#define laikaS_isAlive(arg) (arg->sock != INVALID_SOCKET)
@@ -95,4 +99,6 @@ void laikaS_readInt(struct sLaika_socket *sock, void *buf, size_t sz); /* reads
void laikaS_writeInt(struct sLaika_socket *sock, void *buf, size_t sz); /* writes INT, respecting endianness */
RAWSOCKCODE laikaS_rawRecv(struct sLaika_socket *sock, size_t sz, int *processed);
RAWSOCKCODE laikaS_rawSend(struct sLaika_socket *sock, size_t sz, int *processed);
RAWSOCKCODE laikaS_rawSend(struct sLaika_socket *sock, size_t sz, int *processed);
#endif