diff options
author | fadhil riyanto <me@fadev.org> | 2024-10-06 19:54:10 +0700 |
---|---|---|
committer | fadhil riyanto <me@fadev.org> | 2024-10-06 19:54:10 +0700 |
commit | 7273e70e79f400ad1f8472aff00cbf9933a6aef2 (patch) | |
tree | 8526a6ec6cdffec42b94c4b08c32940c3b4fed72 /main2.c | |
parent | e761e0f47250bb4a752d44848febc0f3c7745a4b (diff) |
add signal SIG_PIPE ignore
Signed-off-by: fadhil riyanto <me@fadev.org>
Diffstat (limited to 'main2.c')
-rw-r--r-- | main2.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -1,6 +1,7 @@ #include <asm-generic/socket.h> #include <signal.h> +#include <signal.h> #include <stdio.h> #include <string.h> #include <getopt.h> @@ -249,7 +250,11 @@ static int create_sock_ret_fd(struct sockaddr_storage *ss_addr) static void signal_cb(int signum) { printf("signal detected, exiting...\n"); -g_need_exit = 1; + + if (signum == SIGINT) { + g_need_exit = 1; + } + } @@ -267,6 +272,8 @@ static int server_reg_sigaction(void) return -1; } + ret = sigaction(SIGPIPE, &sa, NULL); + return 0; } @@ -645,6 +652,7 @@ static int create_server2server_conn(int *fdptr, int atyp, u_int8_t *addr, u_int * 0: no problem * 1: conn closed by client * 2: recv client error + * 3: client close connection */ static int start_exchange_data(int client_fd, int target_fd) @@ -657,11 +665,13 @@ static int start_exchange_data(int client_fd, int target_fd) int total_srv_read = 0; const u_int8_t *bufptr; + int sd, v; + do { printf("start sending\n"); memset(buf, 0, 4096); - fcntl(client_fd, F_SETFL, O_NONBLOCK); + // fcntl(client_fd, F_SETFL, O_NONBLOCK); /* recv data from socket client */ @@ -701,7 +711,8 @@ do_send_target: } /* read response from server */ - + + readbuf_server: memset(srvbuf, 0, 4096); *srvbuf = 0; @@ -727,10 +738,12 @@ readbuf_server: } else { // *srvbuf = *srvbuf + ret; // total_srv_read += ret; - ret = send(client_fd, srvbuf, ret, 0); + ret = send(client_fd, srvbuf, ret, MSG_NOSIGNAL); if (ret == -1) { perror("send() to client from srv"); + close(client_fd); + return 3; } goto readbuf_server; } |