From 7e3061d98b7861dcf848e169f44406a41f49925e Mon Sep 17 00:00:00 2001 From: "gordon%netscape.com" Date: Tue, 10 Oct 2000 21:25:27 +0000 Subject: [PATCH] Fix for bug 49990 "Networking fails after sleep/wake cycle" on Mac. rtm+, r=pinkerton, sr =sfraser. Added support for provide will/has closed OT events. --- nsprpub/pr/src/md/mac/macsockotpt.c | 63 +++++++++++++++++++---------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/nsprpub/pr/src/md/mac/macsockotpt.c b/nsprpub/pr/src/md/mac/macsockotpt.c index a68773daea1..0a8e01e1302 100644 --- a/nsprpub/pr/src/md/mac/macsockotpt.c +++ b/nsprpub/pr/src/md/mac/macsockotpt.c @@ -67,7 +67,6 @@ static struct { 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); @@ -122,14 +121,13 @@ void _MD_InitNetAccess() 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! */ } @@ -137,8 +135,15 @@ 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 */ @@ -148,25 +153,47 @@ static void _MD_FinishInitNetAccess() /* 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(); - - if (code == T_DNRSTRINGTOADDRCOMPLETE) { + OSStatus errOT; + 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 } @@ -486,7 +513,6 @@ PRInt32 _MD_socket(int domain, int type, int protocol) OSStatus err; EndpointRef endpoint; - if (!gOTInitialized) _MD_FinishInitNetAccess(); // We only deal with internet domain @@ -1894,7 +1920,6 @@ PR_IMPLEMENT(unsigned long) inet_addr(const char *cp) OSStatus err; InetHost host; - if (!gOTInitialized) _MD_FinishInitNetAccess(); err = OTInetStringToHost((char*) cp, &host); @@ -1917,7 +1942,6 @@ PR_IMPLEMENT(struct hostent *) gethostbyname(const char * name) PRUint32 index; PRThread *me = _PR_MD_CURRENT_THREAD(); - if (!gOTInitialized) _MD_FinishInitNetAccess(); me->io_pending = PR_TRUE; @@ -1958,7 +1982,6 @@ PR_IMPLEMENT(struct hostent *) gethostbyaddr(const void *addr, int addrlen, int PR_ASSERT(type == AF_INET); PR_ASSERT(addrlen == sizeof(struct in_addr)); - if (!gOTInitialized) _MD_FinishInitNetAccess(); OTInetHostToString((InetHost)addr, sHostInfo.name); @@ -1969,7 +1992,6 @@ PR_IMPLEMENT(struct hostent *) gethostbyaddr(const void *addr, int addrlen, int PR_IMPLEMENT(char *) inet_ntoa(struct in_addr addr) { - if (!gOTInitialized) _MD_FinishInitNetAccess(); OTInetHostToString((InetHost)addr.s_addr, sHostInfo.name); @@ -1983,7 +2005,6 @@ PRStatus _MD_gethostname(char *name, int namelen) OSStatus err; InetInterfaceInfo info; - if (!gOTInitialized) _MD_FinishInitNetAccess(); /*