aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--lib/libostp/server.c64
-rw-r--r--lib/libostp/session.c2
3 files changed, 38 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index deebcc6..50e8da0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,12 @@
+DIAG=yes
CFILES_OTLIB = $(shell find lib/ -name "*.c")
CFLAGS_OTLIB = -pedantic -Ilib/include/ -fPIC
OTLIB_OBJ = $(CFILES_OTLIB:.c=.o)
+ifeq ($(DIAG),yes)
+CFLAGS_OTLIB += -D_DIAGNOSTIC
+endif
+
libostp.so: $(OTLIB_OBJ)
$(CC) -shared -o $@ $(OTLIB_OBJ)
diff --git a/lib/libostp/server.c b/lib/libostp/server.c
index 794eda0..0916d58 100644
--- a/lib/libostp/server.c
+++ b/lib/libostp/server.c
@@ -174,38 +174,6 @@ listener_poll(struct ostp_listener *lp)
continue;
}
- /* Check if the servers socket has new connections */
- if (FD_ISSET(lp->serv_sockfd, &lp->client_fds)) {
- caddr_len = sizeof(caddr);
- client_sock = accept(lp->serv_sockfd, (struct sockaddr *)&caddr,
- &caddr_len);
-
- if (client_sock < 0) {
- perror("accept");
- continue;
- }
-
- if (lp->client_count >= MAX_CLIENTS) {
- printf("New connection rejected, max clients reached\n");
- close(client_sock);
- continue;
- }
-
- for (int i = 0; i < MAX_CLIENTS; ++i) {
- c = &lp->clients[i];
- if (c->sockfd < 0) {
- c->sockfd = client_sock;
- c->authed = 0;
- ++lp->client_count;
-
- ip = inet_ntoa(caddr.sin_addr);
- printf("Incoming connection from %s\n", ip);
- handle_client(&caddr, c, lp);
- break;
- }
- }
- }
-
/* Handle data from clients */
for (int i = 1; i < MAX_CLIENTS; ++i) {
c = &lp->clients[i];
@@ -244,6 +212,38 @@ listener_poll(struct ostp_listener *lp)
}
}
}
+
+ /* Check if the servers socket has new connections */
+ if (FD_ISSET(lp->serv_sockfd, &lp->client_fds)) {
+ caddr_len = sizeof(caddr);
+ client_sock = accept(lp->serv_sockfd, (struct sockaddr *)&caddr,
+ &caddr_len);
+
+ if (client_sock < 0) {
+ perror("accept");
+ continue;
+ }
+
+ if (lp->client_count >= MAX_CLIENTS) {
+ printf("New connection rejected, max clients reached\n");
+ close(client_sock);
+ continue;
+ }
+
+ for (int i = 0; i < MAX_CLIENTS; ++i) {
+ c = &lp->clients[i];
+ if (c->sockfd < 0) {
+ c->sockfd = client_sock;
+ c->authed = 0;
+ ++lp->client_count;
+
+ ip = inet_ntoa(caddr.sin_addr);
+ printf("Incoming connection from %s\n", ip);
+ handle_client(&caddr, c, lp);
+ break;
+ }
+ }
+ }
}
close(client_sock);
diff --git a/lib/libostp/session.c b/lib/libostp/session.c
index 3843207..b47948e 100644
--- a/lib/libostp/session.c
+++ b/lib/libostp/session.c
@@ -42,7 +42,7 @@
#include <string.h>
#include <unistd.h>
-#if DIAGNOSTIC
+#ifdef _DIAGNOSTIC
#define LOG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define LOG(...) (void)0