diff --git a/src/gwproxy/dns.c b/src/gwproxy/dns.c index 3f3e835..7dfa78d 100644 --- a/src/gwproxy/dns.c +++ b/src/gwproxy/dns.c @@ -616,7 +616,7 @@ static void process_queue_entry(struct gwp_dns_ctx *ctx) * clone() for each entry if we can process them in the current * thread. */ - if ((ctx->nr_entries + 16) > ctx->nr_sleeping) + if (ctx->nr_entries > (ctx->nr_sleeping + 16)) process_queue_entry_batch(ctx); else process_queue_entry_single(ctx); diff --git a/src/gwproxy/gwproxy.c b/src/gwproxy/gwproxy.c index 051cf27..53cb75b 100644 --- a/src/gwproxy/gwproxy.c +++ b/src/gwproxy/gwproxy.c @@ -2789,11 +2789,10 @@ static int handle_socks5_data(struct gwp_wrk *w, struct gwp_conn_pair *gcp) out = gcp->target.buf + gcp->target.len; out_len = gcp->target.cap - gcp->target.len; r = gwp_socks5_conn_handle_data(sc, in, &in_len, out, &out_len); - if (r) - return (r == -EAGAIN) ? 0 : r; - gwp_conn_buf_advance(&gcp->client, in_len); gcp->target.len += out_len; + if (r) + return (r == -EAGAIN) ? 0 : r; if (sc->state == GWP_SOCKS5_ST_CMD_CONNECT) { r = socks5_prepare_target_addr(w, gcp); @@ -2839,12 +2838,15 @@ static int handle_ev_client_socks5(struct gwp_wrk *w, return sr; } - r = handle_socks5_data(w, gcp); - if (gcp->target.len) { - r = handle_socks5_pollout(w, gcp); - if (r && r != -EAGAIN) - return r; + if (gcp->conn_state == CONN_STATE_SOCKS5_DATA) { + r = handle_socks5_data(w, gcp); + if (gcp->target.len) { + r = handle_socks5_pollout(w, gcp); + if (r && r != -EAGAIN) + return r; + } } + return r; } diff --git a/src/gwproxy/socks5.c b/src/gwproxy/socks5.c index d682c40..812a1a9 100644 --- a/src/gwproxy/socks5.c +++ b/src/gwproxy/socks5.c @@ -890,6 +890,9 @@ int gwp_socks5_conn_handle_data(struct gwp_socks5_conn *conn, case GWP_SOCKS5_ST_CMD: r = handle_state_cmd(&arg); break; + case GWP_SOCKS5_ST_CMD_CONNECT: + r = 0; + goto out; default: return -EINVAL; } @@ -900,6 +903,7 @@ int gwp_socks5_conn_handle_data(struct gwp_socks5_conn *conn, if (r && r != -EAGAIN && r != -ENOBUFS) conn->state = GWP_SOCKS5_ST_ERR; +out: if (r == -ENOBUFS) { /* * If we run out of output buffer space, don't change