More work for switchover to message ports.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22054 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-11-21 09:59:42 +00:00
parent 40bdc89439
commit 7c78c45b4f
4 changed files with 73 additions and 78 deletions

View file

@ -81,7 +81,12 @@ GS_EXPORT NSString * const NSPortTimeoutException; /* OPENSTEP */
}
/**
* Basic constructor returns object capable of send and receive.
* Basic constructor returns object capable of send and receive.<br />
* By default, the port returned is an instance of [NSMessagePort]
* capable only of host-local communication. However, the
* <code>NSPortIsMessagePort</code> user default may be set to NO to
* change the behavior so that the returned value is an instance of
* the [NSSocketPort] class.
*/
+ (NSPort*) port;
@ -102,6 +107,7 @@ GS_EXPORT NSString * const NSPortTimeoutException; /* OPENSTEP */
/**
* Basic initializer sets up object capable of send and receive.
* See +port for more details.
*/
- (id) init;
@ -298,7 +304,7 @@ typedef SOCKET NSSocketNativeHandle;
*/
@interface NSMessagePort : NSPort <GCFinalization>
{
void *_internal;
void *_internal;
}
@end

View file

@ -330,7 +330,8 @@ static NSLock *cached_proxies_gate = nil;
}
/**
* Returns a connection initialised using -initWithReceivePort:sendPort:
* Returns a connection initialised using -initWithReceivePort:sendPort:<br />
* Both ports must be of the same type.
*/
+ (NSConnection*) connectionWithReceivePort: (NSPort*)r
sendPort: (NSPort*)s
@ -353,6 +354,8 @@ static NSLock *cached_proxies_gate = nil;
* <p>This method calls +connectionWithRegisteredName:host:usingNameServer:
* using the default system name server.
* </p>
* <p>Use [NSSocketPortNameServer] for connections to remote hosts.
* </p>
*/
+ (NSConnection*) connectionWithRegisteredName: (NSString*)n
host: (NSString*)h
@ -372,7 +375,10 @@ static NSLock *cached_proxies_gate = nil;
* </p>
* <p>
* The nameserver <em>server</em> is used to look up the send
* port to be used for the connection.
* port to be used for the connection.<br />
* Use [NSSocketPortNameServer+sharedInstance]
* for connections to remote hosts.
* </p>
* </p>
* <p>
* If <em>host</em> is <code>nil</code> or an empty string,
@ -577,7 +583,9 @@ static NSLock *cached_proxies_gate = nil;
* to get a connection, then sends it a -rootProxy message to get
* a proxy for the root object being vended by the remote connection.
* Returns the proxy or nil if it couldn't find a connection or if
* the root object for the connection has not been set.
* the root object for the connection has not been set.<br />
* Use [NSSocketPortNameServer+sharedInstance]
* for connections to remote hosts.
*/
+ (NSDistantObject*) rootProxyForConnectionWithRegisteredName: (NSString*)n
host: (NSString*)h usingNameServer: (NSPortNameServer*)s

View file

@ -72,26 +72,22 @@ Class NSPort_concrete_class;
{
if (self == [NSPort class])
{
NSUserDefaults *defs;
NSPort_abstract_class = self;
#ifndef __MINGW32__
/* Must be kept in sync with [NSPortNameServer +systemDefaultPortNameServer]. */
if (GSUserDefaultsFlag(GSMacOSXCompatible) == YES
|| [[NSUserDefaults standardUserDefaults]
boolForKey: @"NSPortIsMessagePort"])
{
NSPort_concrete_class = [NSMessagePort class];
}
else
NSPort_concrete_class = [NSSocketPort class];
defs = [NSUserDefaults standardUserDefaults];
if ([defs objectForKey: @"NSPortIsMessagePort"] != nil
&& [defs boolForKey: @"NSPortIsMessagePort"] == NO)
{
NSPort_concrete_class = [NSSocketPort class];
}
#else
if ([[NSUserDefaults standardUserDefaults]
boolForKey: @"GSMailslot"] == YES)
NSPort_concrete_class = [NSMessagePort class];
else
NSPort_concrete_class = [NSSocketPort class];
#if defined(__MINGW32__)
if ([defs boolForKey: @"GSMailslot"] == NO)
{
NSPort_concrete_class = [NSMessagePort class];
}
#endif
}
}

View file

@ -29,6 +29,7 @@
#include "Foundation/NSException.h"
#include "Foundation/NSPortNameServer.h"
#include "Foundation/NSDebug.h"
#include "Foundation/NSLock.h"
#include "Foundation/NSUserDefaults.h"
#include "GSPrivate.h"
@ -55,69 +56,53 @@
}
/**
* Returns the default port name server for the process.<br />
* 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... unless it
* is running in compatibility mode.<br />
* This may change in future releases.
* <p>Returns the default port name server for the process.<br />
* This is a nameserver for host-local connections private to the current
* user. If you with to create public connections or connections to other
* hosts, you must use [NSSocketPortNameServer+sharedInstance] instead.
* </p>
* This default behavior may be altered by setting the
* <code>NSPortIsMessagePort</code> user default to NO, in which case
* an [NSSocketPortNaemServer] will be used as the default system name server
* and you will have to use [NSMessagePortNameServer+sharedInstance]
* for host-local, private connections.
*/
+ (id) systemDefaultPortNameServer
{
static id nameServer = nil;
if (nameServer == nil)
{
[gnustep_global_lock lock];
if (nameServer == nil)
{
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
id o;
if ([defs objectForKey: @"NSPortIsMessagePort"] != nil
&& [defs boolForKey: @"NSPortIsMessagePort"] == NO)
{
o = [NSSocketPortNameServer sharedInstance];
}
else
{
o = [NSMessagePortNameServer sharedInstance];
}
#if defined(__MINGW__)
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"GSMailslot"] == YES)
{
return [NSMessagePortNameServer sharedInstance];
}
#endif
/* Must be kept in sync with [NSPort +initialize]. */
if (GSUserDefaultsFlag(GSMacOSXCompatible) == YES)
{
#ifndef __MINGW32__
return [NSMessagePortNameServer sharedInstance];
#else
return [NSSocketPortNameServer sharedInstance];
if ([defs boolForKey: @"GSMailslot"] == YES)
{
o = [NSMessagePortNameServer sharedInstance];
}
else
{
o = [NSSocketPortNameServer sharedInstance];
}
#endif
nameServer = RETAIN(o);
}
[gnustep_global_lock unlock];
}
else
{
NSString *def = [[NSUserDefaults standardUserDefaults]
stringForKey: @"NSPortIsMessagePort"];
if (def == nil)
{
GSOnceMLog(
@"\nWARNING -\n"
@"while the default nameserver used by NSConnection\n"
@"currently provides ports which can be used for inter-host\n"
@"and inter-user communications, this will be changed so that\n"
@"nsconnections will only work between processes owned by the\n"
@"same account on the same machine. This change is for\n"
@"MacOSX compatibility and for increased security.\n"
@"If your application actually needs to support inter-host\n"
@"or inter-user communications, you need to alter it to explicity\n"
@"use an instance of the NSSocketPortNameServer class to provide\n"
@"name service facilities.\n"
@"To stop this message appearing, set the NSPortIsMessagePort\n"
@"user default\n\n");
return [NSSocketPortNameServer sharedInstance];
}
else if ([def boolValue] == NO)
{
return [NSSocketPortNameServer sharedInstance];
}
else
{
#ifndef __MINGW32__
return [NSMessagePortNameServer sharedInstance];
#else
return [NSSocketPortNameServer sharedInstance];
#endif
}
}
return nameServer;
}
- (void) dealloc