Fixes
- 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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
2
main.c
2
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;
|
||||
}
|
||||
|
||||
2
server.c
2
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user