From b784e43bae3c2f0a96e703f34d8bbeae04c9ae99 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 18 May 2012 16:25:52 +1000 Subject: [PATCH] Reconnect was bleeding socket handles on a path r3549 | dcl | 2012-05-18 16:25:52 +1000 (Fri, 18 May 2012) | 1 line --- network.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/network.c b/network.c index b5c31aae..cd4420e3 100644 --- a/network.c +++ b/network.c @@ -729,14 +729,21 @@ int NETReconnectWithFlags(mkChannel* self, int flags) */ oldopts = fcntl(self->sockid, F_GETFL, 0); close(self->sockid); - /* Reopen and try to get it on the olf fd */ + /* Reopen and try to get it on the old fd */ sock = socket(AF_INET,SOCK_STREAM,0); + /* If this isn't the same fd, try to move it over */ if (self->sockid != sock) { + /* Duplicate the new socket with the old fd if we can */ iRet = fcntl(sock, F_DUPFD, self->sockid); - if (iRet != sock) + if (iRet != self->sockid) { + /* If we didn't get the one we want, use original and close new */ self->sockid = sock; - else + close(iRet); + } + else { + /* If we did get the one we want, close original and use old */ close(sock); + } sock = self->sockid; } /* restore the old flags */