From 90588fc697ec7f68c46a8c7da5e6dfde74504bc9 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 9 Jan 2003 23:04:34 +0000 Subject: [PATCH] Forcibly close any TCP connections that are still open when PuTTY exits. This saves leaving them lying around to crash the machine later. git-svn-id: svn://svn.tartarus.org/sgt/putty@2524 cda61777-01e9-0310-a592-d414129be87e --- mac/mtcpnet.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/mac/mtcpnet.c b/mac/mtcpnet.c index 69ad35bb..45248185 100644 --- a/mac/mtcpnet.c +++ b/mac/mtcpnet.c @@ -233,7 +233,24 @@ OSErr mactcp_init(void) void mactcp_shutdown(void) { + Actual_Socket s, next; + /* + * Eventually, PuTTY should close down each session as it exits, + * so there should be no sockets left when we get here. Still, + * better safe than sorry. + * + * XXX What about in-flight aync I/O (when we support that)? + */ + for (s = mactcp.socklist; s != NULL; s = next) { + next = s->next; /* s is about to vanish */ + mactcp_close(&s->fn); + } + + /* + * When we get async DNS, we have to wait for any outstanding + * requests to complete here before exiting. + */ CloseResolver(); mactcp.initialised = FALSE; } @@ -574,16 +591,21 @@ void mactcp_poll(void) for (s = mactcp.socklist; s != NULL; s = s->next) { /* XXX above can't handle sockets being deleted. */ - pb.ioCRefNum = mactcp.refnum; - pb.csCode = TCPStatus; - pb.tcpStream = s->s; - pb.csParam.status.userDataPtr = (Ptr)s; - s->err = PBControlSync((ParmBlkPtr)&pb); - if (s->err != noErr) - continue; - if (pb.csParam.status.amtUnreadData > 0) + do { + pb.ioCRefNum = mactcp.refnum; + pb.csCode = TCPStatus; + pb.tcpStream = s->s; + pb.csParam.status.userDataPtr = (Ptr)s; + s->err = PBControlSync((ParmBlkPtr)&pb); + if (s->err != noErr) + goto next_socket; + if (pb.csParam.status.amtUnreadData == 0) + break; mactcp_recv(s, pb.csParam.status.amtUnreadData); - /* Should check connectionState in case remote has closed */ + /* Should check connectionState in case remote has closed */ + } while (TRUE); + next_socket: + ; } } -- 2.11.0