X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/5221f5542f406a13b6eba29835dd1958a22c8d76..9b57f6ea289c28eddc723d91ae1cafd257d06666:/mac/mtcpnet.c diff --git a/mac/mtcpnet.c b/mac/mtcpnet.c index 69ad35bb..60dd84e3 100644 --- a/mac/mtcpnet.c +++ b/mac/mtcpnet.c @@ -197,8 +197,8 @@ static pascal void mactcp_asr(StreamPtr, unsigned short, Ptr, unsigned short, static Plug mactcp_plug(Socket, Plug); static void mactcp_flush(Socket); static void mactcp_close(Socket); -static int mactcp_write(Socket, char *, int); -static int mactcp_write_oob(Socket, char *, int); +static int mactcp_write(Socket, char const *, int); +static int mactcp_write_oob(Socket, char const*, int); static void mactcp_set_private_ptr(Socket, void *); static void *mactcp_get_private_ptr(Socket); static char *mactcp_socket_error(Socket); @@ -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; } @@ -528,14 +545,18 @@ static void mactcp_close(Socket sock) sfree(s); } -static int mactcp_write(Socket sock, char *buf, int len) +static int mactcp_write(Socket sock, char const *buf, int len) { Actual_Socket s = (Actual_Socket) sock; wdsEntry wds[2]; TCPiopb pb; + /* + * Casting away const from buf should be safe -- MacTCP won't + * write to it. + */ wds[0].length = len; - wds[0].ptr = buf; + wds[0].ptr = (char *)buf; wds[1].length = 0; pb.ioCRefNum = mactcp.refnum; @@ -550,7 +571,7 @@ static int mactcp_write(Socket sock, char *buf, int len) return 0; } -static int mactcp_write_oob(Socket sock, char *buf, int len) +static int mactcp_write_oob(Socket sock, char const *buf, int len) { fatalbox("mactcp_write_oob"); @@ -574,16 +595,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: + ; } }