Sync up with 0.94 branch on 10/16/01 PSM_2_2_DEV_20011002_BRANCH
authorddrinan%netscape.com
Wed, 17 Oct 2001 01:31:31 +0000
branchPSM_2_2_DEV_20011002_BRANCH
changeset 2087 9051de3111d50189408ad96256d0863304b61716
parent 2061 75d60a3182cea1e48800a64ec8d7ea6a062cec00
push idunknown
push userunknown
push dateunknown
Sync up with 0.94 branch on 10/16/01
pr/include/md/_macos.h
pr/src/md/mac/macsockotpt.c
--- a/pr/include/md/_macos.h
+++ b/pr/include/md/_macos.h
@@ -115,21 +115,20 @@ struct _MDFileDesc {
 	PRBool      orderlyDisconnect;
 	PRBool      readReady;
 	PRBool      writeReady;
 	PRBool      exceptReady;
 	PRLock *    miscLock;
 	
 	/* Server sockets: listen bit tells the notifier func what to do */
 	PRBool		doListen;
-	
+
 	_MDSocketCallerInfo  misc;
 	_MDSocketCallerInfo  read;
 	_MDSocketCallerInfo  write;
-	_MDSocketCallerInfo  poll;
 };
 
 /*
 ** Iinitialization Related definitions
 */
 
 #define _MD_EARLY_INIT		_MD_EarlyInit
 #define _MD_FINAL_INIT		_MD_FinalInit
--- a/pr/src/md/mac/macsockotpt.c
+++ b/pr/src/md/mac/macsockotpt.c
@@ -300,201 +300,197 @@ WakeUpNotifiedThread(PRThread *thread, O
 		}
 		DoneWaitingOnThisThread(thread);
 	}
 }
 
 // Notification routine
 // Async callback routine.
 // A5 is OK. Cannot allocate memory here
+// Ref: http://gemma.apple.com/techpubs/mac/NetworkingOT/NetworkingWOT-100.html
+//
 static pascal void  NotifierRoutine(void * contextPtr, OTEventCode code, OTResult result, void * cookie)
 {
-	PRFilePrivate *secret  = (PRFilePrivate *) contextPtr;
-	_MDFileDesc * md       = &(secret->md);
-	EndpointRef   endpoint = (EndpointRef)secret->md.osfd;
-    PRThread *    thread   = NULL;
-    PRThread *	  pollThread = md->poll.thread;
-	OSStatus      err;
-	OTResult	  resultOT;
-    TDiscon		  discon;
+    PRFilePrivate *secret  = (PRFilePrivate *) contextPtr;
+    _MDFileDesc * md       = &(secret->md);
+    EndpointRef   endpoint = (EndpointRef)secret->md.osfd;
+    PRThread *    readThread   = NULL;          // also used for 'misc'
+    PRThread *    writeThread  = NULL;
+    OSStatus      err;
+    OTResult      resultOT;
+    TDiscon       discon;
 
     switch (code)
     {
 // OTLook Events - 
         case T_LISTEN:        // A connection request is available
-        	// If md->doListen is true, then PR_Listen has been
-        	// called on this endpoint; therefore, we're ready to
-        	// accept connections. But we'll do that with PR_Accept
-        	// (which calls OTListen, OTAccept, etc) instead of 
-        	// doing it here. 
-        	if (md->doListen) {
-				thread = secret->md.misc.thread;
-	            secret->md.misc.thread    = NULL;
-	            secret->md.misc.cookie    = cookie;
-	            break;
-        	} else {
-        		// Reject the connection, we're not listening
-        		OTSndDisconnect(endpoint, NULL);
-        	}
+            // If md->doListen is true, then PR_Listen has been
+            // called on this endpoint; therefore, we're ready to
+            // accept connections. But we'll do that with PR_Accept
+            // (which calls OTListen, OTAccept, etc) instead of 
+            // doing it here. 
+            if (md->doListen) {
+                readThread = secret->md.misc.thread;
+                secret->md.misc.thread    = NULL;
+                secret->md.misc.cookie    = cookie;
+                break;
+            } else {
+                // Reject the connection, we're not listening
+                OTSndDisconnect(endpoint, NULL);
+            }
             break;
-			
+
         case T_CONNECT:      // Confirmation of a connect request
-			// cookie = sndCall parameter from OTConnect()
+            // cookie = sndCall parameter from OTConnect()
             err = OTRcvConnect(endpoint, NULL);
             PR_ASSERT(err == kOTNoError);
 
-			// wake up waiting thread, if any
-            thread = secret->md.write.thread;
+            // wake up waiting thread, if any.
+            writeThread = secret->md.write.thread;
             secret->md.write.thread    = NULL;
-            secret->md.write.cookie    = cookie;
+            secret->md.write.cookie    = cookie;            
             break;
 
         case T_DATA:        // Standard data is available
-			// Mark this socket as readable.
-			secret->md.readReady = PR_TRUE;
+            // Mark this socket as readable.
+            secret->md.readReady = PR_TRUE;
 
-			// wake up waiting thread, if any
-            thread = secret->md.read.thread;
+            // wake up waiting thread, if any
+            readThread = secret->md.read.thread;
             secret->md.read.thread    = NULL;
             secret->md.read.cookie    = cookie;
-			break;
+            break;
 
         case T_EXDATA:      // Expedited data is available
             PR_ASSERT(!"T_EXDATA Not implemented");
-			return;
+            return;
 
         case T_DISCONNECT:  // A disconnect is available
             discon.udata.len = 0;
             err = OTRcvDisconnect(endpoint, &discon);
             PR_ASSERT(err == kOTNoError);
-            secret->md.exceptReady     = PR_TRUE;
-
-			// wake up waiting threads, if any
-			result = -3199 - discon.reason; // obtain the negative error code
+            secret->md.exceptReady = PR_TRUE;       // XXX Check this
 
-            if ((thread = secret->md.read.thread) != NULL) {
-		        secret->md.read.thread    = NULL;
-    	        secret->md.read.cookie    = cookie;
-            	WakeUpNotifiedThread(thread, result);
-    	    }
-            
-            if ((thread = secret->md.write.thread) != NULL) {
-	            secret->md.write.thread    = NULL;
-	            secret->md.write.cookie    = cookie;
-	            WakeUpNotifiedThread(thread, result);
-	        }
-	        
-	        thread = NULL; // already took care of notification here
+            // wake up waiting threads, if any
+            result = -3199 - discon.reason; // obtain the negative error code
+            if ((readThread = secret->md.read.thread) != NULL) {
+                secret->md.read.thread    = NULL;
+                secret->md.read.cookie    = cookie;
+            }
+
+            if ((writeThread = secret->md.write.thread) != NULL) {
+                secret->md.write.thread    = NULL;
+                secret->md.write.cookie    = cookie;
+            }
             break;
-		
+
         case T_ERROR:       // obsolete/unused in library
             PR_ASSERT(!"T_ERROR Not implemented");
-			return;		
-		
+            return;
+
         case T_UDERR:       // UDP Send error; clear the error
-			(void) OTRcvUDErr((EndpointRef) cookie, NULL);
+            (void) OTRcvUDErr((EndpointRef) cookie, NULL);
             break;
 
         case T_ORDREL:      // An orderly release is available
             err = OTRcvOrderlyDisconnect(endpoint);
             PR_ASSERT(err == kOTNoError);
             secret->md.readReady      = PR_TRUE;   // mark readable (to emulate bsd sockets)
             // remember connection is closed, so we can return 0 on read or receive
-			secret->md.orderlyDisconnect = PR_TRUE;
-	
-            thread = secret->md.read.thread;
-	        secret->md.read.thread    = NULL;
-	        secret->md.read.cookie    = cookie;
-
+            secret->md.orderlyDisconnect = PR_TRUE;
+            
+            readThread = secret->md.read.thread;
+            secret->md.read.thread    = NULL;
+            secret->md.read.cookie    = cookie;
             break;		
 
         case T_GODATA:   // Flow control lifted on standard data
             secret->md.writeReady = PR_TRUE;
-			resultOT = OTLook(endpoint);		// clear T_GODATA event
-			PR_ASSERT(resultOT == T_GODATA);
-			
-			// wake up waiting thread, if any
-            thread = secret->md.write.thread;
+            resultOT = OTLook(endpoint);        // clear T_GODATA event
+            PR_ASSERT(resultOT == T_GODATA);
+            
+            // wake up waiting thread, if any
+            writeThread = secret->md.write.thread;
             secret->md.write.thread    = NULL;
             secret->md.write.cookie    = cookie;
             break;
 
         case T_GOEXDATA: // Flow control lifted on expedited data
             PR_ASSERT(!"T_GOEXDATA Not implemented");
-			return;
+            return;
 
         case T_REQUEST:  // An Incoming request is available
             PR_ASSERT(!"T_REQUEST Not implemented");
             return;
 
         case T_REPLY:    // An Incoming reply is available
             PR_ASSERT(!"T_REPLY Not implemented");
             return;
 
         case T_PASSCON:  // State is now T_DATAXFER
-			// OTAccept() complete, receiving endpoint in T_DATAXFER state
-			// cookie = OTAccept() resRef parameter
-			break;
+            // OTAccept() complete, receiving endpoint in T_DATAXFER state
+            // cookie = OTAccept() resRef parameter
+            break;
 
         case T_RESET:    // Protocol has been reset
             PR_ASSERT(!"T_RESET Not implemented");
-			return;
+            return;
             
 // Async Completion Events
         case T_BINDCOMPLETE:
         case T_UNBINDCOMPLETE:
         case T_ACCEPTCOMPLETE:
         case T_OPTMGMTCOMPLETE:
         case T_GETPROTADDRCOMPLETE:
-			thread = secret->md.misc.thread;
+            readThread = secret->md.misc.thread;
             secret->md.misc.thread    = NULL;
             secret->md.misc.cookie    = cookie;
             break;
 
-//      case T_OPENCOMPLETE:			// we open endpoints in synchronous mode
+//      case T_OPENCOMPLETE:            // we open endpoints in synchronous mode
 //      case T_REPLYCOMPLETE:
-//      case T_DISCONNECTCOMPLETE:		// we don't call OTSndDisconnect()
+//      case T_DISCONNECTCOMPLETE:      // we don't call OTSndDisconnect()
 //      case T_RESOLVEADDRCOMPLETE:
 //      case T_GETINFOCOMPLETE:
 //      case T_SYNCCOMPLETE:
-//      case T_MEMORYRELEASED:			// only if OTAckSends() called on endpoint
+//      case T_MEMORYRELEASED:          // only if OTAckSends() called on endpoint
 //      case T_REGNAMECOMPLETE:
 //      case T_DELNAMECOMPLETE:
 //      case T_LKUPNAMECOMPLETE:
 //      case T_LKUPNAMERESULT:
-		// OpenTptInternet.h
-//      case T_DNRSTRINGTOADDRCOMPLETE:	// DNS is handled by dnsContext in DNSNotifierRoutine()
+        // OpenTptInternet.h
+//      case T_DNRSTRINGTOADDRCOMPLETE: // DNS is handled by dnsContext in DNSNotifierRoutine()
 //      case T_DNRADDRTONAMECOMPLETE:
 //      case T_DNRSYSINFOCOMPLETE:
 //      case T_DNRMAILEXCHANGECOMPLETE:
 //      case T_DNRQUERYCOMPLETE:
         default:
-        	// we should probably have a bit more sophisticated handling of kOTSystemSleep, etc.
-			// PR_ASSERT(code != 0);
+            // we should probably have a bit more sophisticated handling of kOTSystemSleep, etc.
+            // PR_ASSERT(code != 0);
             return;
     }
 
-	if (pollThread)
-		WakeUpNotifiedThread(pollThread, kOTNoError);
+    if (readThread)
+        WakeUpNotifiedThread(readThread, result);
 
-	if (thread && (thread != pollThread))
-		WakeUpNotifiedThread(thread, result);
+    if (writeThread && (writeThread != readThread))
+        WakeUpNotifiedThread(writeThread, result);
 }
 
 
 static OSErr CreateSocket(int type, EndpointRef *endpoint)
 {
     OSStatus err;
     PRThread *me = _PR_MD_CURRENT_THREAD();
     char *  configName;
     OTConfiguration *config;
     EndpointRef ep;
 
-	// for now we just create the endpoint
-	// we'll make it asynchronous and give it a notifier routine in _MD_makenonblock()
+    // for now we just create the endpoint
+    // we'll make it asynchronous and give it a notifier routine in _MD_makenonblock()
 
     switch (type){
         case SOCK_STREAM:   configName = kTCPName;  break;
         case SOCK_DGRAM:    configName = kUDPName;  break;
     }
     config = OTCreateConfiguration(configName);
     ep = OT_OPEN_ENDPOINT(config, 0, NULL, &err);
     if (err != kOTNoError)
@@ -514,17 +510,17 @@ ErrorExit:
 // kOTXXXX - OT returned error
 // EPROTONOSUPPORT - bad socket type/protocol
 // ENOBUFS - not enough space for another socket, or failure in socket creation routine
 PRInt32 _MD_socket(int domain, int type, int protocol)
 {
     OSStatus    err;
     EndpointRef endpoint;
     
-    	_MD_FinishInitNetAccess();
+    _MD_FinishInitNetAccess();
 
     // We only deal with internet domain
     if (domain != AF_INET) {
         err = kEPROTONOSUPPORTErr;
         goto ErrorExit;
     }
     
     // We only know about tcp & udp
@@ -1344,17 +1340,18 @@ PRInt32 _MD_connect(PRFileDesc *fd, PRNe
 
     memset(&sndCall, 0 , sizeof(sndCall));
 
     sndCall.addr.maxlen = addrlen;
     sndCall.addr.len = addrlen;
     sndCall.addr.buf = (UInt8*) addr;
 
 	if (!fd->secret->nonblocking) {    
-        PrepareForAsyncCompletion(me, fd->secret->md.osfd);    
+        PrepareForAsyncCompletion(me, fd->secret->md.osfd);
+        PR_ASSERT(fd->secret->md.write.thread == NULL);
 	    fd->secret->md.write.thread = me;
     }
 	
     err = OTConnect (endpoint, &sndCall, NULL);
 	if (err == kOTNoError) {
         PR_ASSERT(!"OTConnect returned kOTNoError in async mode!?!");	
 	}
 	if (fd->secret->nonblocking) {
@@ -1402,26 +1399,28 @@ static PRInt32 SendReceiveStream(PRFileD
         err = kEBADFErr;
         goto ErrorExit;
     }
         
     if (buf == NULL) {
         err = kEFAULTErr;
         goto ErrorExit;
     }
-    
+
+    PR_ASSERT(opCode == kSTREAM_SEND ? fd->secret->md.write.thread == NULL :
+                                       fd->secret->md.read.thread  == NULL);
+
     while (bytesLeft > 0)
     {
         Boolean disabledNotifications = OTEnterNotifier(endpoint);
     
         PrepareForAsyncCompletion(me, fd->secret->md.osfd);    
 
         if (opCode == kSTREAM_SEND) {
         	do {
-
 				fd->secret->md.write.thread = me;
 				fd->secret->md.writeReady = PR_FALSE;				// expect the worst
 	            result = OTSnd(endpoint, buf, bytesLeft, NULL);
 				fd->secret->md.writeReady = (result != kOTFlowErr);
 				if (fd->secret->nonblocking)							// hope for the best
 					break;
 				else {
 
@@ -1495,73 +1494,86 @@ static PRInt32 SendReceiveStream(PRFileD
 
         // turn notifications back on
         if (disabledNotifications)
             OTLeaveNotifier(endpoint);
 
         if (result > 0) {
             buf = (void *) ( (UInt32) buf + (UInt32)result );
             bytesLeft -= result;
-            if (opCode == kSTREAM_RECEIVE)
-                return result;
+            if (opCode == kSTREAM_RECEIVE) {
+                amount = result;
+                goto NormalExit;
+            }
         } else {
 			switch (result) {
 				case kOTLookErr:
 				    PR_ASSERT(!"call to OTLook() required after all.");
 					break;
 				
 				case kOTFlowErr:
 				case kOTNoDataErr:
 				case kEAGAINErr:
 				case kEWOULDBLOCKErr:
 					if (fd->secret->nonblocking) {
-						err = result;
-						goto ErrorExit;
+					
+					    if (bytesLeft == amount) {  // no data was sent
+						    err = result;
+						    goto ErrorExit;
+						}
+						
+						// some data was sent
+						amount -= bytesLeft;
+						goto NormalExit;
 					}
 
 					WaitOnThisThread(me, timeout);
 					err = me->md.osErrCode;
 					if (err != kOTNoError)
 						goto ErrorExit;				
 					break;
 					
 				case kOTOutStateErr:	// if provider already closed, fall through to handle error
-					if (fd->secret->md.orderlyDisconnect)
-						return 0;
+					if (fd->secret->md.orderlyDisconnect) {
+						amount = 0;
+						goto NormalExit;
+					}
+					// else fall through
 				default:
 					err = result;
 					goto ErrorExit;
 			}
 		}
     }
 
-    PR_ASSERT(opCode == kSTREAM_SEND ? fd->secret->md.write.thread == nil :
-                                       fd->secret->md.read.thread  == nil);
+NormalExit:
+    PR_ASSERT(opCode == kSTREAM_SEND ? fd->secret->md.write.thread == NULL :
+                                       fd->secret->md.read.thread  == NULL);
     return amount;
 
 ErrorExit:
-    PR_ASSERT(opCode == kSTREAM_SEND ? fd->secret->md.write.thread == nil :
-                                       fd->secret->md.read.thread  == nil);
+    PR_ASSERT(opCode == kSTREAM_SEND ? fd->secret->md.write.thread == NULL :
+                                       fd->secret->md.read.thread  == NULL);
     macsock_map_error(err);
     return -1;
-}                               
+}
 
 
 PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, 
                                PRIntn flags, PRIntervalTime timeout)
 {
     return (SendReceiveStream(fd, buf, amount, flags, timeout, kSTREAM_RECEIVE));
-}                               
+}
 
 
 PRInt32 _MD_send(PRFileDesc *fd,const void *buf, PRInt32 amount, 
                                PRIntn flags, PRIntervalTime timeout)
 {
     return (SendReceiveStream(fd, (void *)buf, amount, flags, timeout, kSTREAM_SEND));
-}                               
+}
 
 
 // Errors:
 // EBADF -- bad socket id
 // EFAULT -- bad buffer
 static PRInt32 SendReceiveDgram(PRFileDesc *fd, void *buf, PRInt32 amount, 
                                PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen, 
                                PRIntervalTime timeout, SndRcvOpCode opCode)
@@ -1633,35 +1645,35 @@ static PRInt32 SendReceiveDgram(PRFileDe
     if (opCode == kDGRAM_RECEIVE)
         *addrlen = dgram.addr.len;
 
     return amount;
 
 ErrorExit:
     macsock_map_error(err);
     return -1;
-}                               
+}
 
 
 PRInt32 _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount, 
                                PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
                                PRIntervalTime timeout)
 {
     return (SendReceiveDgram(fd, buf, amount, flags, addr, addrlen,
                             timeout, kDGRAM_RECEIVE));
-}                               
+}
 
 
 PRInt32 _MD_sendto(PRFileDesc *fd,const void *buf, PRInt32 amount, 
                                PRIntn flags, PRNetAddr *addr, PRUint32 addrlen,
                                PRIntervalTime timeout)
 {
     return (SendReceiveDgram(fd, (void *)buf, amount, flags, addr, &addrlen,
                             timeout, kDGRAM_SEND));
-}                               
+}
 
 
 PRInt32 _MD_closesocket(PRInt32 osfd)
 {
     OSStatus err;
     EndpointRef endpoint = (EndpointRef) osfd;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
@@ -1678,47 +1690,67 @@ PRInt32 _MD_closesocket(PRInt32 osfd)
     if (err != kOTNoError)
         goto ErrorExit;
 
     return kOTNoError;
 
 ErrorExit:
     macsock_map_error(err);
     return -1;
-}                               
+}
 
 
 PRInt32 _MD_writev(PRFileDesc *fd, const struct PRIOVec *iov, PRInt32 iov_size, PRIntervalTime timeout)
 {
 #pragma unused (fd, iov, iov_size, timeout)
 
     PR_ASSERT(0);
     _PR_MD_CURRENT_THREAD()->md.osErrCode = unimpErr;
     return -1;
-}                               
+}
 
-
+// OT endpoint states are documented here:
+// http://gemma.apple.com/techpubs/mac/NetworkingOT/NetworkingWOT-27.html#MARKER-9-65
+//
 static PRBool GetState(PRFileDesc *fd, PRBool *readReady, PRBool *writeReady, PRBool *exceptReady)
 {
     OTResult resultOT;
     // hack to emulate BSD sockets; say that a socket that has disconnected
     // is still readable.
     size_t   availableData = 1;
     if (!fd->secret->md.orderlyDisconnect)
         OTCountDataBytes((EndpointRef)fd->secret->md.osfd, &availableData);
 
     *readReady = fd->secret->md.readReady && (availableData > 0);
-	*exceptReady = fd->secret->md.exceptReady;
+    *exceptReady = fd->secret->md.exceptReady;
 
     resultOT = OTGetEndpointState((EndpointRef)fd->secret->md.osfd);
-    switch (resultOT)    {
-        case T_DATAXFER:
-        case T_INREL:
-            *writeReady = PR_TRUE;
+    switch (resultOT) {
+        case T_IDLE:
+        case T_UNBND:
+            // the socket is not connected. Emulating BSD sockets,
+            // we mark it readable and writable. The next PR_Read
+            // or PR_Write will then fail. Usually, in this situation,
+            // fd->secret->md.exceptReady is also set, and returned if
+            // anyone is polling for it.
+            *readReady = PR_FALSE;
+            *writeReady = PR_FALSE;
             break;
+
+        case T_DATAXFER:        // data transfer
+            *writeReady = fd->secret->md.writeReady;
+            break;
+
+        case T_INREL:           // incoming orderly release
+            *writeReady = fd->secret->md.writeReady;
+            break;
+
+        case T_OUTCON:          // outgoing connection pending  
+        case T_INCON:           // incoming connection pending
+        case T_OUTREL:          // outgoing orderly release
         default:
             *writeReady = PR_FALSE;
     }
     
     return  *readReady || *writeReady || *exceptReady;
 }
 
 // check to see if any of the poll descriptors have data available
@@ -1806,55 +1838,66 @@ static void SetDescPollThread(PRPollDesc
 
     for (pd = pds, epd = pd + npds; pd < epd; pd++)
     {   
         if (pd->fd)
         { 
             PRFileDesc *bottomFD = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
             if (bottomFD && (_PR_FILEDESC_OPEN == bottomFD->secret->state))
             {
-                bottomFD->secret->md.poll.thread = thread;
+                if (pd->in_flags & PR_POLL_READ) {
+                    PR_ASSERT(thread == NULL || bottomFD->secret->md.read.thread == NULL);
+                    bottomFD->secret->md.read.thread = thread;
+                }
+
+                if (pd->in_flags & PR_POLL_WRITE) {
+                    // it's possible for the writing thread to be non-null during
+                    // a non-blocking connect, so we assert that we're on
+                    // the same thread, or the thread is null.
+                    // Note that it's strictly possible for the connect and poll
+                    // to be on different threads, so ideally we need to assert
+                    // that if md.write.thread is non-null, there is a non-blocking
+                    // connect in progress.
+                    PR_ASSERT(thread == NULL ||
+                        (bottomFD->secret->md.write.thread == NULL ||
+                         bottomFD->secret->md.write.thread == thread));
+                    bottomFD->secret->md.write.thread = thread;
+                }
             }
         }        
     }
 }
 
 PRInt32 _MD_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
 {
     PRThread    *thread = _PR_MD_CURRENT_THREAD();
     intn is;
     PRInt32 ready;
-    OSErr   result;
     
-    if (timeout == PR_INTERVAL_NO_WAIT) {        
+    if (timeout == PR_INTERVAL_NO_WAIT) {
         return CheckPollDescs(pds, npds);
     }
     
     _PR_INTSOFF(is);
     PR_Lock(thread->md.asyncIOLock);
 
     // ensure that we don't miss the firing of the notifier while checking socket status
     // need to set up the thread
     PrepareForAsyncCompletion(thread, 0);
 
-    SetDescPollThread(pds, npds, thread);        
+    SetDescPollThread(pds, npds, thread);
     ready = CheckPollDescs(pds, npds);
 
     PR_Unlock(thread->md.asyncIOLock);
     _PR_FAST_INTSON(is);
 
     if (ready == 0) {
         WaitOnThisThread(thread, timeout);
-        result = thread->md.osErrCode;
-        if (result != noErr && result != kETIMEDOUTErr) {
-            PR_ASSERT(0);   /* debug: catch unexpected errors */
-            ready = -1;
-        } else {
-            ready = CheckPollDescs(pds, npds);
-        }
+        ready = CheckPollDescs(pds, npds);
+
     } else {
         thread->io_pending = PR_FALSE;
     }
 
     SetDescPollThread(pds, npds, NULL);
 
     return ready;
 }
@@ -1932,17 +1975,17 @@ void _MD_queryfdinheritable(PRFileDesc *
 
 
 PR_IMPLEMENT(PRInt32) _MD_shutdown(PRFileDesc *fd, PRIntn how)
 {
 #pragma unused (fd, how)
 
 /* Just succeed silently!!! */
 return (0);
-}                               
+}
 
 
 PR_IMPLEMENT(PRStatus) 
 _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen)
 {
     PRThread *me = _PR_MD_CURRENT_THREAD();
 	EndpointRef ep = (EndpointRef) fd->secret->md.osfd;
 	InetAddress inetAddr;
@@ -1982,25 +2025,25 @@ PR_IMPLEMENT(PRStatus)
     addr->inet.ip = (PRUint32) inetAddr.fHost;
     
     *addrlen = PR_NETADDR_SIZE(addr); // return the amount of data obtained
 	return PR_SUCCESS;
 
 ErrorExit:
     macsock_map_error(err);
     return PR_FAILURE;
-}                               
+}
 
 
 PR_IMPLEMENT(unsigned long) inet_addr(const char *cp)
 {
     OSStatus err;
     InetHost host;    
 
-    	_MD_FinishInitNetAccess();
+    _MD_FinishInitNetAccess();
 
     err = OTInetStringToHost((char*) cp, &host);
     if (err != kOTNoError)
         return -1;
     
     return host;
 }
 
@@ -2062,30 +2105,30 @@ PR_IMPLEMENT(struct hostent *) gethostby
     OTInetHostToString((InetHost)addr, sHostInfo.name);
     
     return (gethostbyname(sHostInfo.name));
 }
 
 
 PR_IMPLEMENT(char *) inet_ntoa(struct in_addr addr)
 {
-    	_MD_FinishInitNetAccess();
+    _MD_FinishInitNetAccess();
 
     OTInetHostToString((InetHost)addr.s_addr, sHostInfo.name);
     
     return sHostInfo.name;
 }
 
 
 PRStatus _MD_gethostname(char *name, int namelen)
 {
     OSStatus err;
     InetInterfaceInfo info;
 
-    	_MD_FinishInitNetAccess();
+    _MD_FinishInitNetAccess();
 
     /*
      *    On a Macintosh, we don't have the concept of a local host name.
      *    We do though have an IP address & everyone should be happy with
      *     a string version of that for a name.
      *    The alternative here is to ping a local DNS for our name, they
      *    will often know it.  This is the cheap, easiest, and safest way out.
      */
@@ -2159,15 +2202,15 @@ int _MD_mac_get_nonblocking_connect_erro
         case T_OUTCON:
             macsock_map_error(EINPROGRESS);
             return -1;
         case T_DATAXFER:
             return 0;
         case T_IDLE:
             return -1;
         case T_INREL:
-        	macsock_map_error(ENOTCONN);
-        	return -1;
+            macsock_map_error(ENOTCONN);
+            return -1;
         default:
             PR_ASSERT(0);
             return -1;
     }
 }