From 10fd5300fb2e7f8c68bb671c411dbf3452da59d9 Mon Sep 17 00:00:00 2001 From: mccallum Date: Fri, 1 Mar 1996 16:06:03 +0000 Subject: [PATCH] Overhauled for new Port heirarchy. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1021 72102866-910b-0410-8b05-ffd578937521 --- Headers/gnustep/base/Port.h | 69 +++++++++++------ Source/Port.m | 150 +++++++++++++++++++++++++----------- Source/objects/Port.h | 69 +++++++++++------ 3 files changed, 196 insertions(+), 92 deletions(-) diff --git a/Headers/gnustep/base/Port.h b/Headers/gnustep/base/Port.h index c40df9a6f..71af3c8c2 100644 --- a/Headers/gnustep/base/Port.h +++ b/Headers/gnustep/base/Port.h @@ -1,8 +1,8 @@ /* Interface for abstract superclass port for use with Connection - Copyright (C) 1994, 1995 Free Software Foundation, Inc. + Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. Written by: R. Andrew McCallum - Date: July 1994 + Created: July 1994 This file is part of the GNU Objective C Class Library. @@ -25,37 +25,60 @@ #define __Port_h_OBJECTS_INCLUDE #include -#include #include +#include #include -@class Connection; +/* xxx Use something like this? */ +@protocol PacketSending +@end -@interface Port : RetainingNotifier +@interface Port : NSObject +{ + unsigned is_valid:1; + unsigned tcp_port_filler:7; + unsigned retain_count:24; +} +- (void) invalidate; +- (BOOL) isValid; +- (void) close; -/* xxx These will probably change */ -+ newRegisteredPortWithName: (id )n; -+ newPortFromRegisterWithName: (id )n onHost: (id )host; -+ newPort; +- (Class) packetClass; -/* xxx These sending and receiving interfaces will change */ +@end -- (int) sendPacket: (const char *)b length: (int)l - toPort: (Port*) remote; -- (int) sendPacket: (const char *)b length: (int)l - toPort: (Port*)remote - timeout: (int) milliseconds; -- (int) receivePacket: (char*)b length: (int)l - fromPort: (Port**) remote; -- (int) receivePacket: (char*)b length: (int)l - fromPort: (Port**) remote - timeout: (int) milliseconds; +@interface InPort : Port -- (BOOL) isSoft; ++ newForReceiving; ++ newForReceivingFromRegisteredName: (id )name; -- (unsigned) hash; -- (BOOL) isEqual: anotherPort; +/* Get a packet from the net and return it. If no packet is received + within MILLISECONDS, then return nil. The caller is responsible + for releasing the packet. */ +- receivePacketWithTimeout: (int)milliseconds; + +@end + + +@interface OutPort : Port + ++ newForSendingToRegisteredName: (id )name + onHost: (id )hostname; +- (BOOL) sendPacket: packet withTimeout: (int)milliseconds; + +@end + +extern NSString *PortBecameInvalidNotification; + +@interface Packet : MemoryStream +{ + id reply_port; +} + +- initForSendingWithCapacity: (unsigned)c + replyPort: p; +- replyPort; @end diff --git a/Source/Port.m b/Source/Port.m index 817be461d..6dd2e1419 100644 --- a/Source/Port.m +++ b/Source/Port.m @@ -2,7 +2,7 @@ Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. Written by: R. Andrew McCallum - Date: July 1994 + Created: July 1994 This file is part of the GNU Objective C Class Library. @@ -26,75 +26,133 @@ @implementation Port -+ newRegisteredPortWithName: (id )n +/* This is the designated initializer. */ +- init +{ + [super init]; + is_valid = YES; + retain_count = 0; + return self; +} + +- retain +{ + retain_count++; + return self; +} + +- (oneway void) release +{ + if (!retain_count--) + [self dealloc]; +} + +- (unsigned) retainCount +{ + return retain_count; +} + +- (BOOL) isValid +{ + return is_valid; +} + +- (void) close +{ + [self invalidate]; +} + +- (void) invalidate +{ + is_valid = NO; +} + +- (Class) packetClass +{ + [self subclassResponsibility: _cmd]; + return nil; +} + +- (Class) classForConnectedCoder: aRmc +{ + /* Make sure that Connection's always send us bycopy, + i.e. as our own class, not a Proxy class. */ + return [self class]; +} + +- (void) encodeWithCoder: (id )anEncoder +{ + [super encodeWithCoder: anEncoder]; + /* xxx What else? */ +} + +- initWithCoder: (id )coder +{ + self = [super initWithCoder: coder]; + /* xxx What else? */ + return self; +} + +@end + + +@implementation InPort + ++ newForReceivingFromRegisteredName: (id )name { [self subclassResponsibility:_cmd]; return nil; } -+ newPortFromRegisterWithName: (id )n onHost: (id )host ++ newForReceiving +{ + return [self newForReceivingFromRegisteredName: nil]; +} + +- receivePacketWithTimeout: (int)milliseconds { [self subclassResponsibility:_cmd]; return nil; } -+ newPort +@end + + +@implementation OutPort + ++ newForSendingToRegisteredName: (id )name + onHost: (id )hostname { [self subclassResponsibility:_cmd]; return nil; } -/* These sending and receiving interfaces will change */ - -- (int) sendPacket: (const char *)b length: (int)l - toPort: (Port*) remote - timeout: (int) milliseconds -{ - [self subclassResponsibility:_cmd]; - return 0; -} - -- (int) sendPacket: (const char *)b length: (int)l - toPort: (Port*) remote -{ - return [self sendPacket:b length:l toPort:remote timeout:-1]; -} - -- (int) receivePacket: (char*)b length: (int)l - fromPort: (Port**) remote - timeout: (int) milliseconds -{ - [self subclassResponsibility:_cmd]; - return 0; -} - -- (int) receivePacket: (char*)b length: (int)l - fromPort: (Port**) remote -{ - return [self receivePacket:b length:l fromPort:remote timeout:-1]; -} - -- (BOOL) isSoft -{ - [self subclassResponsibility:_cmd]; - return YES; -} - -- (BOOL) isEqual: anotherPort +- (BOOL) sendPacket: packet withTimeout: (int)milliseconds { [self subclassResponsibility:_cmd]; return NO; } -- (unsigned) hash +@end + + +@implementation Packet + +/* xxx There should be a designated initializer for the Packet class. + Currently some subclasses and users, bypass this by calling + MemoryStream initializers. */ + +- initForSendingWithCapacity: (unsigned)c + replyPort: p { - [self subclassResponsibility:_cmd]; - return 0; + [super initWithCapacity: c]; + reply_port = p; + return self; } -- (void) encodeWithCoder: (id )anEncoder +- replyPort { - [super encodeWithCoder:anEncoder]; + return reply_port; } @end diff --git a/Source/objects/Port.h b/Source/objects/Port.h index c40df9a6f..71af3c8c2 100644 --- a/Source/objects/Port.h +++ b/Source/objects/Port.h @@ -1,8 +1,8 @@ /* Interface for abstract superclass port for use with Connection - Copyright (C) 1994, 1995 Free Software Foundation, Inc. + Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. Written by: R. Andrew McCallum - Date: July 1994 + Created: July 1994 This file is part of the GNU Objective C Class Library. @@ -25,37 +25,60 @@ #define __Port_h_OBJECTS_INCLUDE #include -#include #include +#include #include -@class Connection; +/* xxx Use something like this? */ +@protocol PacketSending +@end -@interface Port : RetainingNotifier +@interface Port : NSObject +{ + unsigned is_valid:1; + unsigned tcp_port_filler:7; + unsigned retain_count:24; +} +- (void) invalidate; +- (BOOL) isValid; +- (void) close; -/* xxx These will probably change */ -+ newRegisteredPortWithName: (id )n; -+ newPortFromRegisterWithName: (id )n onHost: (id )host; -+ newPort; +- (Class) packetClass; -/* xxx These sending and receiving interfaces will change */ +@end -- (int) sendPacket: (const char *)b length: (int)l - toPort: (Port*) remote; -- (int) sendPacket: (const char *)b length: (int)l - toPort: (Port*)remote - timeout: (int) milliseconds; -- (int) receivePacket: (char*)b length: (int)l - fromPort: (Port**) remote; -- (int) receivePacket: (char*)b length: (int)l - fromPort: (Port**) remote - timeout: (int) milliseconds; +@interface InPort : Port -- (BOOL) isSoft; ++ newForReceiving; ++ newForReceivingFromRegisteredName: (id )name; -- (unsigned) hash; -- (BOOL) isEqual: anotherPort; +/* Get a packet from the net and return it. If no packet is received + within MILLISECONDS, then return nil. The caller is responsible + for releasing the packet. */ +- receivePacketWithTimeout: (int)milliseconds; + +@end + + +@interface OutPort : Port + ++ newForSendingToRegisteredName: (id )name + onHost: (id )hostname; +- (BOOL) sendPacket: packet withTimeout: (int)milliseconds; + +@end + +extern NSString *PortBecameInvalidNotification; + +@interface Packet : MemoryStream +{ + id reply_port; +} + +- initForSendingWithCapacity: (unsigned)c + replyPort: p; +- replyPort; @end