From f5f27646ee5c3033d04d86d069b6a7a6b5edb8e1 Mon Sep 17 00:00:00 2001 From: Michael Theall Date: Mon, 5 Jun 2017 11:50:41 -0500 Subject: [PATCH] Set SO_LINGER with timeout=0 before close Hopefully this helps with clients that don't acknowledge our close. Thanks to TuxSH for testing with Windows Explorer. --- source/ftp.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/ftp.c b/source/ftp.c index 8fc563c..586ba93 100644 --- a/source/ftp.c +++ b/source/ftp.c @@ -365,6 +365,16 @@ ftp_closesocket(int fd, console_print(RED "poll: %d %s\n" RESET, errno, strerror(errno)); } + /* set linger to 0 */ + struct linger linger; + linger.l_onoff = 1; + linger.l_linger = 0; + rc = setsockopt(fd, SOL_SOCKET, SO_LINGER, + &linger, sizeof(linger)); + if(rc != 0) + console_print(RED "setsockopt: SO_LINGER %d %s\n" RESET, + errno, strerror(errno)); + /* close socket */ rc = close(fd); if(rc != 0)