Fix for PDT+ bug 29908 "Crash on quit after using mail; horks machine". r=wtc, mwelch; a=jar or chofmann (take your pick). Change consists of clearing the thread field in a socket file descriptor after SendReceiveStream is finished with it. nscp_beta1_BRANCH
authorgordon%netscape.com
Wed, 15 Mar 2000 23:37:16 +0000
branchnscp_beta1_BRANCH
changeset 1241 82985b56f986febc3b44cf8e563791da731f8cc9
parent 1195 6a2e556fb4f314c8b5fbb88dd493ce802104e686
push idunknown
push userunknown
push dateunknown
reviewerswtc, mwelch, jar
bugs29908
Fix for PDT+ bug 29908 "Crash on quit after using mail; horks machine". r=wtc, mwelch; a=jar or chofmann (take your pick). Change consists of clearing the thread field in a socket file descriptor after SendReceiveStream is finished with it.
pr/src/md/mac/macsockotpt.c
--- a/pr/src/md/mac/macsockotpt.c
+++ b/pr/src/md/mac/macsockotpt.c
@@ -1343,32 +1343,28 @@ static PRInt32 SendReceiveStream(PRFileD
 {
     OSStatus err;
     OTResult result;
     EndpointRef endpoint = (EndpointRef) fd->secret->md.osfd;
     PRThread *me = _PR_MD_CURRENT_THREAD();
     PRInt32 bytesLeft = amount;
 
     PR_ASSERT(flags == 0);
+    PR_ASSERT(opCode == kSTREAM_SEND || opCode == kSTREAM_RECEIVE);
     
     if (endpoint == NULL) {
         err = kEBADFErr;
         goto ErrorExit;
     }
         
     if (buf == NULL) {
         err = kEFAULTErr;
         goto ErrorExit;
     }
     
-    if (opCode != kSTREAM_SEND && opCode != kSTREAM_RECEIVE) {
-        err = kEINVALErr;
-        goto ErrorExit;
-    }
-        
     while (bytesLeft > 0) {
     
         PrepareForAsyncCompletion(me, fd->secret->md.osfd);    
 
         if (opCode == kSTREAM_SEND) {
         	do {
 
 				fd->secret->md.write.thread = me;
@@ -1427,16 +1423,20 @@ static PRInt32 SendReceiveStream(PRFileD
   			   		PrepareForAsyncCompletion(me, fd->secret->md.osfd);  
 				}
 			}
 			// Retry read if we had to wait for data to show up.
 			while(1);
         }
 
 		me->io_pending = PR_FALSE;
+        if (opCode == kSTREAM_SEND)
+            fd->secret->md.write.thread = nil;
+        else
+            fd->secret->md.read.thread  = nil;
 
         if (result > 0) {
             buf = (void *) ( (UInt32) buf + (UInt32)result );
             bytesLeft -= result;
             if (opCode == kSTREAM_RECEIVE)
                 return result;
         } else {
 			switch (result) {
@@ -1464,19 +1464,23 @@ static PRInt32 SendReceiveStream(PRFileD
 					
 				default:
 					err = result;
 					goto ErrorExit;
 			}
 		}
     }
 
+    PR_ASSERT(opCode == kSTREAM_SEND ? fd->secret->md.write.thread == nil :
+                                       fd->secret->md.read.thread  == nil);
     return amount;
 
 ErrorExit:
+    PR_ASSERT(opCode == kSTREAM_SEND ? fd->secret->md.write.thread == nil :
+                                       fd->secret->md.read.thread  == nil);
     macsock_map_error(err);
     return -1;
 }                               
 
 
 PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, 
                                PRIntn flags, PRIntervalTime timeout)
 {