- Removed void* arithmetic
- Fixed connection_send does not return anything
- Fixed server_events invalid args in main.c (and changed its
  declaration)
This commit is contained in:
Nikita Tyukalov, ASUS, Linux
2026-03-25 01:13:23 +03:00
parent 8e90c4c152
commit 93c83dc40f
5 changed files with 10 additions and 4 deletions

View File

@@ -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); int index = _get_conn_index_by_id(id);
if (index == -1) if (index == -1)
return 0; return 0;
conn_t *c = _conns[index]; conn_t *c = _conns[index];
uint32_t wrote = 0;
uint32_t can_write, will_write; uint32_t can_write, will_write;
// write to ring buffer // write to ring buffer
can_write = rb_raw_write_size(c->send_buf); 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; size -= will_write;
data += will_write; data += will_write;
write += will_write;
} }
// add to epoll if not added // add to epoll if not added
if (!(c->ev_mask & EPOLLOUT)) { if (!(c->ev_mask & EPOLLOUT)) {
@@ -299,4 +302,5 @@ uint32_t connection_send(uint32_t id, const void *data, uint32_t size) {
&ev &ev
); );
} }
return wrote;
} }

View File

@@ -40,6 +40,8 @@ bool connection_is_socket_managed(int fd);
// - true on success // - true on success
// - false on failure // - false on failure
// Remarks: // 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 // - the app should be terminated if this function returns false
void connection_event(int fd, uint32_t events); void connection_event(int fd, uint32_t events);

2
main.c
View File

@@ -175,7 +175,7 @@ static void on_fd_event(int fd, uint32_t events) {
} }
// Server event // Server event
else if (fd == _server_fd) { else if (fd == _server_fd) {
if (!server_event(_server_fd)) { if (!server_event(_server_fd, events)) {
fprintf(stderr, "[!] server_event failed\n"); fprintf(stderr, "[!] server_event failed\n");
_to_work = false; _to_work = false;
} }

View File

@@ -91,7 +91,7 @@ void server_close() {
close(_fd); close(_fd);
} }
bool server_event(uint32_t events) { bool server_event(int fd, uint32_t events) {
if (events & EPOLLIN) { if (events & EPOLLIN) {
return _accept(); return _accept();
} }

View File

@@ -30,7 +30,7 @@ void server_close();
// it with connection.h // it with connection.h
// - you should stop close the server if this function // - you should stop close the server if this function
// returns false // returns false
bool server_event(uint32_t events); bool server_event(int fd, uint32_t events);
#endif #endif