summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgordon%netscape.com <devnull@localhost>2000-10-10 20:52:17 +0000
committergordon%netscape.com <devnull@localhost>2000-10-10 20:52:17 +0000
commit3630369098fba08f9321f02dfff5b8c755f320d2 (patch)
tree4c703451cad2ea773590f4b93dae8c9ec2232948
parent9fe845c92575ac1b080e38aa47d1c9bd4e4470b2 (diff)
downloadnspr-hg-3630369098fba08f9321f02dfff5b8c755f320d2.tar.gz
Fix for bug 49990 "Networking fails after sleep/wake cycle" on Mac. rtm+, r=pinkerton, wtc, sr =sfraser. Added support for provide will/has closed OT events.XBL_FORMS_20001011_BASE
-rw-r--r--pr/src/md/mac/macsockotpt.c63
1 files changed, 42 insertions, 21 deletions
diff --git a/pr/src/md/mac/macsockotpt.c b/pr/src/md/mac/macsockotpt.c
index 4fc643f2..4970a885 100644
--- a/pr/src/md/mac/macsockotpt.c
+++ b/pr/src/md/mac/macsockotpt.c
@@ -51,7 +51,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);
@@ -106,14 +105,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! */
}
@@ -121,8 +119,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 */
@@ -132,25 +137,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
}
@@ -470,7 +497,6 @@ PRInt32 _MD_socket(int domain, int type, int protocol)
OSStatus err;
EndpointRef endpoint;
- if (!gOTInitialized)
_MD_FinishInitNetAccess();
// We only deal with internet domain
@@ -1863,7 +1889,6 @@ PR_IMPLEMENT(unsigned long) inet_addr(const char *cp)
OSStatus err;
InetHost host;
- if (!gOTInitialized)
_MD_FinishInitNetAccess();
err = OTInetStringToHost((char*) cp, &host);
@@ -1886,7 +1911,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;
@@ -1927,7 +1951,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);
@@ -1938,7 +1961,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);
@@ -1952,7 +1974,6 @@ PRStatus _MD_gethostname(char *name, int namelen)
OSStatus err;
InetInterfaceInfo info;
- if (!gOTInitialized)
_MD_FinishInitNetAccess();
/*