From 8bb5de48240fef49287c403880d234f3b0310d63 Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 21 Nov 2008 08:02:41 +0000 Subject: [PATCH] Add ivar for expansion, remove a few lines unused code, add private keepalive. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27105 72102866-910b-0410-8b05-ffd578937521 --- Headers/Foundation/NSConnection.h | 6 ++-- Source/NSConnection.m | 47 +++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Headers/Foundation/NSConnection.h b/Headers/Foundation/NSConnection.h index c6f55bca3..c2ee2c17b 100644 --- a/Headers/Foundation/NSConnection.h +++ b/Headers/Foundation/NSConnection.h @@ -101,8 +101,8 @@ GS_EXPORT NSString* const NSConnectionProxyCount; /* Objects received */ BOOL _authenticateOut; BOOL _multipleThreads; BOOL _shuttingDown; - BOOL _dummy1; - BOOL _dummy2; + BOOL _useKeepalive; + BOOL _dummy; NSPort *_receivePort; NSPort *_sendPort; unsigned _requestDepth; @@ -132,6 +132,8 @@ GS_EXPORT NSString* const NSConnectionProxyCount; /* Objects received */ NSMutableArray *_cachedEncoders; NSString *_registeredName; NSPortNameServer *_nameServer; + int _lastKeepalive; + void *_reserved; // For expansion } + (NSArray*) allConnections; diff --git a/Source/NSConnection.m b/Source/NSConnection.m index f1d059b68..342f27125 100644 --- a/Source/NSConnection.m +++ b/Source/NSConnection.m @@ -239,6 +239,7 @@ stringFromMsgType(int type) - (void) handlePortMessage: (NSPortMessage*)msg; - (void) _runInNewThread; + (void) setDebug: (int)val; +- (void) _enableKeepalive; - (void) addLocalObject: (NSDistantObject*)anObj; - (void) removeLocalObject: (NSDistantObject*)anObj; @@ -2328,6 +2329,13 @@ static void retEncoder (DOContext *ctxt) GSIMapNode node; [rmc decodeValueOfObjCType: @encode(int) at: &sequence]; + if (type == ROOTPROXY_REPLY && sequence == _lastKeepalive) + { + _lastKeepalive = 0; + NSDebugMLLog(@"NSConnection", @"Handled keepalive %d on %@", + sequence, conn); + [self _doneInRmc: rmc]; + } M_LOCK(conn->_queueGate); node = GSIMapNodeForKey(conn->_replyMap, (GSIMapKey)sequence); if (node == 0) @@ -2387,6 +2395,42 @@ static void retEncoder (DOContext *ctxt) debug_connection = val; } +- (void) _keepalive: (NSNotification*)n +{ + if ([self isValid]) + { + if (_lastKeepalive == 0) + { + NSPortCoder *op; + + /* Send out a root proxy request to ping the other end. + */ + op = [self _makeOutRmc: 0 generate: &_lastKeepalive reply: NO]; + [self _sendOutRmc: op type: ROOTPROXY_REQUEST]; + } + else + { + /* keepalive timeout outstanding still. + */ + [self invalidate]; + } + } +} + +- (void) _enableKeepalive +{ + if (_receivePort == _sendPort) + { + [NSException raise: NSGenericException format: @"Illegal operation"]; + } + _useKeepalive = YES; + _lastKeepalive = 0; + [self enableMultipleThreads]; + [[NSNotificationCenter defaultCenter] addObserver: self + selector: @selector(_keepalive:) + name: @"GSHousekeeping" object: nil]; +} + static void callDecoder (DOContext *ctxt) { const char *type = ctxt->type; @@ -3063,7 +3107,6 @@ static void callEncoder (DOContext *ctxt) NSDate *limit; BOOL sent = NO; BOOL raiseException = NO; - BOOL needsReply = NO; NSMutableArray *components = [c _components]; if (_authenticateOut == YES @@ -3084,7 +3127,6 @@ static void callEncoder (DOContext *ctxt) switch (msgid) { case PROXY_RETAIN: - needsReply = YES; case CONNECTION_SHUTDOWN: case METHOD_REPLY: case ROOTPROXY_REPLY: @@ -3097,7 +3139,6 @@ static void callEncoder (DOContext *ctxt) case METHOD_REQUEST: case ROOTPROXY_REQUEST: case METHODTYPE_REQUEST: - needsReply = YES; default: raiseException = YES; break;