From 676227271dce094b3316aef0037942bf5a78ea30 Mon Sep 17 00:00:00 2001 From: ruti <> Date: Tue, 23 Jan 2024 03:08:35 +0300 Subject: [PATCH] Fix POLLOUT handling --- proxy.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/proxy.c b/proxy.c index c3d5563..9a11c6a 100644 --- a/proxy.c +++ b/proxy.c @@ -451,8 +451,10 @@ static inline int on_connect(struct poolhd *pool, struct eval *val, if (e) { return -1; } + if (mod_etype(pool, val, POLLOUT, 0)) { + return -1; + } val->type = EV_TUNNEL; - mod_etype(pool, val, POLLOUT, 0); val->pair->type = EV_CONNECT; } else { @@ -495,8 +497,10 @@ static inline int on_tunnel(struct poolhd *pool, struct eval *val, free(val->tmpbuf); val->tmpbuf = 0; - mod_etype(pool, val, POLLOUT, 0); - mod_etype(pool, val->pair, POLLIN, 1); + if (mod_etype(pool, val, POLLIN, 1) || + mod_etype(pool, pair, POLLOUT, 0)) { + return -1; + } } do { n = recv(val->fd, buffer, bfsize, 0); @@ -524,8 +528,10 @@ static inline int on_tunnel(struct poolhd *pool, struct eval *val, } memcpy(val->tmpbuf, buffer + sn, val->size); - mod_etype(pool, val, POLLIN, 0); - mod_etype(pool, pair, POLLOUT, 1); + if (mod_etype(pool, val, POLLIN, 0) || + mod_etype(pool, pair, POLLOUT, 1)) { + return -1; + } break; } } while (n == bfsize);