From 1ba4b76c034c2a8a431cabcfc74376788cfdff64 Mon Sep 17 00:00:00 2001
From: CaS
*/
typedef struct _NSHashTableCallBacks
{
- /** hash() ... Hashing function. NOTE: Elements with equal values must have
+ /** hash ... Hashing function. NOTE: Elements with equal values must have
* equal hash function values.
*/
unsigned int (*hash)(NSHashTable *, const void *);
- /** isEqual() ... Comparison function.
*/
+ /** isEqual ... Comparison function.
*/
BOOL (*isEqual)(NSHashTable *, const void *, const void *);
- /** retain() ... Retaining function called when adding elements
+ /** retain ... Retaining function called when adding elements
* to the table.
*/
void (*retain)(NSHashTable *, const void *);
- /** release() ... Releasing function called when a data element is
+ /** release ... Releasing function called when a data element is
* removed from the table.
*/
void (*release)(NSHashTable *, void *);
- /** describe() ... Description function.
*/
+ /** describe ... Description function.
*/
NSString *(*describe)(NSHashTable *, const void *);
} NSHashTableCallBacks;
diff --git a/Headers/gnustep/base/NSPort.h b/Headers/gnustep/base/NSPort.h
index 83f90e83f..f8b581938 100644
--- a/Headers/gnustep/base/NSPort.h
+++ b/Headers/gnustep/base/NSPort.h
@@ -22,6 +22,7 @@
AutogsdocSource: NSPort.m
AutogsdocSource: NSSocketPort.m
+ AutogsdocSource: NSMessagePort.m
*/
#ifndef __NSPort_h_GNUSTEP_BASE_INCLUDE
@@ -115,9 +116,9 @@ typedef SOCKET NSSocketNativeHandle;
}
+ (NSSocketPort*) existingPortWithNumber: (gsu16)number
- onHost: (NSHost*)host;
+ onHost: (NSHost*)aHost;
+ (NSSocketPort*) portWithNumber: (gsu16)number
- onHost: (NSHost*)host
+ onHost: (NSHost*)aHost
forceAddress: (NSString*)addr
listener: (BOOL)shouldListen;
@@ -129,7 +130,7 @@ typedef SOCKET NSSocketNativeHandle;
- (void) handlePortMessage: (NSPortMessage*)m;
- (NSHost*) host;
- (gsu16) portNumber;
-- (void) removeHandle: (GSTcpHandle*)h;
+- (void) removeHandle: (GSTcpHandle*)handle;
/*
{
@@ -178,7 +179,7 @@ typedef SOCKET NSSocketNativeHandle;
- (int) _listener;
- (const unsigned char *) _name;
-+ (NSMessagePort*) _portWithName: (const unsigned char *)name
++ (NSMessagePort*) _portWithName: (const unsigned char *)socketName
listener: (BOOL)shouldListen;
- (void) addHandle: (GSMessageHandle*)handle forSend: (BOOL)send;
diff --git a/Headers/gnustep/base/NSPortNameServer.h b/Headers/gnustep/base/NSPortNameServer.h
index 81d879290..5ac64f686 100644
--- a/Headers/gnustep/base/NSPortNameServer.h
+++ b/Headers/gnustep/base/NSPortNameServer.h
@@ -1,5 +1,5 @@
-/* Interface of NSPortNameServer class for Distributed Objects
- Copyright (C) 1998,1999 Free Software Foundation, Inc.
+/** Interface of NSPortNameServer class for Distributed Objects
+ Copyright (C) 1998,1999,2003 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald
* The function to write the data is pointed to by
diff --git a/Source/NSMessagePortNameServer.m b/Source/NSMessagePortNameServer.m
index 8bf4109f0..f4d1f6b64 100644
--- a/Source/NSMessagePortNameServer.m
+++ b/Source/NSMessagePortNameServer.m
@@ -74,31 +74,27 @@ static void clean_up_names(void)
{
if (defaultServer == nil)
{
- NSMessagePortNameServer *s;
-
[serverLock lock];
- if (defaultServer)
+ if (defaultServer == nil)
{
- [serverLock unlock];
- return defaultServer;
+ defaultServer = (NSMessagePortNameServer *)NSAllocateObject(self,
+ 0, NSDefaultMallocZone());
}
- s = (NSMessagePortNameServer *)NSAllocateObject(self, 0, NSDefaultMallocZone());
- defaultServer = s;
[serverLock unlock];
}
return defaultServer;
}
-+(NSString *) _pathForName: (NSString *)name
++ (NSString *) _pathForName: (NSString *)name
{
- NSString *path;
-static NSString *base_path = nil;
+ static NSString *base_path = nil;
+ NSString *path;
[serverLock lock];
if (!base_path)
{
- path=NSTemporaryDirectory();
+ path = NSTemporaryDirectory();
path = [path stringByAppendingPathComponent: @"NSMessagePort"];
mkdir([path fileSystemRepresentation], 0700);
@@ -119,11 +115,11 @@ static NSString *base_path = nil;
}
-+(BOOL) _livePort: (NSString *)path
++ (BOOL) _livePort: (NSString *)path
{
- FILE *f;
- char socket_path[512];
- int pid;
+ FILE *f;
+ char socket_path[512];
+ int pid;
struct stat sb;
NSDebugLLog(@"NSMessagePort", @"_livePort: %@", path);
@@ -142,58 +138,57 @@ static NSString *base_path = nil;
fclose(f);
- if (stat(socket_path,&sb)<0)
+ if (stat(socket_path, &sb) < 0)
{
unlink([path fileSystemRepresentation]);
NSDebugLLog(@"NSMessagePort", @"not live, couldn't stat socket (%m)");
return NO;
}
- if (kill(pid,0)<0)
+ if (kill(pid, 0) < 0)
{
unlink([path fileSystemRepresentation]);
unlink(socket_path);
NSDebugLLog(@"NSMessagePort", @"not live, no such process (%m)");
return NO;
}
+ else
+ {
+ struct sockaddr_un sockAddr;
+ int desc;
- {
- struct sockaddr_un sockAddr;
- int desc;
+ memset(&sockAddr, '\0', sizeof(sockAddr));
+ sockAddr.sun_family = AF_LOCAL;
+ strncpy(sockAddr.sun_path, socket_path, sizeof(sockAddr.sun_path));
- memset(&sockAddr, '\0', sizeof(sockAddr));
- sockAddr.sun_family = AF_LOCAL;
- strncpy(sockAddr.sun_path, socket_path, sizeof(sockAddr.sun_path));
-
- if ((desc = socket(PF_LOCAL, SOCK_STREAM, PF_UNSPEC)) < 0)
- {
- unlink([path fileSystemRepresentation]);
- unlink(socket_path);
- NSDebugLLog(@"NSMessagePort", @"couldn't create socket, assuming not live (%m)");
- return NO;
- }
- if (connect(desc, (struct sockaddr*)&sockAddr, SUN_LEN(&sockAddr)) < 0)
- {
- unlink([path fileSystemRepresentation]);
- unlink(socket_path);
- NSDebugLLog(@"NSMessagePort", @"not live, can't connect (%m)");
- return NO;
- }
- close(desc);
- }
-
-
- NSDebugLLog(@"NSMessagePort", @"port is live");
- return YES;
+ if ((desc = socket(PF_LOCAL, SOCK_STREAM, PF_UNSPEC)) < 0)
+ {
+ unlink([path fileSystemRepresentation]);
+ unlink(socket_path);
+ NSDebugLLog(@"NSMessagePort",
+ @"couldn't create socket, assuming not live (%m)");
+ return NO;
+ }
+ if (connect(desc, (struct sockaddr*)&sockAddr, SUN_LEN(&sockAddr)) < 0)
+ {
+ unlink([path fileSystemRepresentation]);
+ unlink(socket_path);
+ NSDebugLLog(@"NSMessagePort", @"not live, can't connect (%m)");
+ return NO;
+ }
+ close(desc);
+ NSDebugLLog(@"NSMessagePort", @"port is live");
+ return YES;
+ }
}
-- (NSPort *) portForName: (NSString *)name
+- (NSPort*) portForName: (NSString *)name
onHost: (NSString *)host
{
- NSString *path;
- FILE *f;
- char socket_path[512];
+ NSString *path;
+ FILE *f;
+ char socket_path[512];
NSDebugLLog(@"NSMessagePort", @"portForName: %@ host: %@", name, host);
@@ -203,8 +198,8 @@ static NSString *base_path = nil;
return nil;
}
- path = [isa _pathForName: name];
- if (![isa _livePort: path])
+ path = [[self class] _pathForName: name];
+ if (![[self class] _livePort: path])
{
NSDebugLLog(@"NSMessagePort", @"not a live port");
return nil;
@@ -228,24 +223,26 @@ static NSString *base_path = nil;
}
- (BOOL) registerPort: (NSPort *)port
- forName: (NSString *)name
+ forName: (NSString *)name
{
- int fd;
- unsigned char buf[32];
- NSString *path;
- const unsigned char *socket_name;
+ int fd;
+ unsigned char buf[32];
+ NSString *path;
+ const unsigned char *socket_name;
+ NSMutableArray *a;
NSDebugLLog(@"NSMessagePort", @"register %@ as %@\n", port, name);
- if (![port isKindOfClass: [NSMessagePort class]])
+ if ([port isKindOfClass: [NSMessagePort class]] == NO)
{
[NSException raise: NSInvalidArgumentException
- format: @"Attempted to register a non-NSMessagePort with NSMessagePortNameServer"];
+ format: @"Attempted to register a non-NSMessagePort (%@)",
+ port];
return NO;
}
- path=[isa _pathForName: name];
+ path = [[self class] _pathForName: name];
- if ([isa _livePort: path])
+ if ([[self class] _livePort: path])
{
NSDebugLLog(@"NSMessagePort", @"fail, is a live port");
return NO;
@@ -267,38 +264,35 @@ static NSString *base_path = nil;
close(fd);
- {
- NSMutableArray *a;
+ [serverLock lock];
+ a = NSMapGet(portToNamesMap, port);
+ if (!a)
+ {
+ a = [[NSMutableArray alloc] init];
+ NSMapInsert(portToNamesMap, port, a);
+ RELEASE(a);
+ }
- [serverLock lock];
- a = NSMapGet(portToNamesMap, port);
- if (!a)
- {
- a = [[NSMutableArray alloc] init];
- NSMapInsert(portToNamesMap, port, a);
- RELEASE(a);
- }
-
- [a addObject: [name copy]];
- [serverLock unlock];
- }
+ [a addObject: [name copy]];
+ [serverLock unlock];
return YES;
}
- (BOOL) removePortForName: (NSString *)name
{
- NSString *path;
+ NSString *path;
NSDebugLLog(@"NSMessagePort", @"removePortForName: %@", name);
- path=[isa _pathForName: name];
+ path = [[self class] _pathForName: name];
unlink([path fileSystemRepresentation]);
return YES;
}
- (NSArray *) namesForPort: (NSPort *)port
{
- NSMutableArray *a;
+ NSMutableArray *a;
+
[serverLock lock];
a = NSMapGet(portToNamesMap, port);
a = [a copy];
@@ -309,7 +303,7 @@ static NSString *base_path = nil;
- (BOOL) removePort: (NSPort *)port
{
NSMutableArray *a;
- int i;
+ int i;
NSDebugLLog(@"NSMessagePort", @"removePort: %@", port);
@@ -329,14 +323,14 @@ static NSString *base_path = nil;
- (BOOL) removePort: (NSPort*)port forName: (NSString*)name
{
- FILE *f;
- char socket_path[512];
- NSString *path;
- const unsigned char *port_path;
+ FILE *f;
+ char socket_path[512];
+ NSString *path;
+ const unsigned char *port_path;
NSDebugLLog(@"NSMessagePort", @"removePort: %@ forName: %@", port, name);
- path = [isa _pathForName: name];
+ path = [[self class] _pathForName: name];
f = fopen([path fileSystemRepresentation], "rt");
if (!f)
diff --git a/Source/NSPortNameServer.m b/Source/NSPortNameServer.m
index 877d0324e..7b3530126 100644
--- a/Source/NSPortNameServer.m
+++ b/Source/NSPortNameServer.m
@@ -26,41 +26,16 @@
#include "config.h"
#include "Foundation/NSString.h"
-#include "Foundation/NSByteOrder.h"
#include "Foundation/NSException.h"
-#include "Foundation/NSAutoreleasePool.h"
-#include "Foundation/NSLock.h"
-#include "Foundation/NSFileHandle.h"
-#include "Foundation/NSRunLoop.h"
-#include "Foundation/NSNotificationQueue.h"
-#include "Foundation/NSPort.h"
-#include "Foundation/NSMapTable.h"
-#include "Foundation/NSSet.h"
-#include "Foundation/NSHost.h"
-#include "Foundation/NSTask.h"
-#include "Foundation/NSDate.h"
-#include "Foundation/NSTimer.h"
-#include "Foundation/NSPathUtilities.h"
#include "Foundation/NSPortNameServer.h"
#include "Foundation/NSDebug.h"
-#ifdef __MINGW__
-#include
+ * The MacOS-X documentation says that this is a nameserver
+ * dealing with NSMessagePort objects, but that is incompatible
+ * with OpenStep/OPENSTEP/NeXTstep behavior, so GNUstep returns
+ * a name server which deals with NSSocketPort objects capable
+ * of being used for inter-host communications.
+ */
+ (id) systemDefaultPortNameServer
{
return [NSSocketPortNameServer sharedInstance];
@@ -89,11 +72,29 @@
format: @"attempt to deallocate default port name server"];
}
+/**
+ * Looks up the port with the specified name on the local host and
+ * returns it or nil if no port is found with that name.
+ * Different nameservers have different namespaces appropriate to the
+ * type of port they deal with, so failing to find a named port with one
+ * nameserver does not guarantee that a port does with that name does
+ * not exist.
+ * This is a convenience method calling -portForName:onHost: with a nil
+ * host argument.
+ */
- (NSPort*) portForName: (NSString*)name
{
return [self portForName: name onHost: nil];
}
+/**
+ * Different nameservers have different namespaces appropriate to the
+ * type of port they deal with, so failing to find a named port with one
+ * nameserver does not guarantee that a port does with that name does
+ * not exist.
+ */
- (NSPort*) portForName: (NSString*)name
onHost: (NSString*)host
{
@@ -101,6 +102,15 @@
return nil;
}
+/**
+ * Returns YES on success, NO otherwise.
+ * The common cause for failure is that another port is already registered
+ * with the name.
+ * Raises NSInvalidArgumentException if given bad arguments.
+ */
- (BOOL) registerPort: (NSPort*)port
forName: (NSString*)name
{
@@ -108,6 +118,13 @@
return NO;
}
+/**
+ * The common cause for failure is that no port is registered
+ * with the name.
+ * Raises NSInvalidArgumentException if given bad arguments.
+ */
- (BOOL) removePortForName: (NSString*)name
{
[self subclassResponsibility: _cmd];
@@ -119,7 +136,8 @@
* Some extensions to make cleaning up port names easier.
*/
@implementation NSPortNameServer (GNUstep)
-/** Return all names for port
+/**
+ * Use the +sharedInstance method to get a nameserver, rather than
+ * allocating and initialising one.
+ */
@implementation NSSocketPortNameServer
+ (id) allocWithZone: (NSZone*)aZone
@@ -550,6 +557,9 @@ typedef enum {
}
}
+/**
+ * Returns the shared name server object for the process.
+ */
+ (id) sharedInstance
{
if (defaultServer == nil)
@@ -562,7 +572,8 @@ typedef enum {
[serverLock unlock];
return defaultServer;
}
- s = (NSSocketPortNameServer*)NSAllocateObject(self, 0, NSDefaultMallocZone());
+ s = (NSSocketPortNameServer*)NSAllocateObject(self, 0,
+ NSDefaultMallocZone());
s->_portMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks,
NSObjectMapValueCallBacks, 0);
s->_nameMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
@@ -674,11 +685,12 @@ typedef enum {
NS_HANDLER
{
/*
- * If we had a problem - unlock before continueing.
+ * If we had a problem - unlock before continuing.
*/
RELEASE(com);
[serverLock unlock];
- [localException raise];
+ NSDebugMLLog(@"NSSocketPortNameServer", @"%@", localException);
+ return NO;
}
NS_ENDHANDLER
[serverLock unlock];
@@ -778,10 +790,11 @@ typedef enum {
NS_HANDLER
{
/*
- * If we had a problem - unlock before continueing.
+ * If we had a problem - unlock before continuing.
*/
[serverLock unlock];
- [localException raise];
+ NSDebugMLLog(@"NSSocketPortNameServer", @"%@", localException);
+ return NO;
}
NS_ENDHANDLER
[serverLock unlock];
@@ -848,6 +861,11 @@ typedef enum {
[NSException raise: NSInvalidArgumentException
format: @"attempt to register nil port"];
}
+ if ([port isKindOfClass: [NSSocketPort class]] == NO)
+ {
+ [NSException raise: NSInvalidArgumentException
+ format: @"attempt to register non-NSSocketPort (%@)", port];
+ }
len = [name cStringLength];
if (len == 0)
{
@@ -890,7 +908,8 @@ typedef enum {
if ([known count] == 0)
{
com = [GSPortCom new];
- [com startPortUnregistration: [(NSSocketPort *)port portNumber] withName: nil];
+ [com startPortUnregistration: [(NSSocketPort*)port portNumber]
+ withName: nil];
while ([limit timeIntervalSinceNow] > 0 && [com isActive] == YES)
{
[loop runMode: mode
@@ -906,7 +925,8 @@ typedef enum {
}
com = [GSPortCom new];
- [com startPortRegistration: [(NSSocketPort *)port portNumber] withName: name];
+ [com startPortRegistration: [(NSSocketPort*)port portNumber]
+ withName: name];
while ([limit timeIntervalSinceNow] > 0 && [com isActive] == YES)
{
[loop runMode: mode beforeDate: limit];
@@ -987,11 +1007,12 @@ typedef enum {
NS_HANDLER
{
/*
- * If we had a problem - close and unlock before continueing.
+ * If we had a problem - close and unlock before continuing.
*/
DESTROY(com);
[serverLock unlock];
- [localException raise];
+ NSDebugMLLog(@"NSSocketPortNameServer", @"%@", localException);
+ return NO;
}
NS_ENDHANDLER
[serverLock unlock];
@@ -1090,11 +1111,11 @@ typedef enum {
NS_HANDLER
{
/*
- * If we had a problem - unlock before continueing.
+ * If we had a problem - unlock before continuing.
*/
RELEASE(com);
- [serverLock unlock];
- [localException raise];
+ NSDebugMLLog(@"NSSocketPortNameServer", @"%@", localException);
+ val = NO;
}
NS_ENDHANDLER
[serverLock unlock];
@@ -1159,7 +1180,8 @@ typedef enum {
NS_HANDLER
{
[serverLock unlock];
- [localException raise];
+ NSDebugMLLog(@"NSSocketPortNameServer", @"%@", localException);
+ return NO;
}
NS_ENDHANDLER
[serverLock unlock];
diff --git a/Source/NSUndoManager.m b/Source/NSUndoManager.m
index c69c32f45..5341659ee 100644
--- a/Source/NSUndoManager.m
+++ b/Source/NSUndoManager.m
@@ -1,4 +1,4 @@
-/** Implementatikon for
+ * technique.
* You generally never invoke this method directly.
* Instead invoke [-prepareWithInvocationTarget:] with the target of the
* undo action and then invoke the targets method to undo the action
@@ -388,16 +388,16 @@ NSString *NSUndoManagerWillUndoChangeNotification =
* which actually is the undo manager.
* The runtime will then fallback to -forwardInvocation: to do the actual
* registration of the invocation.
- * The invocation will added to the current grouping.
+ * The invocation will added to the current grouping.
* If the registrations have been disabled through [-disableUndoRegistration],
- * this method does nothing.
+ * this method does nothing.
* Unless the reciever implicitly
* groups operations by event, the this method must have been preceeded
* with a [-beginUndoGrouping] message. Otherwise it will raise an
- * NSInternalInconsistencyException.
+ * NSInternalInconsistencyException.
* Unless this method is invoked as part of a [-undo] or [-undoNestedGroup]
- * processing, the redo stack is cleared.
- * If the reciever [-groupsByEvents] and this is the first call to this
+ * processing, the redo stack is cleared.
+ * If the reciever [-groupsByEvent] and this is the first call to this
* method since the last run loop processing, this method sets up
* the reciever to process the [-endUndoGrouping] at the
* end of the event loop.
@@ -554,7 +554,7 @@ NSString *NSUndoManagerWillUndoChangeNotification =
* Prepares the receiver to registers an invocation-based undo operation.
* This method is part of the NSInvocation-based undo registration
* as opposed to the simpler [-registerUndoWithTarget:selector:object:]
- * technique.
+ * technique.
* You invoke this method with the target of the
* undo action and then invoke the targets method to undo the action
* on the return value of this invocation
@@ -576,7 +576,7 @@ NSString *NSUndoManagerWillUndoChangeNotification =
* on the redo stack, the top object is poped of the stack and invoked
* within a nested [-beginUndoGrouping]/[-endUndoGrouping]. During this
* pocessing, the operations registered for undo are recorded on the undo
- * stack again.
+ * stack again.
*/
- (void) redo
{
@@ -637,7 +637,7 @@ NSString *NSUndoManagerWillUndoChangeNotification =
/**
* Returns the full localized title of the actions to be displayed
* as a menu item. This method first invokes [-redoActionName] and
- * passes it to [-redoMenuTitelForUndoActionName:] and returns the result.
+ * passes it to [-redoMenuTitleForUndoActionName:] and returns the result.
*/
- (NSString*) redoMenuItemTitle
{
@@ -647,7 +647,7 @@ NSString *NSUndoManagerWillUndoChangeNotification =
/**
* Returns the localized title of the actions to be displayed
* as a menu item identified by actionName, by appending a
- * localized command string like @"Redo
+ * mechanism.
* You invoke this method with the target of the
* undo action providing the selector which can perform the undo with
* the provided object. The object is often a dictionary of the
* identifying the attribute and thier values before the change.
- * The invocation will added to the current grouping.
+ * The invocation will added to the current grouping.
* If the registrations have been disabled through [-disableUndoRegistration],
- * this method does nothing.
+ * this method does nothing.
* Unless the reciever implicitly
* groups operations by event, the this method must have been preceeded
* with a [-beginUndoGrouping] message. Otherwise it will raise an
- * NSInternalInconsistencyException.
+ * NSInternalInconsistencyException.
* Unless this method is invoked as part of a [-undo] or [-undoNestedGroup]
- * processing, the redo stack is cleared.
- * If the reciever [-groupsByEvents] and this is the first call to this
+ * processing, the redo stack is cleared.
+ * If the reciever [-groupsByEvent] and this is the first call to this
* method since the last run loop processing, this method sets up
* the reciever to process the [-endUndoGrouping] at the
* end of the event loop.
@@ -792,7 +792,7 @@ NSString *NSUndoManagerWillUndoChangeNotification =
/**
* Returns the run loop modes in which the receiver registers
- * the [-endUndoGroup] processing when it [-groupsByEvent].
+ * the [-endUndoGrouping] processing when it [-groupsByEvent].
*/
- (NSArray*) runLoopModes
{
@@ -854,7 +854,7 @@ NSString *NSUndoManagerWillUndoChangeNotification =
/**
* Sets the modes in which the reciever registers the calls
* with the current run loop to invoke
- * [-endUndoGroup] when it [-groupsByEvents]. This method
+ * [-endUndoGrouping] when it [-groupsByEvent]. This method
* first cancels any pending registrations in the old modes and
* registers the invokation in the new modes.
*/
@@ -914,7 +914,7 @@ NSString *NSUndoManagerWillUndoChangeNotification =
/**
* Returns the full localized title of the actions to be displayed
* as a menu item. This method first invokes [-undoActionName] and
- * passes it to [-undoMenuTitelForUndoActionName:] and returns the result.
+ * passes it to [-undoMenuTitleForUndoActionName:] and returns the result.
*/
- (NSString*) undoMenuItemTitle
{
@@ -924,7 +924,7 @@ NSString *NSUndoManagerWillUndoChangeNotification =
/**
* Returns the localized title of the actions to be displayed
* as a menu item identified by actionName, by appending a
- * localized command string like @"Undo
+ * stack.
*/
- (void) undoNestedGroup
{