aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2000-02-19 19:27:02 +0000
committerEric S. Raymond <esr@thyrsus.com>2000-02-19 19:27:02 +0000
commit577b940eaa2daf3048ca3a4880304c80883178a4 (patch)
tree01b51d7b876c901db7f3dba3b57bb3ea4d218957
parentc73ab3b733d13acccb1bee52dfe6386c8fee84e9 (diff)
downloadfetchmail-577b940eaa2daf3048ca3a4880304c80883178a4.tar.gz
fetchmail-577b940eaa2daf3048ca3a4880304c80883178a4.tar.bz2
fetchmail-577b940eaa2daf3048ca3a4880304c80883178a4.zip
Try for better version of graceful shutdown.
svn path=/trunk/; revision=2762
-rw-r--r--socket.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/socket.c b/socket.c
index e91d34b7..9501b1eb 100644
--- a/socket.c
+++ b/socket.c
@@ -667,21 +667,17 @@ int SockClose(int sock)
/* Half-close the connection first so the other end gets notified.
*
* This stops sends but allows receives (effectively, it sends a
- * TCP <FIN>). We ignore the return from this function because
- * some older BSD-based implementations fail shutdown() if a TCP
- * reset has been recieved. In any case, if it fails it means the
- * connection is already closed anyway, so it doesn't matter.
+ * TCP <FIN>).
*/
- shutdown(sock, 1);
-
- /* If there is any data still waiting in the queue, discard it.
- * Call recv() until either it returns 0 (meaning we received a FIN)
- * or any error occurs. This makes sure all data sent by the other
- * side is acknowledged at the TCP level.
- */
- if (recv(sock, &ch, 1, MSG_PEEK) > 0)
- while (read(sock, &ch, 1) > 0)
- continue;
+ if (shutdown(sock, 1) == SUCCESS)
+ /* If there is any data still waiting in the queue, discard it.
+ * Call recv() until either it returns 0 (meaning we received a FIN)
+ * or any error occurs. This makes sure all data sent by the other
+ * side is acknowledged at the TCP level.
+ */
+ if (recv(sock, &ch, 1, MSG_PEEK) > 0)
+ while (read(sock, &ch, 1) > 0)
+ continue;
/* if there's an error closing at this point, not much we can do */
return(close(sock)); /* this is guarded */