From 2be649c84c23fc0ca2c52d27c7787ccc5bdb50e4 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Mon, 9 May 2022 18:13:35 +0800 Subject: [PATCH] fix: use closed socket in `io` watcher ev_epoll.c:134: epoll_modify: Assertion `("libev: I/O watcher with invalid fd found in epoll_ctl", errno != EBADF && errno != ELOOP && errno != EINVAL)` Signed-off-by: Jianhui Zhao --- src/http.c | 3 +++ src/rtty.c | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/http.c b/src/http.c index ebf5e24..10c3767 100644 --- a/src/http.c +++ b/src/http.c @@ -40,6 +40,9 @@ static void send_http_msg(struct http_connection *conn, size_t len, uint8_t *dat struct rtty *rtty = conn->rtty; struct buffer *wb = &rtty->wb; + if (rtty->sock == -1) + return; + buffer_put_u8(wb, MSG_TYPE_HTTP); buffer_put_u16be(wb, 18 + len); buffer_put_data(wb, conn->addr, 18); diff --git a/src/rtty.c b/src/rtty.c index d1bfb04..25e051c 100644 --- a/src/rtty.c +++ b/src/rtty.c @@ -314,10 +314,8 @@ void rtty_exit(struct rtty *rtty) } #endif - if (rtty->sock > 0) { - close(rtty->sock); - rtty->sock = -1; - } + close(rtty->sock); + rtty->sock = -1; http_conns_free(&rtty->http_conns);