From 93c83dc40f004608737d59a71397080f0e84760f Mon Sep 17 00:00:00 2001 From: "Nikita Tyukalov, ASUS, Linux" Date: Wed, 25 Mar 2026 01:13:23 +0300 Subject: [PATCH] Fixes - Removed void* arithmetic - Fixed connection_send does not return anything - Fixed server_events invalid args in main.c (and changed its declaration) --- connection.c | 6 +++++- connection.h | 2 ++ main.c | 2 +- server.c | 2 +- server.h | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/connection.c b/connection.c index b35059c..7030510 100644 --- a/connection.c +++ b/connection.c @@ -265,11 +265,13 @@ void connection_event(int fd, uint32_t events) { } } -uint32_t connection_send(uint32_t id, const void *data, uint32_t size) { +uint32_t connection_send(uint32_t id, const void *data_void, uint32_t size) { + const char *data = data_void; int index = _get_conn_index_by_id(id); if (index == -1) return 0; conn_t *c = _conns[index]; + uint32_t wrote = 0; uint32_t can_write, will_write; // write to ring buffer can_write = rb_raw_write_size(c->send_buf); @@ -286,6 +288,7 @@ uint32_t connection_send(uint32_t id, const void *data, uint32_t size) { ); size -= will_write; data += will_write; + write += will_write; } // add to epoll if not added if (!(c->ev_mask & EPOLLOUT)) { @@ -299,4 +302,5 @@ uint32_t connection_send(uint32_t id, const void *data, uint32_t size) { &ev ); } + return wrote; } diff --git a/connection.h b/connection.h index 105c00a..ac7051d 100644 --- a/connection.h +++ b/connection.h @@ -40,6 +40,8 @@ bool connection_is_socket_managed(int fd); // - true on success // - false on failure // Remarks: +// - you must make sure fd is managed by this module +// (use connection_is_socket_managed) // - the app should be terminated if this function returns false void connection_event(int fd, uint32_t events); diff --git a/main.c b/main.c index b00eec8..2e0b137 100644 --- a/main.c +++ b/main.c @@ -175,7 +175,7 @@ static void on_fd_event(int fd, uint32_t events) { } // Server event else if (fd == _server_fd) { - if (!server_event(_server_fd)) { + if (!server_event(_server_fd, events)) { fprintf(stderr, "[!] server_event failed\n"); _to_work = false; } diff --git a/server.c b/server.c index 8e6e401..be4f3e3 100644 --- a/server.c +++ b/server.c @@ -91,7 +91,7 @@ void server_close() { close(_fd); } -bool server_event(uint32_t events) { +bool server_event(int fd, uint32_t events) { if (events & EPOLLIN) { return _accept(); } diff --git a/server.h b/server.h index 0787b67..bd664bc 100644 --- a/server.h +++ b/server.h @@ -30,7 +30,7 @@ void server_close(); // it with connection.h // - you should stop close the server if this function // returns false -bool server_event(uint32_t events); +bool server_event(int fd, uint32_t events); #endif