Skip to content

Commit

Permalink
HevSocks5SessionUDP: Terminate the UDP association when the TCP conne…
Browse files Browse the repository at this point in the history
…ction is closed.
  • Loading branch information
heiher committed Feb 28, 2025
1 parent 1e239fc commit 9e2f092
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/hev-socks5-session-udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include "hev-socks5-session-udp.h"

#define task_io_yielder hev_socks5_task_io_yielder

typedef struct _HevSocks5UDPFrame HevSocks5UDPFrame;

struct _HevSocks5UDPFrame
Expand All @@ -40,6 +38,25 @@ struct _HevSocks5UDPFrame
size_t len;
};

static int
task_io_yielder (HevTaskYieldType type, void *data)
{
HevSocks5 *self = data;

if (self->type == HEV_SOCKS5_TYPE_UDP_IN_UDP) {
ssize_t res;
char buf;

res = recv (self->fd, &buf, sizeof (buf), 0);
if ((res == 0) || ((res < 0) && (errno != EAGAIN))) {
hev_socks5_set_timeout (self, 0);
return -1;
}
}

return hev_socks5_task_io_yielder (type, data);
}

static int
hev_socks5_session_udp_fwd_f (HevSocks5SessionUDP *self)
{
Expand Down Expand Up @@ -80,6 +97,8 @@ hev_socks5_session_udp_fwd_f (HevSocks5SessionUDP *self)
if (self->alive && hev_socks5_get_timeout (HEV_SOCKS5 (self)))
return 0;
}
if (HEV_SOCKS5 (self)->type == HEV_SOCKS5_TYPE_UDP_IN_TCP)
hev_socks5_set_timeout (HEV_SOCKS5 (self), 0);
LOG_D ("%p socks5 session udp fwd f send", self);
return -1;
}
Expand Down Expand Up @@ -113,6 +132,8 @@ hev_socks5_session_udp_fwd_b (HevSocks5SessionUDP *self)
if (self->alive && hev_socks5_get_timeout (HEV_SOCKS5 (self)))
return 0;
}
if (HEV_SOCKS5 (self)->type == HEV_SOCKS5_TYPE_UDP_IN_TCP)
hev_socks5_set_timeout (HEV_SOCKS5 (self), 0);
LOG_D ("%p socks5 session udp fwd b recv", self);
return -1;
}
Expand Down

0 comments on commit 9e2f092

Please sign in to comment.