home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / Foundation / TCPTransport / TCPPort.h < prev    next >
Text File  |  1996-04-17  |  3KB  |  81 lines

  1. /* TCPPort.h created by blaine on Wed 03-Apr-1996
  2.    Copyright 1996, NeXT Computer, Inc.
  3.    Blaine Garst
  4.    Marc Majka
  5.  */
  6.  
  7. /*
  8.  * The Distributed Objects subsystem within Foundation allows one to
  9.  * substitute a different transport in place of the standard mach IPC
  10.  * (either direct or emulated).
  11.  * The transport takes the form of an alternate concrete NSPort subclass
  12.  * implementation.  This is an example of such a beast, hopefully to
  13.  * serve not as a direct replacement but as a starting point for other
  14.  * work.  Its chief drawbacks over the mach IPC nmserver are:
  15.  *    - no security: intramachine objects are all net visible
  16.  *    - no multiplexing: when you run out of sockets... poof!
  17.  *    - no nameservice: there is no broadcast lookup
  18.  * These all must be solved to be as good as the mach IPC transport.
  19.  */
  20.  
  21.  
  22. #import <Foundation/Foundation.h>
  23. #import "DataStream.h"
  24.  
  25.  
  26. /* TCPPort - a concrete port implementation based on TCP ports.
  27.  * A TCP port is in the range of unsigned shorts.  A port that is
  28.  * advertised for connect()ions does not receive any data directly.
  29.  * Instead, a per-connect()ion port is built and used as the sendPort
  30.  * of NSConnections.  Thus, the TCP port number is used as a rendezvous
  31.  * point and not for any data transmission.
  32.  * There is a race, however, if two parties both do connect()s at the
  33.  * same time.  This results in having two TCP circuits for a single
  34.  * connection between two peers.  Both parties will write on only one
  35.  * of these circuits, however, so there is no ordering problem.  Both
  36.  * parties must read() on the connect()ed socket until an accept()ed
  37.  * socket shows up.
  38.  */
  39.  
  40. /* PLEASE NOTE that DO is thread-safe and so should this class! */
  41.  
  42.  
  43. @interface TCPPort : NSPort {
  44.     id readWriter;    // the connect()ed one
  45.     id reader;    // the accept()ed one
  46.     id delegate;
  47.     TCPPort *listener;
  48.     NSConnection *connection;    // needs to be held until first message processed
  49.     NSCountedSet *modes;
  50.     unsigned long internetAddr;
  51.     unsigned int refCount;
  52.     unsigned short tcpPort;
  53.     BOOL isDying;
  54.     BOOL invalid;
  55.     /* partial portMessage assembly */
  56.     int partialState;
  57.     DataStream *dataStream;
  58.     unsigned int dataLength;
  59.     NSMutableData *dataItem;
  60.     NSMutableArray *items;
  61.     unsigned int nItems;
  62.     unsigned int itemCounter;
  63.     unsigned int itemType;
  64. }
  65.  
  66. - (TCPPort *)initWithNumber:(unsigned short)p;
  67.   /* build a rendezvous port on a publishable number */
  68.  
  69. - (TCPPort *)connectToNumber:(unsigned short)p host:(NSString *)hostname;
  70. - (TCPPort *)connectToNumber:(unsigned short)p address:(unsigned long)addr;
  71.    /* given a port that you are listening on, connect to another.  This
  72.       builds a TCP port connected to the other end suitable for DO
  73.       communication.  There is a race here, so this code must resolve who
  74.       should win if both ends connect to each other at the same time.
  75.     */
  76.  
  77. + (void)_toggleLogging;
  78.  
  79.  
  80. @end
  81.