From 5617e2c32aead0223234997365e6cc35fea9deef Mon Sep 17 00:00:00 2001 From: Michael Theall Date: Mon, 18 Jan 2016 17:45:04 -0600 Subject: [PATCH] reduce dropped connections at end of transfer --- source/ftp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/ftp.c b/source/ftp.c index e71c65c..89e3593 100644 --- a/source/ftp.c +++ b/source/ftp.c @@ -295,6 +295,7 @@ ftp_closesocket(int fd, int rc; struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); + struct pollfd pollinfo; if(connected) { @@ -310,9 +311,17 @@ ftp_closesocket(int fd, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); /* shutdown connection */ - rc = shutdown(fd, SHUT_RDWR); + rc = shutdown(fd, SHUT_WR); if(rc != 0) console_print(RED "shutdown: %d %s\n" RESET, errno, strerror(errno)); + + /* wait for client to close connection */ + pollinfo.fd = fd; + pollinfo.events = POLLIN; + pollinfo.revents = 0; + rc = poll(&pollinfo, 1, 250); + if(rc < 0) + console_print(RED "poll: %d %s\n" RESET, errno, strerror(errno)); } /* close socket */