mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 17:10:48 +00:00
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:
parent
c2d70ec345
commit
65fd114c58
3 changed files with 196 additions and 92 deletions
|
@ -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 <mccallum@gnu.ai.mit.edu>
|
||||
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 <objects/stdobjects.h>
|
||||
#include <objects/RetainingNotifier.h>
|
||||
#include <objects/Coding.h>
|
||||
#include <objects/MemoryStream.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 */
|
||||
+ newRegisteredPortWithName: (id <String>)n;
|
||||
+ newPortFromRegisterWithName: (id <String>)n onHost: (id <String>)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 <String>)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 <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
|
||||
|
||||
|
|
150
Source/Port.m
150
Source/Port.m
|
@ -2,7 +2,7 @@
|
|||
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
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.
|
||||
|
||||
|
@ -26,75 +26,133 @@
|
|||
|
||||
@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];
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ newPortFromRegisterWithName: (id <String>)n onHost: (id <String>)host
|
||||
+ newForReceiving
|
||||
{
|
||||
return [self newForReceivingFromRegisteredName: nil];
|
||||
}
|
||||
|
||||
- receivePacketWithTimeout: (int)milliseconds
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ newPort
|
||||
@end
|
||||
|
||||
|
||||
@implementation OutPort
|
||||
|
||||
+ newForSendingToRegisteredName: (id <String>)name
|
||||
onHost: (id <String>)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 <Encoding>)anEncoder
|
||||
- replyPort
|
||||
{
|
||||
[super encodeWithCoder:anEncoder];
|
||||
return reply_port;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -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 <mccallum@gnu.ai.mit.edu>
|
||||
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 <objects/stdobjects.h>
|
||||
#include <objects/RetainingNotifier.h>
|
||||
#include <objects/Coding.h>
|
||||
#include <objects/MemoryStream.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 */
|
||||
+ newRegisteredPortWithName: (id <String>)n;
|
||||
+ newPortFromRegisterWithName: (id <String>)n onHost: (id <String>)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 <String>)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 <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
|
||||
|
||||
|
|
Loading…
Reference in a new issue