mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-21 12:40:04 +00:00
Renamed 'CERROR' & 'CWARN' to LAIKA_ERROR & LAIKA_WARN
This commit is contained in:
parent
8133a8d3cb
commit
c9fdeba4c5
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build
|
||||
.vscode
|
@ -2,6 +2,7 @@
|
||||
#define LAIKA_CNC_H
|
||||
|
||||
#include "laika.h"
|
||||
#include "lpacket.h"
|
||||
#include "lsocket.h"
|
||||
#include "lpolllist.h"
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
#include "cnc.h"
|
||||
#include "cnc.h"
|
||||
|
||||
|
@ -15,21 +15,21 @@
|
||||
/* if eLaika_errIndx is >= 0, we have a safe spot to jump too if an error is thrown */
|
||||
#define LAIKA_ISPROTECTED (eLaika_errIndx >= 0)
|
||||
|
||||
/* CERROR(printf args):
|
||||
/* LAIKA_ERROR(printf args):
|
||||
if called after a LAIKA_TRY block will jump to the previous LAIKA_CATCH/LAIKA_TRYEND block,
|
||||
otherwise program is exit()'d. if DEBUG is defined printf is called with passed args, else
|
||||
arguments are ignored.
|
||||
*/
|
||||
#ifndef DEBUG
|
||||
#define CERROR(...) { \
|
||||
#define LAIKA_ERROR(...) { \
|
||||
if (LAIKA_ISPROTECTED) \
|
||||
longjmp(eLaika_errStack[eLaika_errIndx], 1); \
|
||||
else \
|
||||
exit(1); \
|
||||
}
|
||||
#define CWARN(...)
|
||||
#define LAIKA_WARN(...)
|
||||
#else
|
||||
#define CERROR(...) { \
|
||||
#define LAIKA_ERROR(...) { \
|
||||
printf("[ERROR] : " __VA_ARGS__); \
|
||||
if (LAIKA_ISPROTECTED) \
|
||||
longjmp(eLaika_errStack[eLaika_errIndx], 1); \
|
||||
@ -37,7 +37,7 @@
|
||||
exit(1); \
|
||||
}
|
||||
|
||||
#define CWARN(...) \
|
||||
#define LAIKA_WARN(...) \
|
||||
printf("[WARN] : " __VA_ARGS__);
|
||||
#endif
|
||||
|
||||
|
@ -12,7 +12,7 @@ void *laikaM_realloc(void *buf, size_t sz) {
|
||||
|
||||
/* if NULL is passed, realloc() acts like malloc() */
|
||||
if ((newBuf = realloc(buf, sz)) == NULL)
|
||||
CERROR("failed to allocate memory!");
|
||||
LAIKA_ERROR("failed to allocate memory!");
|
||||
|
||||
return newBuf;
|
||||
}
|
@ -35,7 +35,7 @@ bool laikaS_handlePeerIn(struct sLaika_peer *peer) {
|
||||
|
||||
/* sanity check packet ID */
|
||||
if (peer->pktID >= LAIKAPKT_MAXNONE)
|
||||
CERROR("received evil pktID!")
|
||||
LAIKA_ERROR("received evil pktID!")
|
||||
|
||||
peer->pktSize = peer->pktSizeTable[peer->pktID];
|
||||
break;
|
||||
|
@ -32,7 +32,7 @@ void laikaP_initPList(struct sLaika_pollList *pList) {
|
||||
/* setup our epoll */
|
||||
memset(&pList->ev, 0, sizeof(struct epoll_event));
|
||||
if ((pList->epollfd = epoll_create(POLLSTARTCAP)) == -1)
|
||||
CERROR("epoll_create() failed!");
|
||||
LAIKA_ERROR("epoll_create() failed!");
|
||||
|
||||
#else
|
||||
pList->fds = NULL; /* laikaP_addSock will allocate the buffer */
|
||||
@ -62,7 +62,7 @@ void laikaP_addSock(struct sLaika_pollList *pList, struct sLaika_socket *sock) {
|
||||
pList->ev.data.ptr = (void*)sock;
|
||||
|
||||
if (epoll_ctl(pList->epollfd, EPOLL_CTL_ADD, sock->sock, &pList->ev) == -1)
|
||||
CERROR("epoll_ctl [ADD] failed");
|
||||
LAIKA_ERROR("epoll_ctl [ADD] failed");
|
||||
|
||||
#else
|
||||
/* allocate space in array & add PollFD */
|
||||
@ -79,7 +79,7 @@ void laikaP_rmvSock(struct sLaika_pollList *pList, struct sLaika_socket *sock) {
|
||||
/* epoll_event* isn't needed with EPOLL_CTL_DEL, however we still need to pass a NON-NULL pointer. [see: https://man7.org/linux/man-pages/man2/epoll_ctl.2.html#BUGS] */
|
||||
if (epoll_ctl(pList->epollfd, EPOLL_CTL_DEL, sock->sock, &pList->ev) == -1) {
|
||||
/* non-fatal error, socket probably just didn't exist, so ignore it. */
|
||||
CWARN("epoll_ctl [DEL] failed");
|
||||
LAIKA_WARN("epoll_ctl [DEL] failed");
|
||||
}
|
||||
#else
|
||||
int i;
|
||||
@ -101,7 +101,7 @@ void laikaP_addPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock
|
||||
pList->ev.data.ptr = (void*)sock;
|
||||
if (epoll_ctl(pList->epollfd, EPOLL_CTL_MOD, sock->sock, &pList->ev) == -1) {
|
||||
/* non-fatal error, socket probably just didn't exist, so ignore it. */
|
||||
CWARN("epoll_ctl [MOD] failed");
|
||||
LAIKA_WARN("epoll_ctl [MOD] failed");
|
||||
}
|
||||
#else
|
||||
int i;
|
||||
@ -122,7 +122,7 @@ void laikaP_rmvPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock
|
||||
pList->ev.data.ptr = (void*)sock;
|
||||
if (epoll_ctl(pList->epollfd, EPOLL_CTL_MOD, sock->sock, &pList->ev) == -1) {
|
||||
/* non-fatal error, socket probably just didn't exist, so ignore it. */
|
||||
CWARN("epoll_ctl [MOD] failed");
|
||||
LAIKA_WARN("epoll_ctl [MOD] failed");
|
||||
}
|
||||
#else
|
||||
int i;
|
||||
@ -148,7 +148,7 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
|
||||
nEvents = epoll_wait(pList->epollfd, pList->ep_events, MAX_EPOLL_EVENTS, timeout);
|
||||
|
||||
if (SOCKETERROR(nEvents))
|
||||
CERROR("epoll_wait() failed!");
|
||||
LAIKA_ERROR("epoll_wait() failed!");
|
||||
|
||||
for (i = 0; i < nEvents; i++) {
|
||||
/* add event to revent array */
|
||||
@ -163,7 +163,7 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
|
||||
nEvents = poll(pList->fds, pList->fdCount, timeout); /* poll returns -1 for error, or the number of events */
|
||||
|
||||
if (SOCKETERROR(nEvents))
|
||||
CERROR("poll() failed!");
|
||||
LAIKA_ERROR("poll() failed!");
|
||||
|
||||
/* 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++) {
|
||||
|
@ -13,7 +13,7 @@ void laikaS_init(void) {
|
||||
WSADATA wsaData;
|
||||
|
||||
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
|
||||
CERROR("WSAStartup failed!")
|
||||
LAIKA_ERROR("WSAStartup failed!")
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ void laikaS_connect(struct sLaika_socket *sock, char *ip, char *port) {
|
||||
struct addrinfo res, *result, *curr;
|
||||
|
||||
if (!SOCKETINVALID(sock->sock))
|
||||
CERROR("socket already setup!");
|
||||
LAIKA_ERROR("socket already setup!");
|
||||
|
||||
/* zero out our address info and setup the type */
|
||||
memset(&res, 0, sizeof(struct addrinfo));
|
||||
@ -77,7 +77,7 @@ void laikaS_connect(struct sLaika_socket *sock, char *ip, char *port) {
|
||||
|
||||
/* grab the address info */
|
||||
if (getaddrinfo(ip, port, &res, &result) != 0)
|
||||
CERROR("getaddrinfo() failed!");
|
||||
LAIKA_ERROR("getaddrinfo() failed!");
|
||||
|
||||
/* getaddrinfo returns a list of possible addresses, step through them and try them until we find a valid address */
|
||||
for (curr = result; curr != NULL; curr = curr->ai_next) {
|
||||
@ -97,7 +97,7 @@ void laikaS_connect(struct sLaika_socket *sock, char *ip, char *port) {
|
||||
|
||||
/* if we reached the end of the linked list, we failed looking up the addr */
|
||||
if (curr == NULL)
|
||||
CERROR("couldn't connect a valid address handle to socket!");
|
||||
LAIKA_ERROR("couldn't connect a valid address handle to socket!");
|
||||
}
|
||||
|
||||
void laikaS_bind(struct sLaika_socket *sock, uint16_t port) {
|
||||
@ -105,12 +105,12 @@ void laikaS_bind(struct sLaika_socket *sock, uint16_t port) {
|
||||
struct sockaddr_in address;
|
||||
|
||||
if (!SOCKETINVALID(sock))
|
||||
CERROR("socket already setup!")
|
||||
LAIKA_ERROR("socket already setup!")
|
||||
|
||||
/* open our socket */
|
||||
sock->sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (SOCKETINVALID(sock))
|
||||
CERROR("socket() failed!");
|
||||
LAIKA_ERROR("socket() failed!");
|
||||
|
||||
/* attach socket to the port */
|
||||
int opt = 1;
|
||||
@ -119,7 +119,7 @@ void laikaS_bind(struct sLaika_socket *sock, uint16_t port) {
|
||||
#else
|
||||
if (setsockopt(sock->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)) != 0)
|
||||
#endif
|
||||
CERROR("setsockopt() failed!");
|
||||
LAIKA_ERROR("setsockopt() failed!");
|
||||
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = INADDR_ANY;
|
||||
@ -129,10 +129,10 @@ void laikaS_bind(struct sLaika_socket *sock, uint16_t port) {
|
||||
|
||||
/* bind to the port */
|
||||
if (SOCKETERROR(bind(sock->sock, (struct sockaddr *)&address, addressSize)))
|
||||
CERROR("bind() failed!");
|
||||
LAIKA_ERROR("bind() failed!");
|
||||
|
||||
if (SOCKETERROR(listen(sock->sock, SOMAXCONN)))
|
||||
CERROR("listen() failed!");
|
||||
LAIKA_ERROR("listen() failed!");
|
||||
}
|
||||
|
||||
void laikaS_acceptFrom(struct sLaika_socket *sock, struct sLaika_socket *from) {
|
||||
@ -141,7 +141,7 @@ void laikaS_acceptFrom(struct sLaika_socket *sock, struct sLaika_socket *from) {
|
||||
|
||||
sock = accept(from->sock, &address, &addressSize);
|
||||
if (SOCKETINVALID(sock))
|
||||
CERROR("accept() failed!")
|
||||
LAIKA_ERROR("accept() failed!")
|
||||
}
|
||||
|
||||
bool laikaS_setNonBlock(struct sLaika_socket *sock) {
|
||||
@ -151,7 +151,7 @@ bool laikaS_setNonBlock(struct sLaika_socket *sock) {
|
||||
#else
|
||||
if (fcntl(sock->sock, F_SETFL, (fcntl(sock->sock, F_GETFL, 0) | O_NONBLOCK)) != 0) {
|
||||
#endif
|
||||
CWARN("fcntl failed on new connection");
|
||||
LAIKA_WARN("fcntl failed on new connection");
|
||||
laikaS_kill(sock);
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user