1994-11-04 16:29:24 +00:00
|
|
|
|
/* Implementation of connection object for remote object messaging
|
1996-01-24 14:11:20 +00:00
|
|
|
|
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
|
Date: July 1994
|
|
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C Class Library.
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* RMC == Remote Method Coder, or Remote Method Call.
|
1996-03-01 15:54:57 +00:00
|
|
|
|
It's an instance of ConnectedEncoder or ConnectedDecoder. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
#include <objects/stdobjects.h>
|
|
|
|
|
#include <objects/Connection.h>
|
|
|
|
|
#include <objects/Proxy.h>
|
|
|
|
|
#include <objects/ConnectedCoder.h>
|
|
|
|
|
#include <objects/SocketPort.h>
|
|
|
|
|
#include <objects/Array.h>
|
|
|
|
|
#include <objects/Dictionary.h>
|
|
|
|
|
#include <objects/Queue.h>
|
|
|
|
|
#include <objects/mframe.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
|
#include <Foundation/NSString.h>
|
1996-03-01 15:54:57 +00:00
|
|
|
|
#include <Foundation/NSNotification.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
@interface Connection (GettingCoderInterface)
|
|
|
|
|
- doReceivedRequestsWithTimeout: (int)to;
|
|
|
|
|
- newReceivedReplyRmcWithSequenceNumber: (int)n;
|
|
|
|
|
- newSendingRequestRmc;
|
|
|
|
|
- newSendingReplyRmcWithSequenceNumber: (int)n;
|
|
|
|
|
- (int) _newMsgNumber;
|
|
|
|
|
@end
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
@interface Connection (Private)
|
|
|
|
|
- _superInit;
|
|
|
|
|
@end
|
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
#define proxiesHashGate refGate
|
|
|
|
|
#define sequenceNumberGate refGate
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* xxx Fix this! */
|
|
|
|
|
#define refGate nil
|
|
|
|
|
|
|
|
|
|
static inline BOOL
|
|
|
|
|
class_is_kind_of (Class self, Class aClassObject)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1995-03-08 23:04:52 +00:00
|
|
|
|
Class class;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
for (class = self; class!=Nil; class = class_get_super_class(class))
|
|
|
|
|
if (class==aClassObject)
|
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
|
hash_int (cache_ptr cache, const void *key)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned)key & cache->mask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
compare_ints (const void *k1, const void *k2)
|
|
|
|
|
{
|
|
|
|
|
return !(k1 - k2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
type_get_number_of_arguments (const char *type)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (*type)
|
|
|
|
|
{
|
|
|
|
|
type = objc_skip_argspec (type);
|
|
|
|
|
i += 1;
|
|
|
|
|
}
|
|
|
|
|
return i - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* class defaults */
|
|
|
|
|
static id default_port_class;
|
1996-03-01 15:54:57 +00:00
|
|
|
|
static id default_proxy_class;
|
|
|
|
|
static id default_encoding_class;
|
|
|
|
|
static id default_decoding_class;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
static int default_in_timeout;
|
|
|
|
|
static int default_out_timeout;
|
|
|
|
|
|
|
|
|
|
static BOOL debug_connection = NO;
|
|
|
|
|
|
|
|
|
|
/* Perhaps this should be a hashtable, keyed by remote port.
|
|
|
|
|
But we may also need to include the local port---even though
|
|
|
|
|
when receiving the local port is fixed, there may be more than
|
|
|
|
|
one registered connection (with different in ports) in the
|
|
|
|
|
application. */
|
|
|
|
|
/* We could write -hash and -isEqual implementations for Connection */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
static Array *connection_array;
|
|
|
|
|
static Lock *connection_array_gate;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
static Dictionary *root_object_dictionary;
|
|
|
|
|
static Lock *root_object_dictionary_gate;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
/* rmc handling */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
static Queue *received_request_rmc_queue;
|
|
|
|
|
static Lock *received_request_rmc_queue_gate;
|
|
|
|
|
static Queue *received_reply_rmc_queue;
|
|
|
|
|
static Lock *received_reply_rmc_queue_gate;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
static int messages_received_count;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
@implementation Connection
|
|
|
|
|
|
1995-03-12 22:23:25 +00:00
|
|
|
|
+ (void) initialize
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
connection_array = [[Array alloc] init];
|
|
|
|
|
connection_array_gate = [Lock new];
|
|
|
|
|
received_request_rmc_queue = [[Queue alloc] init];
|
|
|
|
|
received_request_rmc_queue_gate = [Lock new];
|
|
|
|
|
received_reply_rmc_queue = [[Queue alloc] init];
|
|
|
|
|
received_reply_rmc_queue_gate = [Lock new];
|
|
|
|
|
root_object_dictionary = [[Dictionary alloc] init];
|
|
|
|
|
root_object_dictionary_gate = [Lock new];
|
|
|
|
|
messages_received_count = 0;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
default_port_class = [SocketPort class];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
default_proxy_class = [Proxy class];
|
|
|
|
|
default_encoding_class = [ConnectedEncoder class];
|
|
|
|
|
default_decoding_class = [ConnectedDecoder class];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
default_in_timeout = CONNECTION_DEFAULT_TIMEOUT;
|
|
|
|
|
default_out_timeout = CONNECTION_DEFAULT_TIMEOUT;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
/* Getting and setting class variables */
|
|
|
|
|
|
|
|
|
|
+ (void) setDefaultPortClass: (Class)aClass
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
default_port_class = aClass;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
+ (Class) defaultPortClass
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return default_port_class;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
+ (void) setDefaultProxyClass: (Class)aClass
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
default_proxy_class = aClass;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
+ (Class) defaultProxyClass
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return default_proxy_class;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
+ (void) setDefaultDecodingClass: (Class) aClass
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
default_decoding_class = aClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (Class) default_decoding_class
|
|
|
|
|
{
|
|
|
|
|
return default_decoding_class;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (int) defaultOutTimeout
|
|
|
|
|
{
|
|
|
|
|
return default_out_timeout;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
+ (void) setDefaultOutTimeout: (int)to
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
default_out_timeout = to;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (int) defaultInTimeout
|
|
|
|
|
{
|
|
|
|
|
return default_in_timeout;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
+ (void) setDefaultInTimeout: (int)to
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
default_in_timeout = to;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
/* Class-wide stats and collections. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
+ (int) messagesReceived
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return messages_received_count;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (id <Collecting>) allConnections
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return [connection_array copy];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (unsigned) connectionsCount
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return [connection_array count];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (unsigned) connectionsCountWithInPort: (Port*)aPort
|
|
|
|
|
{
|
|
|
|
|
unsigned count = 0;
|
1996-03-01 15:54:57 +00:00
|
|
|
|
id o;
|
|
|
|
|
[connection_array_gate lock];
|
|
|
|
|
FOR_ARRAY (connection_array, o)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if ([aPort isEqual: [o inPort]])
|
1994-11-04 16:29:24 +00:00
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
FOR_ARRAY_END;
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[connection_array_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
/* Creating and initializing connections. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
- init
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
id newPort = [default_port_class newForReceiving];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
id newConn =
|
|
|
|
|
[Connection newForInPort:newPort outPort:nil ancestorConnection:nil];
|
1995-03-12 19:58:48 +00:00
|
|
|
|
[self release];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return newConn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ new
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
id newPort = [default_port_class newForReceiving];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
id newConn =
|
|
|
|
|
[Connection newForInPort:newPort outPort:nil ancestorConnection:nil];
|
|
|
|
|
return newConn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (Connection*) newWithRootObject: anObj;
|
|
|
|
|
{
|
|
|
|
|
id newPort;
|
|
|
|
|
id newConn;
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
newPort = [default_port_class newForReceiving];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
newConn = [self newForInPort:newPort outPort:nil
|
|
|
|
|
ancestorConnection:nil];
|
|
|
|
|
[self setRootObject:anObj forInPort:newPort];
|
|
|
|
|
return newConn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* I want this method name to clearly indicate that we're not connecting
|
|
|
|
|
to a pre-existing registration name, we're registering a new name,
|
|
|
|
|
and this method will fail if that name has already been registered.
|
|
|
|
|
This is why I don't like "newWithRegisteredName:" --- it's unclear
|
|
|
|
|
if we're connecting to another Connection that already registered
|
|
|
|
|
with that name. */
|
|
|
|
|
|
1995-04-03 03:23:45 +00:00
|
|
|
|
+ (Connection*) newRegisteringAtName: (id <String>)n withRootObject: anObj
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
id newPort;
|
|
|
|
|
id newConn;
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
newPort = [default_port_class newForReceivingFromRegisteredName: n];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
newConn = [self newForInPort:newPort outPort:nil
|
|
|
|
|
ancestorConnection:nil];
|
|
|
|
|
[self setRootObject:anObj forInPort:newPort];
|
|
|
|
|
return newConn;
|
|
|
|
|
}
|
|
|
|
|
|
1995-04-03 03:23:45 +00:00
|
|
|
|
+ (Proxy*) rootProxyAtName: (id <String>)n
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return [self rootProxyAtName: n onHost: @""];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-04-03 03:23:45 +00:00
|
|
|
|
+ (Proxy*) rootProxyAtName: (id <String>)n onHost: (id <String>)h
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
id p = [default_port_class newForSendingToRegisteredName: n onHost: h];
|
|
|
|
|
return [self rootProxyAtPort: p];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-03-12 22:23:25 +00:00
|
|
|
|
+ (Proxy*) rootProxyAtPort: (Port*)anOutPort
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
id newInPort = [default_port_class newForReceiving];
|
|
|
|
|
return [self rootProxyAtPort: anOutPort withInPort: newInPort];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-03-12 22:23:25 +00:00
|
|
|
|
+ (Proxy*) rootProxyAtPort: (Port*)anOutPort withInPort: (Port*)anInPort
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
Connection *newConn = [self newForInPort:anInPort
|
|
|
|
|
outPort:anOutPort
|
|
|
|
|
ancestorConnection:nil];
|
|
|
|
|
Proxy *newRemote;
|
|
|
|
|
|
|
|
|
|
newRemote = [newConn rootProxy];
|
|
|
|
|
return newRemote;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
/* This is the designated initializer for Connection */
|
|
|
|
|
|
|
|
|
|
+ (Connection*) newForInPort: (Port*)ip outPort: (Port*)op
|
|
|
|
|
ancestorConnection: (Connection*)ancestor;
|
|
|
|
|
{
|
|
|
|
|
Connection *newConn;
|
|
|
|
|
int i, count;
|
|
|
|
|
id newConnInPort, newConnOutPort;
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[connection_array_gate lock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
/* Find previously existing connection if there */
|
|
|
|
|
/* xxx Clean this up */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
count = [connection_array count];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
newConn = [connection_array objectAtIndex: i];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
newConnInPort = [newConn inPort];
|
|
|
|
|
newConnOutPort = [newConn outPort];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if ([newConnInPort isEqual: ip]
|
|
|
|
|
&& [newConnOutPort isEqual: op])
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[connection_array_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return newConn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newConn = [[Connection alloc] _superInit];
|
|
|
|
|
if (debug_connection)
|
|
|
|
|
printf("new connection 0x%x, inPort 0x%x outPort 0x%x\n",
|
|
|
|
|
(unsigned)newConn, (unsigned)ip, (unsigned)op);
|
|
|
|
|
newConn->in_port = ip;
|
|
|
|
|
[ip retain];
|
|
|
|
|
newConn->out_port = op;
|
|
|
|
|
[op retain];
|
|
|
|
|
newConn->message_count = 0;
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* This maps (void*)obj to (id)obj. The obj's are retained.
|
|
|
|
|
We use this instead of an NSHashTable because we only care about
|
|
|
|
|
the object's address, and don't want to send the -hash message to it. */
|
|
|
|
|
newConn->local_targets =
|
|
|
|
|
NSCreateMapTable (NSNonOwnedPointerMapKeyCallBacks,
|
|
|
|
|
NSObjectMapValueCallBacks, 0);
|
|
|
|
|
|
|
|
|
|
/* This maps [proxy targetForProxy] to proxy. The proxy's are retained. */
|
|
|
|
|
newConn->remote_proxies =
|
|
|
|
|
NSCreateMapTable (NSIntMapKeyCallBacks,
|
|
|
|
|
NSObjectMapValueCallBacks, 0);
|
|
|
|
|
|
|
|
|
|
newConn->incoming_xref_2_const_ptr =
|
|
|
|
|
NSCreateMapTable (NSIntMapKeyCallBacks,
|
|
|
|
|
NSNonOwnedPointerMapValueCallBacks, 0);
|
|
|
|
|
newConn->outgoing_const_ptr_2_xref =
|
|
|
|
|
NSCreateMapTable (NSIntMapKeyCallBacks,
|
|
|
|
|
NSNonOwnedPointerMapValueCallBacks, 0);
|
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
newConn->in_timeout = [self defaultInTimeout];
|
|
|
|
|
newConn->out_timeout = [self defaultOutTimeout];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
newConn->encoding_class = default_encoding_class;
|
|
|
|
|
if (ancestor)
|
|
|
|
|
newConn->port_class = [ancestor portClass];
|
|
|
|
|
else
|
|
|
|
|
newConn->port_class = default_port_class;
|
|
|
|
|
newConn->delay_dialog_interruptions = YES;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
newConn->delegate = nil;
|
|
|
|
|
|
|
|
|
|
/* Here ask the delegate for permission. */
|
|
|
|
|
/* delegate is responsible for freeing newConn if it returns something
|
|
|
|
|
different. */
|
|
|
|
|
if ([[ancestor delegate] respondsTo:@selector(connection:didConnect:)])
|
|
|
|
|
newConn = [[ancestor delegate] connection:ancestor
|
|
|
|
|
didConnect:newConn];
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* Register outselves for invalidation notification when the
|
|
|
|
|
ports become invalid. */
|
|
|
|
|
[[NSNotification defaultCenter] addObserver: self
|
|
|
|
|
selector: @selector(portIsInvalid:)
|
|
|
|
|
name: PortBecameInvalidNotification
|
|
|
|
|
object: ip];
|
|
|
|
|
[[NSNotification defaultCenter] addObserver: self
|
|
|
|
|
selector: @selector(portIsInvalid:)
|
|
|
|
|
name: PortBecameInvalidNotification
|
|
|
|
|
object: op];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1995-06-29 00:53:34 +00:00
|
|
|
|
/* xxx This is weird, though. When will newConn ever get dealloc'ed?
|
|
|
|
|
connectionArray will retain it, but connectionArray will never get
|
|
|
|
|
deallocated. This sort of retain/release cirularity must be common
|
|
|
|
|
enough. Think about this and fix it. */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[connection_array addObject: newConn];
|
1995-06-29 00:53:34 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[connection_array_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
return newConn;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- _superInit
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[super init];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Creating new rmc's for encoding requests and replies */
|
|
|
|
|
|
|
|
|
|
/* Create a new, empty rmc, which will be filled with a request. */
|
|
|
|
|
- newSendingRequestRmc
|
|
|
|
|
{
|
|
|
|
|
id rmc;
|
|
|
|
|
|
|
|
|
|
assert(in_port);
|
|
|
|
|
rmc = [[self encodingClass] newForWritingWithConnection: self
|
|
|
|
|
sequenceNumber: [self _newMsgNumber]
|
|
|
|
|
identifier: METHOD_REQUEST];
|
|
|
|
|
return rmc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create a new, empty rmc, which will be filled with a reply to msg #n. */
|
|
|
|
|
- newSendingReplyRmcWithSequenceNumber: (int)n
|
|
|
|
|
{
|
|
|
|
|
id rmc = [[self encodingClass] newForWritingWithConnection: self
|
|
|
|
|
sequenceNumber: n
|
|
|
|
|
identifier: METHOD_REPLY];
|
|
|
|
|
return rmc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Methods for handling client and server, requests and replies */
|
|
|
|
|
|
|
|
|
|
/* Proxy's -forward:: method calls this to the the message over the wire. */
|
|
|
|
|
- (retval_t) forwardForProxy: (Proxy*)object
|
|
|
|
|
selector: (SEL)sel
|
|
|
|
|
argFrame: (arglist_t)argframe
|
|
|
|
|
{
|
|
|
|
|
ConnectedEncoder *op;
|
|
|
|
|
|
|
|
|
|
/* The callback for encoding the args of the method call. */
|
|
|
|
|
void encoder (int argnum, void *datum, const char *type, int flags)
|
|
|
|
|
{
|
|
|
|
|
#define ENCODED_ARGNAME @"argument value"
|
|
|
|
|
switch (*type)
|
|
|
|
|
{
|
|
|
|
|
case _C_ID:
|
|
|
|
|
if (flags & _F_BYCOPY)
|
|
|
|
|
[op encodeBycopyObject: *(id*)datum withName: ENCODED_ARGNAME];
|
|
|
|
|
else
|
|
|
|
|
[op encodeObject: *(id*)datum withName: ENCODED_ARGNAME];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
[op encodeValueOfObjCType: type at: datum withName: ENCODED_ARGNAME];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Encode the method on an RMC, and send it. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
BOOL out_parameters;
|
|
|
|
|
const char *type;
|
|
|
|
|
retval_t retframe;
|
|
|
|
|
int seq_num;
|
|
|
|
|
|
|
|
|
|
op = [self newSendingRequestRmc];
|
|
|
|
|
seq_num = [op sequenceNumber];
|
|
|
|
|
|
|
|
|
|
/* get the method types from the selector */
|
|
|
|
|
#if NeXT_runtime
|
|
|
|
|
[self error:
|
|
|
|
|
"sorry, distributed objects does not work with the NeXT runtime"];
|
|
|
|
|
/* type = [object selectorTypeForProxy:sel]; */
|
|
|
|
|
#else
|
|
|
|
|
type = sel_get_type(sel);
|
1995-04-07 21:23:24 +00:00
|
|
|
|
#endif
|
1996-03-01 15:54:57 +00:00
|
|
|
|
assert(type);
|
|
|
|
|
assert(*type);
|
|
|
|
|
|
|
|
|
|
/* Send the types that we're using, so that the performer knows
|
|
|
|
|
exactly what qualifiers we're using.
|
|
|
|
|
If all selectors included qualifiers, and if I could make
|
|
|
|
|
sel_types_match() work the way I wanted, we wouldn't need to do
|
|
|
|
|
this. */
|
|
|
|
|
[op encodeValueOfCType: @encode(char*)
|
|
|
|
|
at: &type
|
|
|
|
|
withName: @"selector type"];
|
|
|
|
|
|
|
|
|
|
/* xxx This doesn't work with proxies and the NeXT runtime because
|
|
|
|
|
type may be a method_type from a remote machine with a
|
|
|
|
|
different architecture, and its argframe layout specifiers
|
|
|
|
|
won't be right for this machine! */
|
|
|
|
|
out_parameters = dissect_method_call (argframe, type, encoder);
|
|
|
|
|
/* Send the rmc */
|
|
|
|
|
[op dismiss];
|
|
|
|
|
|
|
|
|
|
/* Get the reply rmc, and decode it. */
|
|
|
|
|
{
|
|
|
|
|
ConnectedDecoder *ip = nil;
|
|
|
|
|
int last_argnum;
|
|
|
|
|
|
|
|
|
|
void decoder(int argnum, void *datum, const char *type, int flags)
|
|
|
|
|
{
|
|
|
|
|
assert(ip != (id)-1);
|
|
|
|
|
if (!ip)
|
|
|
|
|
ip = [self newReceivedReplyRmcWithSequenceNumber:seq_num];
|
|
|
|
|
[ip decodeValueOfObjCType:type at:datum withName:NULL];
|
|
|
|
|
if (argnum == last_argnum)
|
|
|
|
|
{
|
|
|
|
|
/* this must be here to avoid trashing alloca'ed retframe */
|
|
|
|
|
[ip dismiss];
|
|
|
|
|
ip = (id)-1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
last_argnum = type_get_number_of_arguments(type) - 1;
|
|
|
|
|
retframe = dissect_method_return(argframe, type, out_parameters,
|
|
|
|
|
decoder);
|
|
|
|
|
return retframe;
|
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* Connection calls this to service the incoming method request. */
|
|
|
|
|
- (void) _service_forwardForProxy: aRmc
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
char *forward_type;
|
|
|
|
|
id op = nil;
|
|
|
|
|
int reply_sequence_number;
|
|
|
|
|
int numargs;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
void decoder (int argnum, void *datum, const char *type)
|
|
|
|
|
{
|
|
|
|
|
[aRmc decodeValueOfObjCType:type
|
|
|
|
|
at:datum
|
|
|
|
|
withName:NULL];
|
|
|
|
|
/* We need this "dismiss" to happen here and not later so that Coder
|
|
|
|
|
"-awake..." methods will get sent before the __builtin_apply! */
|
|
|
|
|
if (argnum == numargs-1)
|
|
|
|
|
[aRmc dismiss];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void encoder (int argnum, void *datum, const char *type, int flags)
|
|
|
|
|
{
|
|
|
|
|
#define ENCODED_RETNAME @"return value"
|
|
|
|
|
if (op == nil)
|
|
|
|
|
op = [self newSendingReplyRmcWithSequenceNumber:
|
|
|
|
|
reply_sequence_number];
|
|
|
|
|
switch (*type)
|
|
|
|
|
{
|
|
|
|
|
case _C_ID:
|
|
|
|
|
if (flags & _F_BYCOPY)
|
|
|
|
|
[op encodeBycopyObject:*(id*)datum withName:ENCODED_RETNAME];
|
|
|
|
|
else
|
|
|
|
|
[op encodeObject:*(id*)datum withName:ENCODED_RETNAME];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
[op encodeValueOfObjCType:type at:datum withName:ENCODED_RETNAME];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Save this for later */
|
|
|
|
|
reply_sequence_number = [aRmc sequenceNumber];
|
|
|
|
|
|
|
|
|
|
/* Get the types that we're using, so that we know
|
|
|
|
|
exactly what qualifiers the forwarder used.
|
|
|
|
|
If all selectors included qualifiers and I could make sel_types_match()
|
|
|
|
|
work the way I wanted, we wouldn't need to do this. */
|
|
|
|
|
[aRmc decodeValueOfCType:@encode(char*)
|
|
|
|
|
at:&forward_type
|
|
|
|
|
withName:NULL];
|
|
|
|
|
|
|
|
|
|
numargs = type_get_number_of_arguments(forward_type);
|
|
|
|
|
|
|
|
|
|
make_method_call(forward_type, decoder, encoder);
|
|
|
|
|
[op dismiss];
|
|
|
|
|
|
|
|
|
|
(*objc_free)(forward_type);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (Proxy*) rootProxy
|
|
|
|
|
{
|
|
|
|
|
id op, ip;
|
|
|
|
|
Proxy *newProxy;
|
|
|
|
|
int seq_num = [self _newMsgNumber];
|
|
|
|
|
|
|
|
|
|
assert(in_port);
|
1996-03-01 15:54:57 +00:00
|
|
|
|
op = [[self encodingClass]
|
|
|
|
|
newForWritingWithConnection: self
|
|
|
|
|
sequenceNumber: seq_num
|
|
|
|
|
identifier: ROOTPROXY_REQUEST];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[op dismiss];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
ip = [self newReceivedReplyRmcWithSequenceNumber: seq_num];
|
|
|
|
|
[ip decodeObjectAt: &newProxy withName: NULL];
|
|
|
|
|
assert (class_is_kind_of (newProxy->isa, objc_get_class ("Proxy")));
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[ip dismiss];
|
|
|
|
|
return newProxy;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) _service_rootObject: rmc
|
|
|
|
|
{
|
|
|
|
|
id rootObject = [Connection rootObjectForInPort:in_port];
|
|
|
|
|
ConnectedEncoder* op = [[self encodingClass]
|
|
|
|
|
newForWritingWithConnection: [rmc connection]
|
|
|
|
|
sequenceNumber: [rmc sequenceNumber]
|
|
|
|
|
identifier: ROOTPROXY_REPLY];
|
|
|
|
|
assert (in_port);
|
|
|
|
|
/* Perhaps we should turn this into a class method. */
|
|
|
|
|
assert([rmc connection] == self);
|
|
|
|
|
[op encodeObject: rootObject withName: @"root object"];
|
|
|
|
|
[op dismiss];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) shutdown
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
id op;
|
|
|
|
|
|
|
|
|
|
assert(in_port);
|
1996-03-01 15:54:57 +00:00
|
|
|
|
op = [[self encodingClass]
|
|
|
|
|
newForWritingWithConnection: self
|
|
|
|
|
sequenceNumber: [self _newMsgNumber]
|
|
|
|
|
identifier: CONNECTION_SHUTDOWN];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[op dismiss];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) _service_shutdown: rmc forConnection: receiving_connection
|
|
|
|
|
{
|
|
|
|
|
[self invalidate];
|
|
|
|
|
if (receiving_connection == self)
|
|
|
|
|
[self error: "connection waiting for request was shut down"];
|
|
|
|
|
[self dealloc]; // xxx release instead?
|
|
|
|
|
[rmc dismiss];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
id op, ip;
|
|
|
|
|
char *type;
|
|
|
|
|
int seq_num;
|
|
|
|
|
|
|
|
|
|
assert(in_port);
|
|
|
|
|
seq_num = [self _newMsgNumber];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
op = [[self encodingClass]
|
|
|
|
|
newForWritingWithConnection: self
|
|
|
|
|
sequenceNumber: seq_num
|
|
|
|
|
identifier: METHODTYPE_REQUEST];
|
1996-01-23 23:57:17 +00:00
|
|
|
|
[op encodeValueOfObjCType:":"
|
1994-11-04 16:29:24 +00:00
|
|
|
|
at:&sel
|
|
|
|
|
withName:NULL];
|
1996-01-23 23:57:17 +00:00
|
|
|
|
[op encodeValueOfCType:@encode(unsigned)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
at:&target
|
|
|
|
|
withName:NULL];
|
|
|
|
|
[op dismiss];
|
|
|
|
|
ip = [self newReceivedReplyRmcWithSequenceNumber:seq_num];
|
1996-01-23 23:57:17 +00:00
|
|
|
|
[ip decodeValueOfCType:@encode(char*)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
at:&type
|
|
|
|
|
withName:NULL];
|
|
|
|
|
[ip dismiss];
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) _service_typeForSelector: rmc
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
ConnectedEncoder* op;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
unsigned target;
|
|
|
|
|
SEL sel;
|
|
|
|
|
const char *type;
|
|
|
|
|
struct objc_method* m;
|
|
|
|
|
|
|
|
|
|
assert(in_port);
|
|
|
|
|
assert([rmc connection] == self);
|
1996-03-01 15:54:57 +00:00
|
|
|
|
op = [[self encodingClass]
|
|
|
|
|
newForWritingWithConnection: [rmc connection]
|
|
|
|
|
sequenceNumber: [rmc sequenceNumber]
|
|
|
|
|
identifier: METHODTYPE_REPLY];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-01-23 23:57:17 +00:00
|
|
|
|
[rmc decodeValueOfObjCType:":"
|
1994-11-04 16:29:24 +00:00
|
|
|
|
at:&sel
|
|
|
|
|
withName:NULL];
|
1996-01-23 23:57:17 +00:00
|
|
|
|
[rmc decodeValueOfCType:@encode(unsigned)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
at:&target
|
|
|
|
|
withName:NULL];
|
|
|
|
|
/* xxx We should make sure that TARGET is a valid object. */
|
|
|
|
|
/* Not actually a Proxy, but we avoid the warnings "id" would have made. */
|
|
|
|
|
m = class_get_instance_method(((Proxy*)target)->isa, sel);
|
|
|
|
|
/* Perhaps I need to be more careful in the line above to get the
|
|
|
|
|
version of the method types that has the type qualifiers in it.
|
|
|
|
|
Search the protocols list. */
|
|
|
|
|
if (m)
|
|
|
|
|
type = m->method_types;
|
|
|
|
|
else
|
|
|
|
|
type = "";
|
1996-01-23 23:57:17 +00:00
|
|
|
|
[op encodeValueOfCType:@encode(char*)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
at:&type
|
1996-01-24 03:33:21 +00:00
|
|
|
|
withName:@"Requested Method Type for Target"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[op dismiss];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
/* Running the connection, getting/sending requests/replies. */
|
|
|
|
|
|
|
|
|
|
- (void) runConnection
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[self runConnectionWithTimeout: -1];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* to < 0 will never time out */
|
|
|
|
|
- (void) runConnectionWithTimeout: (int)to
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[self doReceivedRequestsWithTimeout: to];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (int) _newMsgNumber
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
[sequenceNumberGate lock];
|
|
|
|
|
n = message_count++;
|
|
|
|
|
[sequenceNumberGate unlock];
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* We not going to get one from a queue; actually go to the network and
|
|
|
|
|
wait for it. */
|
|
|
|
|
- _newReceivedRmcWithTimeout: (int)to
|
|
|
|
|
{
|
|
|
|
|
id rmc;
|
|
|
|
|
|
|
|
|
|
rmc = [[self encodingClass] newDecodingWithConnection: self
|
|
|
|
|
timeout: to];
|
|
|
|
|
/* if (!rmc) [self error:"received timed out"]; */
|
|
|
|
|
assert((!rmc) || [rmc isDecoding]);
|
|
|
|
|
return rmc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Waiting for incoming requests. */
|
|
|
|
|
- _serviceReceivedRequestsWithTimeout: (int)to
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
id rmc;
|
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
if (debug_connection)
|
|
|
|
|
printf("%s\n", sel_get_name(_cmd));
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* Get a rmc, either from off the queue, or from the network. */
|
|
|
|
|
[received_request_rmc_queue_gate lock];
|
|
|
|
|
count = [received_request_rmc_queue count];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if (count)
|
|
|
|
|
{
|
|
|
|
|
if (debug_connection)
|
1996-03-01 15:54:57 +00:00
|
|
|
|
printf ("Getting received request from queue\n");
|
|
|
|
|
rmc = [received_request_rmc_queue dequeueObject];
|
|
|
|
|
[received_request_rmc_queue_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[received_request_rmc_queue_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
rmc = [self _newReceivedRmcWithTimeout:to];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* If we timed out, just return. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if (!rmc) return self; /* timed out */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
assert([rmc isKindOf: [Decoder class]]);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* We got a rmc; process it */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
switch ([rmc identifier])
|
|
|
|
|
{
|
|
|
|
|
case ROOTPROXY_REQUEST:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[[rmc connection] _service_rootObject: rmc];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[rmc dismiss];
|
|
|
|
|
break;
|
|
|
|
|
case ROOTPROXY_REPLY:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[self error: "Got ROOTPROXY reply when looking for request"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case METHOD_REQUEST:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[[rmc connection] _service_forwardForProxy: rmc];
|
|
|
|
|
break;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
case METHOD_REPLY:
|
|
|
|
|
/* Will this ever happen?
|
|
|
|
|
Yes, with multi-threaded callbacks */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[received_reply_rmc_queue_gate lock];
|
|
|
|
|
[received_reply_rmc_queue enqueueObject: rmc];
|
|
|
|
|
[received_reply_rmc_queue_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case METHODTYPE_REQUEST:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[[rmc connection] _service_typeForSelector: rmc];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[rmc dismiss];
|
|
|
|
|
break;
|
|
|
|
|
case METHODTYPE_REPLY:
|
|
|
|
|
/* Will this ever happen?
|
|
|
|
|
Yes, with multi-threaded callbacks */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[received_reply_rmc_queue_gate lock];
|
|
|
|
|
[received_reply_rmc_queue enqueueObject: rmc];
|
|
|
|
|
[received_reply_rmc_queue_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case CONNECTION_SHUTDOWN:
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[[rmc connection] _service_shutdown: rmc forConnection: self];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[self error:"unrecognized ConnectedDecoder identifier"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* Waiting for a reply to a request. */
|
|
|
|
|
- _serviceNewReceivedReplyRmcWithSequenceNumber: (int)n
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
id rmc, aRmc;
|
|
|
|
|
unsigned count, i;
|
|
|
|
|
|
|
|
|
|
again:
|
|
|
|
|
|
|
|
|
|
/* Get a rmc */
|
|
|
|
|
rmc = nil;
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[received_reply_rmc_queue_gate lock];
|
|
|
|
|
/* Check to see if what we are looking for is on the queue. */
|
|
|
|
|
count = [received_reply_rmc_queue count];
|
|
|
|
|
/* xxx There should be a per-thread queue of rmcs so we can do
|
1994-11-04 16:29:24 +00:00
|
|
|
|
callbacks when multi-threaded. */
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
aRmc = [received_reply_rmc_queue objectAtIndex: i];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if ([aRmc connection] == self
|
|
|
|
|
&& [aRmc sequenceNumber] == n)
|
|
|
|
|
{
|
|
|
|
|
if (debug_connection)
|
|
|
|
|
printf("Getting received reply from queue\n");
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[received_reply_rmc_queue removeObjectAtIndex:i];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
rmc = aRmc;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[received_reply_rmc_queue_gate unlock];
|
|
|
|
|
|
|
|
|
|
/* What we needed was not on the queue, get it from the network. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if (rmc == nil)
|
|
|
|
|
rmc = [self _newReceivedRmcWithTimeout:in_timeout];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
/* We timed out on the network. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if (rmc == nil)
|
|
|
|
|
{
|
|
|
|
|
/* We timed out */
|
|
|
|
|
[self error:"connection timed out after waiting %d milliseconds "
|
|
|
|
|
"for a reply",
|
|
|
|
|
in_timeout];
|
|
|
|
|
/* Eventually we need to change this from crashing to
|
|
|
|
|
connection invalidating? I want to use gcc exceptions for this. */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Process the rmc we got */
|
|
|
|
|
switch ([rmc identifier])
|
|
|
|
|
{
|
|
|
|
|
case ROOTPROXY_REQUEST:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[self _service_rootObject: rmc];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[rmc dismiss];
|
|
|
|
|
break;
|
|
|
|
|
case METHODTYPE_REQUEST:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[self _service_typeForSelector: rmc];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[rmc dismiss];
|
|
|
|
|
break;
|
|
|
|
|
case ROOTPROXY_REPLY:
|
|
|
|
|
case METHOD_REPLY:
|
|
|
|
|
case METHODTYPE_REPLY:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* We got a reply... */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if ([rmc connection] != self)
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* ... but it wasn't for us; enqueue it. */
|
|
|
|
|
[received_reply_rmc_queue_gate lock];
|
|
|
|
|
[received_reply_rmc_queue enqueueObject:rmc];
|
|
|
|
|
[received_reply_rmc_queue_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* ... and it's for us; make sure the sequence is right. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if ([rmc sequenceNumber] != n)
|
|
|
|
|
[self error:"sequence number mismatch %d != %d\n",
|
|
|
|
|
[rmc sequenceNumber], n];
|
|
|
|
|
if (debug_connection)
|
|
|
|
|
printf("received reply number %d\n", n);
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* ... and all checks out; return it. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return rmc;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case METHOD_REQUEST:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* We got a new request while waiting for a reply.
|
|
|
|
|
We can either
|
|
|
|
|
(1) honor new requests from other connections immediately, or
|
|
|
|
|
(2) just queue them. */
|
|
|
|
|
if (delay_dialog_interruptions && [rmc connection] != self)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
/* Here we queue them */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[received_request_rmc_queue_gate lock];
|
|
|
|
|
[received_request_rmc_queue enqueueObject:rmc];
|
|
|
|
|
[received_request_rmc_queue_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Here we honor them right away */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[self _service_forwardForProxy: rmc];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case CONNECTION_SHUTDOWN:
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[[rmc connection] _service_shutdown: rmc forConnection: self];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[self error:"unrecognized ConnectedDecoder identifier"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
goto again;
|
|
|
|
|
|
|
|
|
|
return rmc;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
/* Managing objects and proxies. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* This should get called whenever an object free's itself */
|
|
|
|
|
+ (void) removeLocalObject: anObj
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
id c;
|
|
|
|
|
int i, count = [connection_array count];
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
c = [connection_array objectAtIndex:i];
|
|
|
|
|
[c removeLocalObject: anObj];
|
|
|
|
|
[c removeProxy: anObj];
|
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) removeLocalObject: anObj
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
[proxiesHashGate lock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* This also releases anObj */
|
|
|
|
|
NSMapRemove (local_targets, (void*)anObj);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate unlock];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) removeProxy: (Proxy*)aProxy
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned target = [aProxy targetForProxy];
|
|
|
|
|
[proxiesHashGate lock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* This also releases aProxy */
|
|
|
|
|
NSMapRemove (remote_proxies, (void*)target);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate unlock];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id <Collecting>) localObjects
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
id c;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
[proxiesHashGate lock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
c = NSAllMapTableValues (local_targets);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate unlock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return c;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id <Collecting>) proxies
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
id c;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
[proxiesHashGate lock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
c = NSAllMapTableValues (remote_proxies);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate unlock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return c;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (Proxy*) proxyForTarget: (unsigned)target
|
|
|
|
|
{
|
|
|
|
|
Proxy *p;
|
|
|
|
|
[proxiesHashGate lock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
p = NSMapGet (remote_proxies, (void*)target);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate unlock];
|
|
|
|
|
assert(!p || [p connectionForProxy] == self);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) addProxy: (Proxy*) aProxy
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned target = [aProxy targetForProxy];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
assert(aProxy->isa == [Proxy class]);
|
|
|
|
|
assert([aProxy connectionForProxy] == self);
|
|
|
|
|
[proxiesHashGate lock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if (NSMapGet (remote_proxies, (void*)target))
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[self error:"Trying to add the same proxy twice"];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
NSMapInsert (remote_proxies, (void*)target, aProxy);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate unlock];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) addLocalObject: anObj
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
[proxiesHashGate lock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* xxx Do we need to check to make sure it's not already there? */
|
|
|
|
|
/* This retains anObj */
|
|
|
|
|
NSMapInsert (local_targets, (void*)anObj, anObj);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate unlock];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (BOOL) includesProxyForTarget: (unsigned)target
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
BOOL ret;
|
|
|
|
|
[proxiesHashGate lock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
ret = NSMapGet (remote_proxies, (void*)target) ? YES : NO;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate unlock];
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (BOOL) includesLocalObject: anObj
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
BOOL ret;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate lock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
ret = NSMapGet (local_targets, (void*)anObj) ? YES : NO;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
[proxiesHashGate unlock];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return ret;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
/* Pass nil to remove any reference keyed by aPort. */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
+ (void) setRootObject: anObj forInPort: (Port*)aPort
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
id oldRootObject = [self rootObjectForInPort: aPort];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* xxx This retains aPort? How will aPort ever get dealloc'ed? */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if (oldRootObject != anObj)
|
|
|
|
|
{
|
|
|
|
|
if (anObj)
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[root_object_dictionary_gate lock];
|
|
|
|
|
[root_object_dictionary putObject: anObj atKey: aPort];
|
|
|
|
|
[root_object_dictionary_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
else /* anObj == nil && oldRootObject != nil */
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[root_object_dictionary_gate lock];
|
|
|
|
|
[root_object_dictionary removeObjectAtKey: aPort];
|
|
|
|
|
[root_object_dictionary_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ rootObjectForInPort: (Port*)aPort
|
|
|
|
|
{
|
|
|
|
|
id ro;
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[root_object_dictionary_gate lock];
|
|
|
|
|
ro = [root_object_dictionary objectAtKey:aPort];
|
|
|
|
|
[root_object_dictionary_gate unlock];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return ro;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- setRootObject: anObj
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[[self class] setRootObject: anObj forInPort: in_port];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- rootObject
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return [[self class] rootObjectForInPort: in_port];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
/* Accessing ivars */
|
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
- (int) outTimeout
|
|
|
|
|
{
|
|
|
|
|
return out_timeout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (int) inTimeout
|
|
|
|
|
{
|
|
|
|
|
return in_timeout;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) setOutTimeout: (int)to
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
out_timeout = to;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) setInTimeout: (int)to
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
in_timeout = to;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (Class) portClass
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
return port_class;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) setPortClass: (Class) aPortClass
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
port_class = aPortClass;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (Class) proxyClass
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
/* we might replace this with a per-Connection proxy class. */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return default_proxy_class;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (Class) encodingClass
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return encoding_class;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (Class) decodingClass
|
|
|
|
|
{
|
|
|
|
|
/* we might replace this with a per-Connection class. */
|
|
|
|
|
return default_decoding_class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- outPort
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
return out_port;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- inPort
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
return in_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- delegate
|
|
|
|
|
{
|
|
|
|
|
return delegate;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (void) setDelegate: anObj
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
delegate = anObj;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
/* Support for cross-connection const-ptr cache. */
|
|
|
|
|
|
|
|
|
|
- (unsigned) _encoderCreateReferenceForConstPtr: (const void*)ptr
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
unsigned xref;
|
|
|
|
|
xref = NSCountMapTable (outgoing_const_ptr_2_xref) + 1;
|
|
|
|
|
assert (! NSMapGet (outgoing_const_ptr_2_xref, (void*)xref));
|
|
|
|
|
NSMapInsert (outgoing_const_ptr_2_xref, ptr, (void*)xref);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (unsigned) _encoderReferenceForConstPtr: (const void*)ptr
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return (unsigned) NSMapGet (outgoing_const_ptr_2_xref, ptr);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (unsigned) _decoderCreateReferenceForConstPtr: (const void*)ptr
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
unsigned xref;
|
|
|
|
|
xref = NSCountMapTable (incoming_xref_2_const_ptr);
|
|
|
|
|
NSMapInsert (incoming_xref_2_const_ptr, (void*)xref, ptr);
|
|
|
|
|
return xref;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
- (const void*) _decoderConstPtrAtReference: (unsigned)xref
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return NSMapGet (incoming_xref_2_const_ptr, (void*)xref);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Prevent trying to encode the connection itself */
|
|
|
|
|
|
1995-04-09 01:53:53 +00:00
|
|
|
|
- (void) encodeWithCoder: anEncoder
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
[self shouldNotImplement:_cmd];
|
|
|
|
|
}
|
|
|
|
|
|
1995-04-09 01:53:53 +00:00
|
|
|
|
+ newWithCoder: aDecoder;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
[self shouldNotImplement:_cmd];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
/* Shutting down and deallocating. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* We register this method with NSNotification for when a port dies. */
|
|
|
|
|
- portIsInvalid: anObj
|
|
|
|
|
{
|
|
|
|
|
if (anObj == in_port || anObj == out_port)
|
|
|
|
|
[self invalidate];
|
|
|
|
|
/* xxx What else? */
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* xxx This needs locks */
|
|
|
|
|
- (void) invalidate
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if (!is_valid)
|
|
|
|
|
return;
|
|
|
|
|
/* xxx Note: this is causing us to send a shutdown message
|
|
|
|
|
to the connection that shut *us* down. Don't do that.
|
|
|
|
|
Well, perhaps it's a good idea just in case other side didn't really
|
|
|
|
|
send us the shutdown; this way we let them know we're going away */
|
|
|
|
|
[self shutdown];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* This needs locks */
|
|
|
|
|
- (void) dealloc
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if (debug_connection)
|
|
|
|
|
printf("deallocating 0x%x\n", (unsigned)self);
|
|
|
|
|
[self invalidate];
|
|
|
|
|
[connection_array removeObject: self];
|
|
|
|
|
/* Remove rootObject from root_object_dictionary
|
|
|
|
|
if this is last connection */
|
|
|
|
|
if (![Connection connectionsCountWithInPort:in_port])
|
|
|
|
|
[Connection setRootObject:nil forInPort:in_port];
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
[in_port release];
|
|
|
|
|
[out_port release];
|
|
|
|
|
|
|
|
|
|
[proxiesHashGate lock];
|
|
|
|
|
NSFreeMapTable (remote_proxies);
|
|
|
|
|
NSFreeMapTable (local_targets);
|
|
|
|
|
NSFreeMapTable (incoming_xref_2_const_ptr);
|
|
|
|
|
NSFreeMapTable (outgoing_const_ptr_2_xref);
|
|
|
|
|
[proxiesHashGate unlock];
|
|
|
|
|
|
|
|
|
|
[super dealloc];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|