([TcpInPort -numberOfConnectedOutPorts]): New method.

([TcpInPort -_connectedOutPortInvalidated:]): Post an
InPortClientBecameInvalidNotification.
([TcpInPort -portNumber]): New method.
([TcpInPort -description]): New method.
([TcpOutPort +newWithAcceptedSocket:inPort:]): Fill in the _address
ivar.
([TcpOutPort -portNumber]): New method.
([TcpOutPort -description]): New method.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1039 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Andrew McCallum 1996-03-03 00:40:46 +00:00
parent 272ac50286
commit 7d8460ea0e

View file

@ -28,6 +28,7 @@
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/TcpPort.h> #include <objects/TcpPort.h>
#include <objects/Array.h> #include <objects/Array.h>
#include <objects/Notification.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -188,6 +189,11 @@ static NSMapTable* port_number_2_port;
autorelease]; autorelease];
} }
- (unsigned) numberOfConnectedOutPorts
{
return NSCountMapTable (client_sock_2_out_port);
}
- receivePacketWithTimeout: (int)milliseconds - receivePacketWithTimeout: (int)milliseconds
{ {
static int fd_index = 0; static int fd_index = 0;
@ -311,6 +317,7 @@ static NSMapTable* port_number_2_port;
NSMapInsert (client_sock_2_out_port, (void*)s, p); NSMapInsert (client_sock_2_out_port, (void*)s, p);
} }
/* Called by an OutPort in its -invalidate method. */
- (void) _connectedOutPortInvalidated: p - (void) _connectedOutPortInvalidated: p
{ {
id packet; id packet;
@ -324,6 +331,13 @@ static NSMapTable* port_number_2_port;
} }
NSMapRemove (client_sock_2_out_port, (void*)s); NSMapRemove (client_sock_2_out_port, (void*)s);
FD_CLR(s, &active_fd_set); FD_CLR(s, &active_fd_set);
/* xxx Should this be earlier, so that the notification recievers
can still use client_sock_2_out_port before the out port P is removed? */
[NotificationDispatcher
postNotificationName: InPortClientBecameInvalidNotification
object: self
userInfo: p];
} }
- (int) _socket - (int) _socket
@ -331,6 +345,11 @@ static NSMapTable* port_number_2_port;
return _socket; return _socket;
} }
- (int) portNumber
{
return (int) ntohs (_address.sin_port);
}
- (void) invalidate - (void) invalidate
{ {
if (is_valid) if (is_valid)
@ -341,6 +360,7 @@ static NSMapTable* port_number_2_port;
int sock; int sock;
id out_ports[count]; id out_ports[count];
int i; int i;
for (i = 0; for (i = 0;
NSNextMapEnumeratorPair (&me, (void*)&sock, (void*)&out_port); NSNextMapEnumeratorPair (&me, (void*)&sock, (void*)&out_port);
i++) i++)
@ -351,7 +371,10 @@ static NSMapTable* port_number_2_port;
[out_ports[i] invalidate]; [out_ports[i] invalidate];
} }
assert (!NSCountMapTable (client_sock_2_out_port)); assert (!NSCountMapTable (client_sock_2_out_port));
close (_socket); close (_socket);
/* This also posts a PortBecameInvalidNotification. */
[super invalidate]; [super invalidate];
} }
} }
@ -384,6 +407,15 @@ static NSMapTable* port_number_2_port;
return [TcpPacket class]; return [TcpPacket class];
} }
- description
{
return [NSString stringWithFormat: @"%s 0x%x port %hd socket %d",
object_get_class_name (self),
(unsigned)self,
ntohs (_address.sin_port),
_socket];
}
@end @end
@ -465,7 +497,19 @@ static NSMapTable* port_number_2_port;
+ newWithAcceptedSocket: (int)s inPort: p + newWithAcceptedSocket: (int)s inPort: p
{ {
return [[self alloc] _initWithSocket: s inPort: p]; TcpOutPort *op;
struct sockaddr_in addr;
int size = sizeof (struct sockaddr_in);
/* Create the port object. */
op = [[self alloc] _initWithSocket: s inPort: p];
/* Fill in its _address ivar. */
getsockname (op->_socket, (struct sockaddr*)&addr, &size);
assert (size == sizeof (struct sockaddr_in));
memcpy (&(op->_address), &addr, sizeof (struct sockaddr_in));
return op;
} }
- (int) writeBytes: (const char*)b length: (int)len - (int) writeBytes: (const char*)b length: (int)len
@ -497,6 +541,11 @@ static NSMapTable* port_number_2_port;
return _socket; return _socket;
} }
- (int) portNumber
{
return (int) ntohs (_address.sin_port);
}
- (void) close - (void) close
{ {
[self invalidate]; [self invalidate];
@ -511,6 +560,7 @@ static NSMapTable* port_number_2_port;
[connected_in_port _connectedOutPortInvalidated: self]; [connected_in_port _connectedOutPortInvalidated: self];
[connected_in_port release]; [connected_in_port release];
connected_in_port = nil; connected_in_port = nil;
/* This also posts a PortBecameInvalidNotification. */
[super invalidate]; [super invalidate];
} }
} }
@ -534,6 +584,16 @@ static NSMapTable* port_number_2_port;
return [TcpPacket class]; return [TcpPacket class];
} }
- description
{
return [NSString stringWithFormat: @"%s 0x%x host %s port %hd socket %d",
object_get_class_name (self),
(unsigned)self,
inet_ntoa (_address.sin_addr),
ntohs (_address.sin_port),
_socket];
}
@end @end
@ -630,3 +690,9 @@ static NSMapTable* port_number_2_port;
@end @end
/* Notification Strings. */
NSString *
InPortClientBecameInvalidNotification =
@"InPortClientBecameInvalidNotification";