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