Merging changes from the Netscape_20000922_BRANCH (as of 10/14/00 01:04am) EMBEDDING_08042000_BRANCH
authorrpotts%netscape.com
Wed, 18 Oct 2000 04:34:42 +0000
branchEMBEDDING_08042000_BRANCH
changeset 1600 3a6e77b887a7faa18c1a470aa03fae9c7c5c5285
parent 1570 dd66622604d601699a82182aed755a44d6abe5c2
child 1624 f58bd65db849c652b12bcd5860310fa7da887e36
push idunknown
push userunknown
push dateunknown
Merging changes from the Netscape_20000922_BRANCH (as of 10/14/00 01:04am)
lib/libc/src/strccmp.c
pr/src/md/mac/macsockotpt.c
--- a/lib/libc/src/strccmp.c
+++ b/lib/libc/src/strccmp.c
@@ -30,17 +30,33 @@ static const unsigned char uc[] =
     '8',    '9',    ':',    ';',    '<',    '=',    '>',    '?',
     '@',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
     'X',    'Y',    'Z',    '[',    '\\',   ']',    '^',    '_',
     '`',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
-    'X',    'Y',    'Z',    '{',    '|',    '}',    '~',    '\177'
+    'X',    'Y',    'Z',    '{',    '|',    '}',    '~',    '\177',
+    '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
+    '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
+    '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
+    '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
+    '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
+    '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
+    '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
+    '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
+    '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
+    '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
+    '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
+    '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
+    '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
+    '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
+    '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
+    '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377'
 };
 
 PR_IMPLEMENT(PRIntn)
 PL_strcasecmp(const char *a, const char *b)
 {
     const unsigned char *ua = (const unsigned char *)a;
     const unsigned char *ub = (const unsigned char *)b;
 
--- a/pr/src/md/mac/macsockotpt.c
+++ b/pr/src/md/mac/macsockotpt.c
@@ -46,17 +46,16 @@ typedef enum SndRcvOpCode {
 
 static struct {
 	PRLock *    lock;
 	InetSvcRef  serviceRef;
 	PRThread *  thread;
 	void *      cookie;
 } dnsContext;
 
-static PRBool gOTInitialized;
 
 static pascal void  DNSNotifierRoutine(void * contextPtr, OTEventCode code, OTResult result, void * cookie);
 static pascal void  NotifierRoutine(void * contextPtr, OTEventCode code, OTResult result, void * cookie);
 static pascal void  RawEndpointNotifierRoutine(void * contextPtr, OTEventCode code, OTResult result, void * cookie);
 
 static PRBool GetState(PRFileDesc *fd, PRBool *readReady, PRBool *writeReady, PRBool *exceptReady);
 
 extern void WaitOnThisThread(PRThread *thread, PRIntervalTime timeout);
@@ -101,61 +100,89 @@ void _MD_InitNetAccess()
 
     DNSNotifierRoutineUPP	=  NewOTNotifyUPP(DNSNotifierRoutine);
     NotifierRoutineUPP		=  NewOTNotifyUPP(NotifierRoutine);
     RawEndpointNotifierRoutineUPP = NewOTNotifyUPP(RawEndpointNotifierRoutine);
 
     errOT = INIT_OPEN_TRANSPORT();
     PR_ASSERT(err == kOTNoError);
 
+	dnsContext.serviceRef = NULL;
 	dnsContext.lock = PR_NewLock();
 	PR_ASSERT(dnsContext.lock != NULL);
 
 	dnsContext.thread = _PR_MD_CURRENT_THREAD();
 	dnsContext.cookie = NULL;
-	
-	gOTInitialized = PR_FALSE;
-	
+		
 /* XXX Does not handle absence of open tpt and tcp yet! */
 }
 
 static void _MD_FinishInitNetAccess()
 {
     OSStatus    errOT;
 
+	if (dnsContext.serviceRef)
+		return;
+		
     dnsContext.serviceRef = OT_OPEN_INTERNET_SERVICES(kDefaultInternetServicesPath, NULL, &errOT);
-    if (errOT != kOTNoError) return;    /* no network -- oh well */
+    if (errOT != kOTNoError) {
+        dnsContext.serviceRef = NULL;
+        return;    /* no network -- oh well */
+    }
+    
     PR_ASSERT((dnsContext.serviceRef != NULL) && (errOT == kOTNoError));
 
     /* Install notify function for DNR Address To String completion */
     errOT = OTInstallNotifier(dnsContext.serviceRef, DNSNotifierRoutineUPP, &dnsContext);
     PR_ASSERT(errOT == kOTNoError);
 
     /* Put us into async mode */
     errOT = OTSetAsynchronous(dnsContext.serviceRef);
     PR_ASSERT(errOT == kOTNoError);
-    
-    gOTInitialized = PR_TRUE;
 }
 
 
-static pascal void  DNSNotifierRoutine(void * contextPtr, OTEventCode code, OTResult result, void * cookie)
+static pascal void  DNSNotifierRoutine(void * contextPtr, OTEventCode otEvent, OTResult result, void * cookie)
 {
 #pragma unused(contextPtr)
     _PRCPU *    cpu    = _PR_MD_CURRENT_CPU(); 
+	OSStatus    errOT;
+
+	dnsContext.thread->md.osErrCode = result;
+	dnsContext.cookie = cookie;
 	
-	if (code == T_DNRSTRINGTOADDRCOMPLETE) {
-		dnsContext.thread->md.osErrCode = result;
-		dnsContext.cookie = cookie;
-		if (_PR_MD_GET_INTSOFF()) {
-			cpu->u.missed[cpu->where] |= _PR_MISSED_IO;
-			dnsContext.thread->md.missedIONotify = PR_TRUE;
-			return;
-		}
-		DoneWaitingOnThisThread(dnsContext.thread);
+	switch (otEvent) {
+		case T_DNRSTRINGTOADDRCOMPLETE:
+				if (_PR_MD_GET_INTSOFF()) {
+					cpu->u.missed[cpu->where] |= _PR_MISSED_IO;
+					dnsContext.thread->md.missedIONotify = PR_TRUE;
+					return;
+				}
+				DoneWaitingOnThisThread(dnsContext.thread);
+				break;
+		
+        case kOTProviderWillClose:
+                errOT = OTSetSynchronous(dnsContext.serviceRef);
+                // fall through to kOTProviderIsClosed case
+		
+        case kOTProviderIsClosed:
+                errOT = OTCloseProvider((ProviderRef)dnsContext.serviceRef);
+                dnsContext.serviceRef = nil;
+
+				if (_PR_MD_GET_INTSOFF()) {
+					cpu->u.missed[cpu->where] |= _PR_MISSED_IO;
+					dnsContext.thread->md.missedIONotify = PR_TRUE;
+					return;
+				}
+				DoneWaitingOnThisThread(dnsContext.thread);
+                break;
+
+        default: // or else we don't handle the event
+	            PR_ASSERT(otEvent==NULL);
+		
 	}
 	// or else we don't handle the event
 }
 
 
 static void macsock_map_error(OSStatus err)
 {
     _PR_MD_CURRENT_THREAD()->md.osErrCode = err;
@@ -465,18 +492,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;
     
-    if (!gOTInitialized)
-    	_MD_FinishInitNetAccess();
+    _MD_FinishInitNetAccess();
 
     // We only deal with internet domain
     if (domain != AF_INET) {
         err = kEPROTONOSUPPORTErr;
         goto ErrorExit;
     }
     
     // We only know about tcp & udp
@@ -1434,19 +1460,16 @@ static PRInt32 SendReceiveStream(PRFileD
 
         if (result > 0) {
             buf = (void *) ( (UInt32) buf + (UInt32)result );
             bytesLeft -= result;
             if (opCode == kSTREAM_RECEIVE)
                 return result;
         } else {
 			switch (result) {
-				case kOTOutStateErr:			// it has been closed
-                    return 0;
-				
 				case kOTLookErr:
 				    PR_ASSERT(!"call to OTLook() required after all.");
 					break;
 				
 				case kOTFlowErr:
 				case kOTNoDataErr:
 				case kEAGAINErr:
 				case kEWOULDBLOCKErr:
@@ -1456,16 +1479,17 @@ static PRInt32 SendReceiveStream(PRFileD
 					}
 
 					WaitOnThisThread(me, timeout);
 					err = me->md.osErrCode;
 					if (err != kOTNoError)
 						goto ErrorExit;				
 					break;
 					
+				case kOTOutStateErr:	// it has been closed, fall through for error
 				default:
 					err = result;
 					goto ErrorExit;
 			}
 		}
     }
 
     PR_ASSERT(opCode == kSTREAM_SEND ? fd->secret->md.write.thread == nil :
@@ -1858,18 +1882,17 @@ ErrorExit:
 }                               
 
 
 PR_IMPLEMENT(unsigned long) inet_addr(const char *cp)
 {
     OSStatus err;
     InetHost host;    
 
-    if (!gOTInitialized)
-    	_MD_FinishInitNetAccess();
+    _MD_FinishInitNetAccess();
 
     err = OTInetStringToHost((char*) cp, &host);
     if (err != kOTNoError)
         return -1;
     
     return host;
 }
 
@@ -1881,18 +1904,17 @@ static InetHost *sAddresses[kMaxHostAddr
 
 
 PR_IMPLEMENT(struct hostent *) gethostbyname(const char * name)
 {
     OSStatus err;
     PRUint32 index;
     PRThread *me = _PR_MD_CURRENT_THREAD();
 
-    if (!gOTInitialized)
-    	_MD_FinishInitNetAccess();
+    _MD_FinishInitNetAccess();
 
     me->io_pending       = PR_TRUE;
     me->io_fd            = NULL;
     me->md.osErrCode     = noErr;
 	
 	PR_Lock(dnsContext.lock);	// so we can safely store our thread ptr in dnsContext
 	dnsContext.thread = me;		// so we know what thread to wake up when OTInetStringToAddress completes
 
@@ -1922,43 +1944,40 @@ ErrorExit:
 }
 
 
 PR_IMPLEMENT(struct hostent *) gethostbyaddr(const void *addr, int addrlen, int type)
 {
     PR_ASSERT(type == AF_INET);
     PR_ASSERT(addrlen == sizeof(struct in_addr));
 
-    if (!gOTInitialized)
-    	_MD_FinishInitNetAccess();
+    _MD_FinishInitNetAccess();
 
     OTInetHostToString((InetHost)addr, sHostInfo.name);
     
     return (gethostbyname(sHostInfo.name));
 }
 
 
 PR_IMPLEMENT(char *) inet_ntoa(struct in_addr addr)
 {
-    if (!gOTInitialized)
-    	_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;
 
-    if (!gOTInitialized)
-    	_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.
      */