summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortiptorrent development team <tiptorrent@soleta.eu>2021-12-21 14:19:35 +0100
committertiptorrent development team <tiptorrent@soleta.eu>2021-12-22 12:28:45 +0100
commitb18630a920a682e96b4a42494ef107fc50ab6135 (patch)
tree9d35ee90310c7cb2573b499f46429296a48d56c2
parent7bf3eebb98488aeb1a5fd38a516c1c41f864f1fd (diff)
do not create redirect if client unexpectedly closes connection
Close the socket without creating the redirection, this client did not successfully downloaded the image file. Moreover, check for connection closed by client in all of the possible read states.
-rw-r--r--src/core.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/core.c b/src/core.c
index 45853d9..94c0390 100644
--- a/src/core.c
+++ b/src/core.c
@@ -121,8 +121,14 @@ static void tip_client_read_cb(struct ev_loop *loop, struct ev_io *io, int event
if (ret < 0)
goto close;
- if (cli->state != TIP_CLIENT_CLOSE_WAIT)
+ if (cli->state != TIP_CLIENT_CLOSE_WAIT) {
+ if (ret == 0) {
+ syslog(LOG_ERR, "client %s:%hu unexpectedly closes connection\n",
+ inet_ntoa(cli->addr.sin_addr), ntohs(cli->addr.sin_port));
+ goto close;
+ }
ev_timer_again(loop, &cli->timer);
+ }
cli->buf_len += ret;
if (cli->buf_len >= sizeof(cli->buf)) {
@@ -168,11 +174,6 @@ static void tip_client_read_cb(struct ev_loop *loop, struct ev_io *io, int event
break;
case TIP_CLIENT_PROCESSING_REQUEST_2:
case TIP_CLIENT_PROCESSING_REQUEST_3:
- if (ret == 0) {
- syslog(LOG_ERR, "client %s:%hu unexpectedly closes connection\n",
- inet_ntoa(cli->addr.sin_addr), ntohs(cli->addr.sin_port));
- goto shutdown;
- }
syslog(LOG_ERR, "unexpected read from client %s:%hu while in write state\n",
inet_ntoa(cli->addr.sin_addr), ntohs(cli->addr.sin_port));
goto close;