Overhauled for new Port heirarchy.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1021 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mccallum 1996-03-01 16:06:03 +00:00
parent f56cfab056
commit 10fd5300fb
3 changed files with 196 additions and 92 deletions

View file

@ -1,8 +1,8 @@
/* Interface for abstract superclass port for use with Connection /* 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 <mccallum@gnu.ai.mit.edu> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: July 1994 Created: July 1994
This file is part of the GNU Objective C Class Library. This file is part of the GNU Objective C Class Library.
@ -25,37 +25,60 @@
#define __Port_h_OBJECTS_INCLUDE #define __Port_h_OBJECTS_INCLUDE
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/RetainingNotifier.h>
#include <objects/Coding.h> #include <objects/Coding.h>
#include <objects/MemoryStream.h>
#include <objects/NSString.h> #include <objects/NSString.h>
@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 */ - (Class) packetClass;
+ newRegisteredPortWithName: (id <String>)n;
+ newPortFromRegisterWithName: (id <String>)n onHost: (id <String>)host;
+ newPort;
/* 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 @interface InPort : Port
fromPort: (Port**) remote;
- (int) receivePacket: (char*)b length: (int)l
fromPort: (Port**) remote
timeout: (int) milliseconds;
- (BOOL) isSoft; + newForReceiving;
+ newForReceivingFromRegisteredName: (id <String>)name;
- (unsigned) hash; /* Get a packet from the net and return it. If no packet is received
- (BOOL) isEqual: anotherPort; within MILLISECONDS, then return nil. The caller is responsible
for releasing the packet. */
- receivePacketWithTimeout: (int)milliseconds;
@end
@interface OutPort : Port
+ newForSendingToRegisteredName: (id <String>)name
onHost: (id <String>)hostname;
- (BOOL) sendPacket: packet withTimeout: (int)milliseconds;
@end
extern NSString *PortBecameInvalidNotification;
@interface Packet : MemoryStream
{
id reply_port;
}
- initForSendingWithCapacity: (unsigned)c
replyPort: p;
- replyPort;
@end @end

View file

@ -2,7 +2,7 @@
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: July 1994 Created: July 1994
This file is part of the GNU Objective C Class Library. This file is part of the GNU Objective C Class Library.
@ -26,75 +26,133 @@
@implementation Port @implementation Port
+ newRegisteredPortWithName: (id <String>)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 <Encoding>)anEncoder
{
[super encodeWithCoder: anEncoder];
/* xxx What else? */
}
- initWithCoder: (id <Decoding>)coder
{
self = [super initWithCoder: coder];
/* xxx What else? */
return self;
}
@end
@implementation InPort
+ newForReceivingFromRegisteredName: (id <String>)name
{ {
[self subclassResponsibility:_cmd]; [self subclassResponsibility:_cmd];
return nil; return nil;
} }
+ newPortFromRegisterWithName: (id <String>)n onHost: (id <String>)host + newForReceiving
{
return [self newForReceivingFromRegisteredName: nil];
}
- receivePacketWithTimeout: (int)milliseconds
{ {
[self subclassResponsibility:_cmd]; [self subclassResponsibility:_cmd];
return nil; return nil;
} }
+ newPort @end
@implementation OutPort
+ newForSendingToRegisteredName: (id <String>)name
onHost: (id <String>)hostname
{ {
[self subclassResponsibility:_cmd]; [self subclassResponsibility:_cmd];
return nil; return nil;
} }
/* These sending and receiving interfaces will change */ - (BOOL) sendPacket: packet withTimeout: (int)milliseconds
- (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
{ {
[self subclassResponsibility:_cmd]; [self subclassResponsibility:_cmd];
return NO; 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]; [super initWithCapacity: c];
return 0; reply_port = p;
return self;
} }
- (void) encodeWithCoder: (id <Encoding>)anEncoder - replyPort
{ {
[super encodeWithCoder:anEncoder]; return reply_port;
} }
@end @end

View file

@ -1,8 +1,8 @@
/* Interface for abstract superclass port for use with Connection /* 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 <mccallum@gnu.ai.mit.edu> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: July 1994 Created: July 1994
This file is part of the GNU Objective C Class Library. This file is part of the GNU Objective C Class Library.
@ -25,37 +25,60 @@
#define __Port_h_OBJECTS_INCLUDE #define __Port_h_OBJECTS_INCLUDE
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/RetainingNotifier.h>
#include <objects/Coding.h> #include <objects/Coding.h>
#include <objects/MemoryStream.h>
#include <objects/NSString.h> #include <objects/NSString.h>
@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 */ - (Class) packetClass;
+ newRegisteredPortWithName: (id <String>)n;
+ newPortFromRegisterWithName: (id <String>)n onHost: (id <String>)host;
+ newPort;
/* 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 @interface InPort : Port
fromPort: (Port**) remote;
- (int) receivePacket: (char*)b length: (int)l
fromPort: (Port**) remote
timeout: (int) milliseconds;
- (BOOL) isSoft; + newForReceiving;
+ newForReceivingFromRegisteredName: (id <String>)name;
- (unsigned) hash; /* Get a packet from the net and return it. If no packet is received
- (BOOL) isEqual: anotherPort; within MILLISECONDS, then return nil. The caller is responsible
for releasing the packet. */
- receivePacketWithTimeout: (int)milliseconds;
@end
@interface OutPort : Port
+ newForSendingToRegisteredName: (id <String>)name
onHost: (id <String>)hostname;
- (BOOL) sendPacket: packet withTimeout: (int)milliseconds;
@end
extern NSString *PortBecameInvalidNotification;
@interface Packet : MemoryStream
{
id reply_port;
}
- initForSendingWithCapacity: (unsigned)c
replyPort: p;
- replyPort;
@end @end