io: Always call read handler on EPOLLIN
PATCH 1/2 io: Always call read handler on EPOLLIN
When detecting EPOLLIN, always invoke read handler first. This ensures that even when error conditions (i.e., EPOLLHUP and/or EPOLLERR) are encountered, any residual data is still delivered to the client.
--- ell/io.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
ell/io.c +8 -8
@@ -111,14 +111,6 @@ static void io_callback(int fd, uint32_t events, void *user_data) {struct l_io *io = user_data; -if (unlikely (events & (EPOLLERR |EPOLLHUP ))) { -l_util_debug (io->debug_handler, io->debug_data, -"disconnect event <%p>" , io); -watch_remove (io->fd, !io->close_on_destroy); -io_closed (io); -return ; - } -if ((events &EPOLLIN ) && io->read_handler) {l_util_debug (io->debug_handler, io->debug_data,"read event <%p>" , io);
@@ -142,6 +134,14 @@ static void io_callback(int fd, uint32_t events, void *user_data) } } +if (unlikely (events & (EPOLLERR |EPOLLHUP ))) { +l_util_debug (io->debug_handler, io->debug_data, +"disconnect event <%p>" , io); +watch_remove (io->fd, !io->close_on_destroy); +io_closed (io); +return ; + } +if ((events &EPOLLOUT ) && io->write_handler) {l_util_debug (io->debug_handler, io->debug_data,"write event <%p>" , io);
Signature · 1 line
2.26.2
PATCH 2/2 io: Call disconnect handler before removing the watch
When encountering EPOLLERR or EPOLLHUP conditions, first invoke disconnect handler if it is set, and only then clear/remove the watch.
This allows the client to retrieve the actual code for the socket error via getsockopt(). Otherwise, if the socket is closed prior to calling the disconnect handler, the error code is lost.
--- ell/io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
ell/io.c +4 -1
@@ -135,10 +135,13 @@ static void io_callback(int fd, uint32_t events, void *user_data) }if (unlikely (events & (EPOLLERR |EPOLLHUP ))) { +bool close_on_destroy = io->close_on_destroy; +int fd = io->fd; +l_util_debug (io->debug_handler, io->debug_data,"disconnect event <%p>" , io); -watch_remove (io->fd, !io->close_on_destroy);io_closed (io); +watch_remove (fd, !close_on_destroy);return ; }
Signature · 1 line
2.26.2
Hi Inga,
Quoted 8 lines · Inga Stotland
When detecting EPOLLIN, always invoke read handler first. This ensures that even when error conditions (i.e., EPOLLHUP and/or EPOLLERR) are encountered, any residual data is still delivered to the client.
--- ell/io.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Both applied, thanks.
Regards,
-Denis