diff --git a/ChangeLog b/ChangeLog index f945e54ee..bd1f1cb57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-01-23 Richard Frith-Macdonald + + * Source/win32/NSMessagePortNameServerWin32.m: + * Source/win32/NSMessagePortWin32.m: + Bugfixes to try to make win32 nameserver operation more reliable. + 2007-01-19 Richard Frith-Macdonald * Tools/defaults.m: Make errors go to stderr and be more informative. diff --git a/Source/win32/NSMessagePortWin32.m b/Source/win32/NSMessagePortWin32.m index 9395ced70..436a04edc 100644 --- a/Source/win32/NSMessagePortWin32.m +++ b/Source/win32/NSMessagePortWin32.m @@ -206,12 +206,6 @@ static Class messagePortClass = 0; p = [[self alloc] initWithName: name]; } M_UNLOCK(messagePortLock); - if ([p _setupSendPort] == NO) - { - NSLog(@"unable to access mailslot '%@' - %@", - [p name], [NSError _last]); - DESTROY(p); - } return p; } @@ -364,6 +358,7 @@ static Class messagePortClass = 0; - (id) initWithName: (NSString*)name { NSMessagePort *p; + BOOL found = NO; M_LOCK(messagePortLock); p = RETAIN((NSMessagePort*)NSMapGet(ports, (void*)name)); @@ -385,15 +380,34 @@ static Class messagePortClass = 0; this->rEvent = INVALID_HANDLE_VALUE; this->wHandle = INVALID_HANDLE_VALUE; this->wEvent = INVALID_HANDLE_VALUE; - - NSMapInsert(ports, (void*)this->name, (void*)self); - NSDebugMLLog(@"NSMessagePort", @"Created speaking port: %@", self); } else { + found = YES; RELEASE(self); self = p; } + + /* This is a 'speaking' port ... set it up for write operation + * if necessary. + * NB. This must be done (to create the mailbox) before the port + * is added to the nameserver mapping ... or nother process might + * try to access the mailbox before it exists. + */ + if ([self _setupSendPort] == NO) + { + NSLog(@"unable to access mailslot '%@' - %@", + [self name], [NSError _last]); + DESTROY(self); + } + + if (self != nil && found == NO) + { + /* This was newly created ... add to map so that it can be found. + */ + NSMapInsert(ports, (void*)[self name], (void*)self); + NSDebugMLLog(@"NSMessagePort", @"Created speaking port: %@", self); + } M_UNLOCK(messagePortLock); return self; }