mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 06:59:44 +07:00
[wslproxy]: survive closed socket, close socket correctly.
1.When remote side socket is closed, `SIGPIPE` might be sent. We must ignore and exit correctly (we can't die as we might accept more connections) 2. shutdown and close sockets will inform remote side that socket is closed. Without it, remote side may not notice anything until the next write. GitOrigin-RevId: 51a6204651e49f63ac8b52d9e3e1e4928007c3ff
This commit is contained in:
committed by
intellij-monorepo-bot
parent
25f08fe587
commit
ae0ed41348
Binary file not shown.
Binary file not shown.
@@ -8,6 +8,7 @@
|
||||
#include <strings.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
// See svg file and wslproxy_test_client.py
|
||||
@@ -129,13 +130,20 @@ static void *jb_connect_pair(jb_sockpair *sockpair) {
|
||||
while (sent < bytes) {
|
||||
if ((write_result = write(dest, buf + sent, bytes - sent)) < 0) {
|
||||
if (errno != EINTR || errno != EAGAIN) {
|
||||
break; //socket closed
|
||||
goto end; //socket closed
|
||||
}
|
||||
}
|
||||
sent += write_result;
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
shutdown(source, SHUT_WR);
|
||||
close(source);
|
||||
|
||||
shutdown(dest, SHUT_WR);
|
||||
close(dest);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -189,6 +197,10 @@ _Noreturn static void *jb_listen_ingress(const int *p_ingress_srv_sock_fd) {
|
||||
static int g_ingress_srv_sock_fd;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// We expect write failures to occur but we want to handle them where
|
||||
// the error occurs rather than in a SIGPIPE handler.
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
// '--loopback' means use 127.0.0.1 as egress IP
|
||||
g_egress_ip = (argc > 1 && strcmp(&argv[1][0], "--loopback") == 0) ? htonl(INADDR_LOOPBACK)
|
||||
: jb_get_wsl_public_ip();
|
||||
|
||||
Reference in New Issue
Block a user