Up
Authors
- Andrew Kachites McCallum (
mccallum@gnu.ai.mit.edu
)
-
- Richard Frith-Macdonald (
rfm@gnu.org
)
-
Version: 1.152
Date: 2005/11/28 15:41:32
Copyright: (C) 1994, 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
- Declared in:
- Foundation/NSConnection.h
Availability: OpenStep
NSConnection objects are used to manage communications between objects in different processes, in different machines, or in different threads.
Method summary
+ (
NSArray*)
allConnections;
Availability: OpenStep
Returns an array containing all the NSConnection objects known to the system. These connections will be valid at the time that the array was created, but may be invalidated by other threads before you get to examine the array.
+ (
NSConnection*)
connectionWithRegisteredName: (
NSString*)n
host: (
NSString*)h
usingNameServer: (
NSPortNameServer*)s;
Availability: OpenStep
Returns an NSConnection object whose send port is that of the NSConnection registered under name on host.
The nameserver server is used to look up the send port to be used for the connection.
Use [NSSocketPortNameServer +sharedInstance]
for connections to remote hosts.
If host is nil
or an empty string, the host is taken to be the local machine. If it is an asterisk ('*') then the nameserver checks all hosts on the local subnet (unless the nameserver is one that only manages local ports). In the GNUstep implementation, the local host is searched before any other hosts.
If no NSConnection can be found for name and host host, the method returns nil
.
The returned object has the default NSConnection of the current thread as its parent (it has the same receive port as the default connection).
+ (id)
currentConversation;
Availability: OpenStep
Return the current conversation... not implemented in GNUstep
+ (
NSConnection*)
defaultConnection;
Availability: OpenStep
Returns the default connection for a thread.
Creates a new instance if necessary.
The default connection has a single NSPort object used for both sending and receiving - this it can't be used to connect to a remote process, but can be used to vend objects.
Possible problem - if the connection is invalidated, it won't be cleaned up until this thread calls this method again. The connection and it's ports could hang around for a very long time.
- (void)
addRequestMode: (
NSString*)mode;
Availability: OpenStep
Adds mode to the run loop modes that the NSConnection will listen to for incoming messages.
- (void)
addRunLoop: (
NSRunLoop*)loop;
Availability: OpenStep
Adds loop to the set of run loops that the NSConnection will listen to for incoming messages.
- (id)
delegate;
Availability: OpenStep
Returns the delegate of the NSConnection.
- (void)
enableMultipleThreads;
Availability: OpenStep
Sets the NSConnection configuration so that multiple threads may use the connection to send requests to the remote connection.
This option is inherited by child connections.
NB. A connection with multiple threads enabled will run slower than a normal connection.
- (BOOL)
independentConversationQueueing;
Availability: OpenStep
Returns YES
if the NSConnection is configured to handle remote messages atomically, NO
otherwise.
This option is inherited by child connections.
- (id)
initWithReceivePort: (
NSPort*)r
sendPort: (
NSPort*)s;
Availability: OpenStep
This is a designated initialiser for the class.
Initialises an NSConnection with the receive port
r and the send port
s.
Behavior varies with the port values as follows -
- r is
nil
-
The NSConnection is released and the method returns
nil
.
- s is
nil
-
The NSConnection uses r as the send port as well as the receive port.
- s is the same as r
-
The NSConnection is usable only for vending objects.
- A connection with the same ports exists
-
The new connection is released and the old connection is retained and returned.
- A connection with the same ports (swapped) exists
-
The new connection is initialised as normal, and will communicate with the old connection.
If a connection exists whose send and receive ports are both the same as the new connections receive port, that existing connection is deemed to be the parent of the new connection. The new connection inherits configuration information from the parent, and the delegate of the parent has a chance to adjust the configuration of the new connection or veto its creation.
NSConnectionDidInitializeNotification is posted once a new connection is initialised.
- (void)
invalidate;
Availability: OpenStep
Marks the receiving NSConnection as invalid.
Removes the NSConnections ports from any run loops.
Posts an NSConnectionDidDieNotification.
Invalidates all remote objects and local proxies.
- (BOOL)
isValid;
Availability: OpenStep
Returns
YES
if the connection is valid,
NO
otherwise. A connection is valid until it has been sent an
-invalidate
message.
- (
NSArray*)
localObjects;
Availability: OpenStep
Returns an array of all the local objects that have proxies at the remote end of the connection because they have been sent over the connection and not yet released by the far end.
- (BOOL)
multipleThreadsEnabled;
Availability: OpenStep
Returns
YES
if the connection permits multiple threads to use it to send requests,
NO
otherwise.
See the
-enableMultipleThreads
method.
- (
NSPort*)
receivePort;
Availability: OpenStep
Returns the NSPort object on which incoming messages are received.
- (BOOL)
registerName: (
NSString*)name;
Availability: OpenStep
- (BOOL)
registerName: (
NSString*)name
withNameServer: (
NSPortNameServer*)svr;
Availability: OpenStep
Registers the receive port of the NSConnection as name and unregisters the previous value (if any).
Returns YES
on success, NO
on failure.
On failure, the connection remains registered under the previous name.
Supply nil
as name to unregister the NSConnection.
- (
NSArray*)
remoteObjects;
Availability: OpenStep
Returns an array of proxies to all the remote objects known to the NSConnection.
- (void)
removeRequestMode: (
NSString*)mode;
Availability: OpenStep
Removes mode from the run loop modes used to receive incoming messages.
- (void)
removeRunLoop: (
NSRunLoop*)loop;
Availability: OpenStep
Removes loop from the run loops used to receive incoming messages.
- (
NSTimeInterval)
replyTimeout;
Availability: OpenStep
Returns the timeout interval used when waiting for a reply to a request sent on the NSConnection. This value is inherited from the parent connection or may be set using the
-setReplyTimeout:
method.
The default value is the maximum delay (effectively infinite).
- (
NSArray*)
requestModes;
Availability: OpenStep
Returns an array of all the run loop modes that the NSConnection uses when waiting for an incoming request.
- (
NSTimeInterval)
requestTimeout;
Availability: OpenStep
Returns the timeout interval used when trying to send a request on the NSConnection. This value is inherited from the parent connection or may be set using the
-setRequestTimeout:
method.
The default value is the maximum delay (effectively infinite).
- (id)
rootObject;
Availability: OpenStep
Returns the object that is made available by this connection or by its parent (the object is associated with the receive port).
Returns nil
if no root object has been set.
- (void)
runInNewThread;
Availability: OpenStep
Removes the NSConnection from the current threads default run loop, then creates a new thread and runs the NSConnection in it.
- (
NSPort*)
sendPort;
Availability: OpenStep
Returns the port on which the NSConnection sends messages.
- (void)
setDelegate: (id)anObj;
Availability: OpenStep
Sets the NSConnection's delegate (without retaining it).
The delegate is able to control some of the NSConnection's behavior by implementing methods in an informal protocol.
- (void)
setIndependentConversationQueueing: (BOOL)flag;
Availability: OpenStep
Sets whether or not the NSConnection should handle requests arriving from the remote NSConnection atomically.
By default, this is set to NO
... if set to YES
then any messages arriving while one message is being dealt with, will be queued.
NB. careful - use of this option can cause deadlocks.
- (void)
setReplyTimeout: (
NSTimeInterval)to;
Availability: OpenStep
Sets the time interval that the NSConnection will wait for a reply for one of its requests before raising an NSPortTimeoutException.
NB. In GNUstep you may also get such an exception if the connection becomes invalidated while waiting for a reply to a request.
- (void)
setRequestMode: (
NSString*)mode;
Availability: OpenStep
Sets the runloop mode in which requests will be sent to the remote end of the connection. Normally this is NSDefaultRunloopMode
- (void)
setRequestTimeout: (
NSTimeInterval)to;
Availability: OpenStep
Sets the time interval that the NSConnection will wait to send one of its requests before raising an NSPortTimeoutException.
- (void)
setRootObject: (id)anObj;
Availability: OpenStep
Sets the root object that is vended by the connection.
- (
NSDictionary*)
statistics;
Availability: OpenStep
Returns an object containing various statistics for the NSConnection.
On GNUstep the dictionary contains -
- NSConnectionRepliesReceived
-
The number of messages replied to by the remote NSConnection.
- NSConnectionRepliesSent
-
The number of replies sent to the remote NSConnection.
- NSConnectionRequestsReceived
-
The number of messages received from the remote NSConnection.
- NSConnectionRequestsSent
-
The number of messages sent to the remote NSConnection.
- NSConnectionLocalCount
-
The number of local objects currently vended.
- NSConnectionProxyCount
-
The number of remote objects currently in use.
- Declared in:
- Foundation/NSConnection.h
- Conforms to:
- GCFinalization
Availability: OpenStep
This category contains legacy methods from the original GNU 'Connection' class, and useful extensions to
NSConnection
.
Method summary
+ (
NSConnection*)
newRegisteringAtName: (
NSString*)name
withRootObject: (id)anObject;
Availability: OpenStep
Alternative convenience constructor, not specified in OpenStep, where you register root anObject under given name in one step.
- (retval_t)
forwardForProxy: (
NSDistantObject*)object
selector: (SEL)sel
argFrame: (arglist_t)argframe;
Availability: OpenStep
[NSDistantObject -forward::] calls this to send the message over the wire.
- (void)
forwardInvocation: (
NSInvocation*)inv
forProxy: (
NSDistantObject*)object;
Availability: OpenStep
[NSDistantObject -forwardInvocation:] calls this to send the message over the wire.
- (void)
gcFinalize;
Availability: OpenStep
Performs local and remote cleanup.
- (const char*)
typeForSelector: (SEL)sel
remoteTarget: (unsigned)target;
Availability: OpenStep
Returns type code (@encode()-compatible) for given remote method.
- Declared in:
- Foundation/NSConnection.h
Availability: OpenStep
This category represents an informal protocol to which NSConnection delegates may conform... These methods are not actually implemented by NSObject, so implementing these methods in your class has the effect documented.
Method summary
- (BOOL)
authenticateComponents: (
NSMutableArray*)components
withData: (
NSData*)authenticationData;
Availability: OpenStep
This is not an NSConnection method, but is a method that may be implemented by the delegate of an NSConnection object.
If the delegate implements this method, the NSConnection will invoke the method for every message request or reply it receives from the remote NSConnection. The delegate should use the authentication data to check all the NSData objects in the components array (ignoring NSPort objects), and return YES
if they are valid, NO
otherwise.
If the method returns NO
then an NSFailedAuthentication exception will be raised.
In GNUstep the components array is mutable, allowing you to replace the NSData objects with your own version.
- (
NSData*)
authenticationDataForComponents: (
NSMutableArray*)components;
Availability: OpenStep
This is not an NSConnection method, but is a method that may be implemented by the delegate of an NSConnection object.
If the delegate implements this method, the NSConnection will invoke the method for every message request to reply it sends to the remote NSConnection. The delegate should generate authentication data by examining all the NSData objects in the components array (ignoring NSPort objects), and return the authentication data that can be used by the remote NSConnection.
If the method returns nil
then an NSGenericException exception will be raised.
In GNUstep the components array is mutable, allowing you to replace the NSData objects with your own version.
- (BOOL)
connection: (
NSConnection*)parent
shouldMakeNewConnection: (
NSConnection*)newConnection;
Availability: OpenStep
This is not an NSConnection method, but is a method that may be implemented by the delegate of an NSConnection object.
If the delegate implements this method, it will be called whenever a new NSConnection is created that has this NSConnection as its parent. The delegate may take this opportunity to adjust the configuration of the new connection and may return a boolean value to tell the parent whether the creation of the new connection is to be permitted or not.
Up