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:
parent
6d799a7532
commit
6cab9107bb
@ -8,6 +8,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "lconfig.h"
|
||||||
|
|
||||||
#define ARRAY_START 4
|
#define ARRAY_START 4
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -16,6 +18,4 @@
|
|||||||
#define LAIKA_DEBUG(...)
|
#define LAIKA_DEBUG(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "lconfig.h"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -6,8 +6,8 @@
|
|||||||
#define LAIKA_VERSION_MINOR 0
|
#define LAIKA_VERSION_MINOR 0
|
||||||
|
|
||||||
/* keys */
|
/* keys */
|
||||||
#define LAIKA_PUBKEY "b507a9c8bc8f2c61ea019122311b64361d034ba2b6299a11628a2608ef7f4137"
|
#define LAIKA_PUBKEY "997d026d1c65deb6c30468525132be4ea44116d6f194c142347b67ee73d18814"
|
||||||
#define LAIKA_PRIVKEY "4fefc9c4dba37f569432d091497b2c0e931ce78be945328e2ba57674969a3539"
|
#define LAIKA_PRIVKEY "1dbd33962f1e170d1e745c6d3e19175049b5616822fac2fa3535d7477957a841"
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,5 +9,4 @@
|
|||||||
#define LAIKA_PUBKEY "@LAIKA_PUBKEY@"
|
#define LAIKA_PUBKEY "@LAIKA_PUBKEY@"
|
||||||
#define LAIKA_PRIVKEY "@LAIKA_PRIVKEY@"
|
#define LAIKA_PRIVKEY "@LAIKA_PRIVKEY@"
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -4,6 +4,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
#include "laika.h"
|
||||||
|
|
||||||
/* defines errorstack size */
|
/* defines errorstack size */
|
||||||
#define LAIKA_MAXERRORS 32
|
#define LAIKA_MAXERRORS 32
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* moves array elements above indx down by numElem, removing numElem elements at indx */
|
/* 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); \
|
int _i, _sz = ((count-indx)-numElem); \
|
||||||
for (_i = 0; _i < _sz; _i++) \
|
for (_i = 0; _i < _sz; _i++) \
|
||||||
buf[indx+_i] = buf[indx+numElem+_i]; \
|
buf[indx+_i] = buf[indx+numElem+_i]; \
|
||||||
|
@ -89,7 +89,7 @@ void laikaP_rmvSock(struct sLaika_pollList *pList, struct sLaika_socket *sock) {
|
|||||||
for (i = 0; i < pList->fdCount; i++) {
|
for (i = 0; i < pList->fdCount; i++) {
|
||||||
if (pList->fds[i].fd == sock->sock) {
|
if (pList->fds[i].fd == sock->sock) {
|
||||||
/* remove from array */
|
/* remove from array */
|
||||||
laikaM_rmvarray(PollFD, pList->fds, pList->fdCount, i, 1);
|
laikaM_rmvarray(pList->fds, pList->fdCount, i, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +151,6 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
|
|||||||
if (SOCKETERROR(nEvents))
|
if (SOCKETERROR(nEvents))
|
||||||
LAIKA_ERROR("epoll_wait() failed!\n");
|
LAIKA_ERROR("epoll_wait() failed!\n");
|
||||||
|
|
||||||
*_nevents = nEvents;
|
|
||||||
for (i = 0; i < nEvents; i++) {
|
for (i = 0; i < nEvents; i++) {
|
||||||
/* add event to revent array */
|
/* add event to revent array */
|
||||||
laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity);
|
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))
|
if (SOCKETERROR(nEvents))
|
||||||
LAIKA_ERROR("poll() failed!\n");
|
LAIKA_ERROR("poll() failed!\n");
|
||||||
|
|
||||||
*_nevents = nEvents;
|
|
||||||
/* walk through the returned poll fds, if they have an event, add it to our revents array */
|
/* 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++) {
|
for (i = 0; i < pList->fdCount && nEvents > 0; i++) {
|
||||||
PollFD pfd = pList->fds[i];
|
PollFD pfd = pList->fds[i];
|
||||||
if (pList->fds[i].revents != 0) {
|
if (pList->fds[i].revents != 0) {
|
||||||
/* grab socket from hashmap */
|
/* 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 */
|
/* insert event into revents array */
|
||||||
laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity);
|
laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity);
|
||||||
pList->revents[pList->reventCount++] = (struct sLaika_pollEvent){
|
pList->revents[pList->reventCount++] = (struct sLaika_pollEvent){
|
||||||
.sock = _sock->sock,
|
.sock = elem->sock,
|
||||||
.pollIn = pfd.revents & POLLIN,
|
.pollIn = pfd.revents & POLLIN,
|
||||||
.pollOut = pfd.revents & POLLOUT
|
.pollOut = pfd.revents & POLLOUT
|
||||||
};
|
};
|
||||||
@ -188,6 +186,8 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
*_nevents = pList->reventCount;
|
||||||
|
|
||||||
/* return revents array */
|
/* return revents array */
|
||||||
return pList->revents;
|
return pList->revents;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ bool laikaS_setNonBlock(struct sLaika_socket *sock) {
|
|||||||
|
|
||||||
void laikaS_read(struct sLaika_socket *sock, void *buf, size_t sz) {
|
void laikaS_read(struct sLaika_socket *sock, void *buf, size_t sz) {
|
||||||
memcpy(buf, sock->inBuf, 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) {
|
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)
|
if (crypto_box_seal_open(buf, sock->inBuf, LAIKAENC_SIZE(sz), pub, priv) != 0)
|
||||||
LAIKA_ERROR("Failed to decrypt!\n");
|
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) {
|
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;
|
uint8_t tmp = *sock->inBuf;
|
||||||
|
|
||||||
/* pop 1 byte */
|
/* pop 1 byte */
|
||||||
laikaM_rmvarray(uint8_t, sock->inBuf, sock->inCount, 0, 1);
|
laikaM_rmvarray(sock->inBuf, sock->inCount, 0, 1);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ RAWSOCKCODE laikaS_rawSend(struct sLaika_socket *sock, size_t sz, int *processed
|
|||||||
|
|
||||||
_rawWriteExit:
|
_rawWriteExit:
|
||||||
/* trim sent data from outBuf */
|
/* 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;
|
*processed = sentBytes;
|
||||||
return errCode;
|
return errCode;
|
||||||
|
Loading…
Reference in New Issue
Block a user