mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Assert is_valid in many places.
([Connection +newForInPort:outPort:ancestorConnection:]): Set is_valid to 1. Only ask for notification of out port death if out port is non-nil. ([Connection -portIsInvalid:]): Properly get the port from the notification object. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1089 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0e774391ed
commit
c2cf958548
1 changed files with 91 additions and 20 deletions
|
@ -356,6 +356,7 @@ static int messages_received_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
newConn = [[Connection alloc] _superInit];
|
newConn = [[Connection alloc] _superInit];
|
||||||
|
newConn->is_valid = 1;
|
||||||
if (debug_connection)
|
if (debug_connection)
|
||||||
fprintf(stderr, "Created new connection 0x%x\n\t%s\n\t%s\n",
|
fprintf(stderr, "Created new connection 0x%x\n\t%s\n\t%s\n",
|
||||||
(unsigned)newConn,
|
(unsigned)newConn,
|
||||||
|
@ -415,10 +416,15 @@ static int messages_received_count;
|
||||||
selector: @selector(portIsInvalid:)
|
selector: @selector(portIsInvalid:)
|
||||||
name: PortBecameInvalidNotification
|
name: PortBecameInvalidNotification
|
||||||
object: ip];
|
object: ip];
|
||||||
[NotificationDispatcher addObserver: newConn
|
if (op)
|
||||||
selector: @selector(portIsInvalid:)
|
[NotificationDispatcher addObserver: newConn
|
||||||
name: PortBecameInvalidNotification
|
selector: @selector(portIsInvalid:)
|
||||||
object: op];
|
name: PortBecameInvalidNotification
|
||||||
|
object: op];
|
||||||
|
/* if OP is nil, making this notification request would have
|
||||||
|
registered us to receive all PortBecameInvalidNotification
|
||||||
|
requests, independent of which port posted them. This isn't
|
||||||
|
what we want. */
|
||||||
|
|
||||||
/* xxx This is weird, though. When will newConn ever get dealloc'ed?
|
/* xxx This is weird, though. When will newConn ever get dealloc'ed?
|
||||||
connectionArray will retain it, but connectionArray will never get
|
connectionArray will retain it, but connectionArray will never get
|
||||||
|
@ -450,6 +456,7 @@ static int messages_received_count;
|
||||||
id rmc;
|
id rmc;
|
||||||
|
|
||||||
assert(in_port);
|
assert(in_port);
|
||||||
|
assert (is_valid);
|
||||||
rmc = [[self encodingClass] newForWritingWithConnection: self
|
rmc = [[self encodingClass] newForWritingWithConnection: self
|
||||||
sequenceNumber: [self _newMsgNumber]
|
sequenceNumber: [self _newMsgNumber]
|
||||||
identifier: METHOD_REQUEST];
|
identifier: METHOD_REQUEST];
|
||||||
|
@ -462,6 +469,7 @@ static int messages_received_count;
|
||||||
id rmc = [[self encodingClass] newForWritingWithConnection: self
|
id rmc = [[self encodingClass] newForWritingWithConnection: self
|
||||||
sequenceNumber: n
|
sequenceNumber: n
|
||||||
identifier: METHOD_REPLY];
|
identifier: METHOD_REPLY];
|
||||||
|
assert (is_valid);
|
||||||
return rmc;
|
return rmc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,6 +507,7 @@ static int messages_received_count;
|
||||||
retval_t retframe;
|
retval_t retframe;
|
||||||
int seq_num;
|
int seq_num;
|
||||||
|
|
||||||
|
assert (is_valid);
|
||||||
op = [self newSendingRequestRmc];
|
op = [self newSendingRequestRmc];
|
||||||
seq_num = [op sequenceNumber];
|
seq_num = [op sequenceNumber];
|
||||||
|
|
||||||
|
@ -595,6 +604,8 @@ static int messages_received_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert (is_valid);
|
||||||
|
|
||||||
/* Save this for later */
|
/* Save this for later */
|
||||||
reply_sequence_number = [aRmc sequenceNumber];
|
reply_sequence_number = [aRmc sequenceNumber];
|
||||||
|
|
||||||
|
@ -621,6 +632,7 @@ static int messages_received_count;
|
||||||
int seq_num = [self _newMsgNumber];
|
int seq_num = [self _newMsgNumber];
|
||||||
|
|
||||||
assert(in_port);
|
assert(in_port);
|
||||||
|
assert (is_valid);
|
||||||
op = [[self encodingClass]
|
op = [[self encodingClass]
|
||||||
newForWritingWithConnection: self
|
newForWritingWithConnection: self
|
||||||
sequenceNumber: seq_num
|
sequenceNumber: seq_num
|
||||||
|
@ -641,6 +653,7 @@ static int messages_received_count;
|
||||||
sequenceNumber: [rmc sequenceNumber]
|
sequenceNumber: [rmc sequenceNumber]
|
||||||
identifier: ROOTPROXY_REPLY];
|
identifier: ROOTPROXY_REPLY];
|
||||||
assert (in_port);
|
assert (in_port);
|
||||||
|
assert (is_valid);
|
||||||
/* Perhaps we should turn this into a class method. */
|
/* Perhaps we should turn this into a class method. */
|
||||||
assert([rmc connection] == self);
|
assert([rmc connection] == self);
|
||||||
[op encodeObject: rootObject withName: @"root object"];
|
[op encodeObject: rootObject withName: @"root object"];
|
||||||
|
@ -652,6 +665,7 @@ static int messages_received_count;
|
||||||
id op;
|
id op;
|
||||||
|
|
||||||
assert(in_port);
|
assert(in_port);
|
||||||
|
assert (is_valid);
|
||||||
op = [[self encodingClass]
|
op = [[self encodingClass]
|
||||||
newForWritingWithConnection: self
|
newForWritingWithConnection: self
|
||||||
sequenceNumber: [self _newMsgNumber]
|
sequenceNumber: [self _newMsgNumber]
|
||||||
|
@ -661,10 +675,11 @@ static int messages_received_count;
|
||||||
|
|
||||||
- (void) _service_shutdown: rmc forConnection: receiving_connection
|
- (void) _service_shutdown: rmc forConnection: receiving_connection
|
||||||
{
|
{
|
||||||
|
assert (is_valid);
|
||||||
[self invalidate];
|
[self invalidate];
|
||||||
if (receiving_connection == self)
|
if (receiving_connection == self)
|
||||||
[self error: "connection waiting for request was shut down"];
|
[self error: "connection waiting for request was shut down"];
|
||||||
[self dealloc]; // xxx release instead?
|
[self dealloc]; // xxx release instead? YES!!
|
||||||
[rmc dismiss];
|
[rmc dismiss];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -675,6 +690,7 @@ static int messages_received_count;
|
||||||
int seq_num;
|
int seq_num;
|
||||||
|
|
||||||
assert(in_port);
|
assert(in_port);
|
||||||
|
assert (is_valid);
|
||||||
seq_num = [self _newMsgNumber];
|
seq_num = [self _newMsgNumber];
|
||||||
op = [[self encodingClass]
|
op = [[self encodingClass]
|
||||||
newForWritingWithConnection: self
|
newForWritingWithConnection: self
|
||||||
|
@ -704,6 +720,7 @@ static int messages_received_count;
|
||||||
struct objc_method* m;
|
struct objc_method* m;
|
||||||
|
|
||||||
assert(in_port);
|
assert(in_port);
|
||||||
|
assert (is_valid);
|
||||||
assert([rmc connection] == self);
|
assert([rmc connection] == self);
|
||||||
op = [[self encodingClass]
|
op = [[self encodingClass]
|
||||||
newForWritingWithConnection: [rmc connection]
|
newForWritingWithConnection: [rmc connection]
|
||||||
|
@ -750,6 +767,7 @@ static int messages_received_count;
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
assert (is_valid);
|
||||||
[sequenceNumberGate lock];
|
[sequenceNumberGate lock];
|
||||||
n = message_count++;
|
n = message_count++;
|
||||||
[sequenceNumberGate unlock];
|
[sequenceNumberGate unlock];
|
||||||
|
@ -762,6 +780,7 @@ static int messages_received_count;
|
||||||
{
|
{
|
||||||
id rmc;
|
id rmc;
|
||||||
|
|
||||||
|
assert (is_valid);
|
||||||
rmc = [[self decodingClass] newDecodingWithConnection: self
|
rmc = [[self decodingClass] newDecodingWithConnection: self
|
||||||
timeout: to];
|
timeout: to];
|
||||||
/* If this times out, rmc will be nil. */
|
/* If this times out, rmc will be nil. */
|
||||||
|
@ -774,6 +793,7 @@ static int messages_received_count;
|
||||||
id rmc;
|
id rmc;
|
||||||
unsigned count;
|
unsigned count;
|
||||||
|
|
||||||
|
assert (is_valid);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -849,6 +869,7 @@ static int messages_received_count;
|
||||||
id rmc, aRmc;
|
id rmc, aRmc;
|
||||||
unsigned count, i;
|
unsigned count, i;
|
||||||
|
|
||||||
|
assert (is_valid);
|
||||||
again:
|
again:
|
||||||
|
|
||||||
/* Get a rmc */
|
/* Get a rmc */
|
||||||
|
@ -958,6 +979,7 @@ static int messages_received_count;
|
||||||
|
|
||||||
- (void) addLocalObject: anObj
|
- (void) addLocalObject: anObj
|
||||||
{
|
{
|
||||||
|
assert (is_valid);
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
/* xxx Do we need to check to make sure it's not already there? */
|
/* xxx Do we need to check to make sure it's not already there? */
|
||||||
/* This retains anObj. */
|
/* This retains anObj. */
|
||||||
|
@ -972,6 +994,8 @@ static int messages_received_count;
|
||||||
{
|
{
|
||||||
id c;
|
id c;
|
||||||
int i, count = [connection_array count];
|
int i, count = [connection_array count];
|
||||||
|
|
||||||
|
/* Don't assert (is_valid); */
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
c = [connection_array objectAtIndex:i];
|
c = [connection_array objectAtIndex:i];
|
||||||
|
@ -982,6 +1006,7 @@ static int messages_received_count;
|
||||||
|
|
||||||
- (void) removeLocalObject: anObj
|
- (void) removeLocalObject: anObj
|
||||||
{
|
{
|
||||||
|
/* Don't assert (is_valid); */
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
/* This also releases anObj */
|
/* This also releases anObj */
|
||||||
NSMapRemove (local_targets, (void*)anObj);
|
NSMapRemove (local_targets, (void*)anObj);
|
||||||
|
@ -992,6 +1017,8 @@ static int messages_received_count;
|
||||||
- (void) removeProxy: (Proxy*)aProxy
|
- (void) removeProxy: (Proxy*)aProxy
|
||||||
{
|
{
|
||||||
unsigned target = [aProxy targetForProxy];
|
unsigned target = [aProxy targetForProxy];
|
||||||
|
|
||||||
|
/* Don't assert (is_valid); */
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
/* This also releases aProxy */
|
/* This also releases aProxy */
|
||||||
NSMapRemove (remote_proxies, (void*)target);
|
NSMapRemove (remote_proxies, (void*)target);
|
||||||
|
@ -1002,6 +1029,7 @@ static int messages_received_count;
|
||||||
{
|
{
|
||||||
id c;
|
id c;
|
||||||
|
|
||||||
|
/* Don't assert (is_valid); */
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
c = NSAllMapTableValues (local_targets);
|
c = NSAllMapTableValues (local_targets);
|
||||||
[proxiesHashGate unlock];
|
[proxiesHashGate unlock];
|
||||||
|
@ -1012,6 +1040,7 @@ static int messages_received_count;
|
||||||
{
|
{
|
||||||
id c;
|
id c;
|
||||||
|
|
||||||
|
/* Don't assert (is_valid); */
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
c = NSAllMapTableValues (remote_proxies);
|
c = NSAllMapTableValues (remote_proxies);
|
||||||
[proxiesHashGate unlock];
|
[proxiesHashGate unlock];
|
||||||
|
@ -1021,6 +1050,8 @@ static int messages_received_count;
|
||||||
- (Proxy*) proxyForTarget: (unsigned)target
|
- (Proxy*) proxyForTarget: (unsigned)target
|
||||||
{
|
{
|
||||||
Proxy *p;
|
Proxy *p;
|
||||||
|
|
||||||
|
/* Don't assert (is_valid); */
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
p = NSMapGet (remote_proxies, (void*)target);
|
p = NSMapGet (remote_proxies, (void*)target);
|
||||||
[proxiesHashGate unlock];
|
[proxiesHashGate unlock];
|
||||||
|
@ -1032,6 +1063,7 @@ static int messages_received_count;
|
||||||
{
|
{
|
||||||
unsigned target = [aProxy targetForProxy];
|
unsigned target = [aProxy targetForProxy];
|
||||||
|
|
||||||
|
assert (is_valid);
|
||||||
assert(aProxy->isa == [Proxy class]);
|
assert(aProxy->isa == [Proxy class]);
|
||||||
assert([aProxy connectionForProxy] == self);
|
assert([aProxy connectionForProxy] == self);
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
|
@ -1044,6 +1076,8 @@ static int messages_received_count;
|
||||||
- (BOOL) includesProxyForTarget: (unsigned)target
|
- (BOOL) includesProxyForTarget: (unsigned)target
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
|
/* Don't assert (is_valid); */
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
ret = NSMapGet (remote_proxies, (void*)target) ? YES : NO;
|
ret = NSMapGet (remote_proxies, (void*)target) ? YES : NO;
|
||||||
[proxiesHashGate unlock];
|
[proxiesHashGate unlock];
|
||||||
|
@ -1053,6 +1087,8 @@ static int messages_received_count;
|
||||||
- (BOOL) includesLocalObject: anObj
|
- (BOOL) includesLocalObject: anObj
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
|
/* Don't assert (is_valid); */
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
ret = NSMapGet (local_targets, (void*)anObj) ? YES : NO;
|
ret = NSMapGet (local_targets, (void*)anObj) ? YES : NO;
|
||||||
[proxiesHashGate unlock];
|
[proxiesHashGate unlock];
|
||||||
|
@ -1068,6 +1104,8 @@ static int messages_received_count;
|
||||||
+ (BOOL) includesLocalObject: anObj
|
+ (BOOL) includesLocalObject: anObj
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
|
/* Don't assert (is_valid); */
|
||||||
assert (all_connections_local_targets);
|
assert (all_connections_local_targets);
|
||||||
[proxiesHashGate lock];
|
[proxiesHashGate lock];
|
||||||
ret = NSMapGet (all_connections_local_targets, (void*)anObj) ? YES : NO;
|
ret = NSMapGet (all_connections_local_targets, (void*)anObj) ? YES : NO;
|
||||||
|
@ -1081,6 +1119,7 @@ static int messages_received_count;
|
||||||
{
|
{
|
||||||
id oldRootObject = [self rootObjectForInPort: aPort];
|
id oldRootObject = [self rootObjectForInPort: aPort];
|
||||||
|
|
||||||
|
assert ([aPort isValid]);
|
||||||
/* xxx This retains aPort? How will aPort ever get dealloc'ed? */
|
/* xxx This retains aPort? How will aPort ever get dealloc'ed? */
|
||||||
if (oldRootObject != anObj)
|
if (oldRootObject != anObj)
|
||||||
{
|
{
|
||||||
|
@ -1102,6 +1141,7 @@ static int messages_received_count;
|
||||||
+ rootObjectForInPort: (Port*)aPort
|
+ rootObjectForInPort: (Port*)aPort
|
||||||
{
|
{
|
||||||
id ro;
|
id ro;
|
||||||
|
|
||||||
[root_object_dictionary_gate lock];
|
[root_object_dictionary_gate lock];
|
||||||
ro = [root_object_dictionary objectAtKey:aPort];
|
ro = [root_object_dictionary objectAtKey:aPort];
|
||||||
[root_object_dictionary_gate unlock];
|
[root_object_dictionary_gate unlock];
|
||||||
|
@ -1205,6 +1245,8 @@ static int messages_received_count;
|
||||||
- (unsigned) _encoderCreateReferenceForConstPtr: (const void*)ptr
|
- (unsigned) _encoderCreateReferenceForConstPtr: (const void*)ptr
|
||||||
{
|
{
|
||||||
unsigned xref;
|
unsigned xref;
|
||||||
|
|
||||||
|
assert (is_valid);
|
||||||
/* This must match the assignment of xref in _decoderCreateRef... */
|
/* This must match the assignment of xref in _decoderCreateRef... */
|
||||||
xref = NSCountMapTable (outgoing_const_ptr_2_xref) + 1;
|
xref = NSCountMapTable (outgoing_const_ptr_2_xref) + 1;
|
||||||
assert (! NSMapGet (outgoing_const_ptr_2_xref, (void*)xref));
|
assert (! NSMapGet (outgoing_const_ptr_2_xref, (void*)xref));
|
||||||
|
@ -1213,12 +1255,15 @@ static int messages_received_count;
|
||||||
|
|
||||||
- (unsigned) _encoderReferenceForConstPtr: (const void*)ptr
|
- (unsigned) _encoderReferenceForConstPtr: (const void*)ptr
|
||||||
{
|
{
|
||||||
|
assert (is_valid);
|
||||||
return (unsigned) NSMapGet (outgoing_const_ptr_2_xref, ptr);
|
return (unsigned) NSMapGet (outgoing_const_ptr_2_xref, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned) _decoderCreateReferenceForConstPtr: (const void*)ptr
|
- (unsigned) _decoderCreateReferenceForConstPtr: (const void*)ptr
|
||||||
{
|
{
|
||||||
unsigned xref;
|
unsigned xref;
|
||||||
|
|
||||||
|
assert (is_valid);
|
||||||
/* This must match the assignment of xref in _encoderCreateRef... */
|
/* This must match the assignment of xref in _encoderCreateRef... */
|
||||||
xref = NSCountMapTable (incoming_xref_2_const_ptr) + 1;
|
xref = NSCountMapTable (incoming_xref_2_const_ptr) + 1;
|
||||||
NSMapInsert (incoming_xref_2_const_ptr, (void*)xref, ptr);
|
NSMapInsert (incoming_xref_2_const_ptr, (void*)xref, ptr);
|
||||||
|
@ -1227,6 +1272,7 @@ static int messages_received_count;
|
||||||
|
|
||||||
- (const void*) _decoderConstPtrAtReference: (unsigned)xref
|
- (const void*) _decoderConstPtrAtReference: (unsigned)xref
|
||||||
{
|
{
|
||||||
|
assert (is_valid);
|
||||||
return NSMapGet (incoming_xref_2_const_ptr, (void*)xref);
|
return NSMapGet (incoming_xref_2_const_ptr, (void*)xref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1249,27 +1295,52 @@ static int messages_received_count;
|
||||||
/* Shutting down and deallocating. */
|
/* Shutting down and deallocating. */
|
||||||
|
|
||||||
/* We register this method with NotificationDispatcher for when a port dies. */
|
/* We register this method with NotificationDispatcher for when a port dies. */
|
||||||
- portIsInvalid: anObj
|
- (void) portIsInvalid: notification
|
||||||
{
|
{
|
||||||
if (anObj == in_port || anObj == out_port)
|
id port = [notification object];
|
||||||
[self invalidate];
|
|
||||||
/* xxx What else? */
|
assert (is_valid);
|
||||||
return nil;
|
if (debug_connection)
|
||||||
|
fprintf (stderr, "Received port invalidation notification for "
|
||||||
|
"connection 0x%x\n\t%s\n", (unsigned)self,
|
||||||
|
[[port description] cStringNoCopy]);
|
||||||
|
/* We shouldn't be getting any port invalidation notifications,
|
||||||
|
except from our own ports; this is how we registered ourselves
|
||||||
|
with the NotificationDispatcher in
|
||||||
|
+newForInPort:outPort:ancestorConnection. */
|
||||||
|
assert (port == in_port || port == out_port);
|
||||||
|
[self invalidate];
|
||||||
|
/* xxx Anything else? */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* xxx This needs locks */
|
/* xxx This needs locks */
|
||||||
- (void) invalidate
|
- (void) invalidate
|
||||||
{
|
{
|
||||||
if (!is_valid)
|
if (is_valid)
|
||||||
return;
|
{
|
||||||
/* xxx Note: this is causing us to send a shutdown message
|
is_valid = 0;
|
||||||
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
|
/* xxx Note: this is causing us to send a shutdown message
|
||||||
send us the shutdown; this way we let them know we're going away */
|
to the connection that shut *us* down. Don't do that.
|
||||||
[self shutdown];
|
Well, perhaps it's a good idea just in case other side didn't really
|
||||||
[NotificationDispatcher
|
send us the shutdown; this way we let them know we're going away */
|
||||||
postNotificationName: ConnectionBecameInvalidNotification
|
#if 0
|
||||||
object: self];
|
[self shutdown];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (debug_connection)
|
||||||
|
fprintf(stderr, "Invalidating connection 0x%x\n\t%s\n\t%s\n",
|
||||||
|
(unsigned)self,
|
||||||
|
[[in_port description] cStringNoCopy],
|
||||||
|
[[out_port description] cStringNoCopy]);
|
||||||
|
|
||||||
|
[NotificationDispatcher
|
||||||
|
postNotificationName: ConnectionBecameInvalidNotification
|
||||||
|
object: self];
|
||||||
|
/* xxx Anything else? */
|
||||||
|
/* xxx Yes, somehow Proxies of connections with invalid ports
|
||||||
|
are being asked to encode themselves. */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This needs locks */
|
/* This needs locks */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue