Correct code to insert into a doubly-linked list.
authorben <ben@cda61777-01e9-0310-a592-d414129be87e>
Sun, 12 Jan 2003 13:50:04 +0000 (13:50 +0000)
committerben <ben@cda61777-01e9-0310-a592-d414129be87e>
Sun, 12 Jan 2003 13:50:04 +0000 (13:50 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/putty@2553 cda61777-01e9-0310-a592-d414129be87e

mac/macterm.c
mac/mtcpnet.c
mac/otnet.c

index b38c3ec..014260c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macterm.c,v 1.40 2003/01/12 01:25:34 ben Exp $ */
+/* $Id: macterm.c,v 1.41 2003/01/12 13:50:04 ben Exp $ */
 /*
  * Copyright (c) 1999 Simon Tatham
  * Copyright (c) 1999, 2002 Ben Harris
@@ -188,7 +188,8 @@ void mac_startsession(Session *s)
     ShowWindow(s->window);
     s->next = sesslist;
     s->prev = s->next->prev;
-    s->next->prev = &s->next;
+    if (ret->next != NULL)
+       s->next->prev = &s->next;
     sesslist = s;
 }
 
index 9d40051..543caa1 100644 (file)
@@ -504,7 +504,8 @@ Socket mactcp_new(SockAddr addr, int port, int privport, int oobinline,
     /* Add this to the list of all sockets */
     ret->next = mactcp.socklist;
     ret->prev = &mactcp.socklist;
-    ret->next->prev = &ret->next;
+    if (ret->next != NULL)
+       ret->next->prev = &ret->next;
     mactcp.socklist = ret;
 
     return (Socket)ret;
index 4c9ec4b..baa7a8a 100644 (file)
@@ -313,6 +313,8 @@ Socket ot_new(SockAddr addr, int port, int privport, int oobinline,
     /* Add this to the list of all sockets */
     ret->next = ot.socklist;
     ret->prev = &ot.socklist;
+    if (ret->next != NULL)
+       ret->next->prev = &ret->next;
     ot.socklist = ret;
 
     return (Socket) ret;
@@ -462,9 +464,13 @@ void ot_recv(Actual_Socket s)
 
     if (s->frozen) return;
 
-    while ((o = OTRcv(s->ep, buf, sizeof(buf), &flags)) != kOTNoDataErr) {
-       plug_receive(s->plug, 0, buf, sizeof(buf));
-    }
+    do {
+       o = OTRcv(s->ep, buf, sizeof(buf), &flags);
+       if (o > 0)
+           plug_receive(s->plug, 0, buf, sizeof(buf));
+       if (o < 0 && o != kOTNoDataErr)
+           plug_closing(s->plug, NULL, 0, 0); /* XXX Error msg */
+    } while (o > 0);
 }