home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / Level 0 Macintosh 29Sep94 / Network.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  5.6 KB  |  125 lines  |  [TEXT/KAHL]

  1. /* Network.h */
  2.  
  3. #ifndef Included_Network_h
  4. #define Included_Network_h
  5.  
  6. /* Network module depends on */
  7. /* MiscInfo.h */
  8. /* Audit */
  9. /* Debug */
  10. /* Definitions */
  11. /* Memory */
  12. /* EventLoop */
  13. /* Array */
  14.  
  15. /* this is the AppleTalk PPCToolBox version of the Network module */
  16.  
  17. /* ID number type of a network port being listened at */
  18. struct PortIDType;
  19. typedef struct PortIDType PortIDType;
  20.  
  21. /* ID number of a communications session */
  22. struct SessionIDType;
  23. typedef struct SessionIDType SessionIDType;
  24.  
  25. /* kind of network that you can ask for */
  26. typedef enum
  27.     {
  28.         eNetDefault EXECUTE(= -21234),
  29.         eNetAppleTalk,
  30.         eNetTCP
  31.     } NetworkTypes;
  32.  
  33. /* errors that can occur when dealing with ports */
  34. typedef enum
  35.     {
  36.         eNetNoError EXECUTE(= -9343),
  37.         eNetNoMemory, /* not enough memory to allocate a new port record */
  38.         eNetPortInUse, /* the port is already being used by another thing on the system */
  39.         eNetBadPortString, /* the port string is not valid for the network in use */
  40.         eNetBadMachineString, /* the machine name is not valid for this network */
  41.         eNetMachineUnknown, /* the machine could not be reached; connection timed out */
  42.         eNetNetworkNotAvailable, /* the network services are not available on machine */
  43.         eNetCouldntInitNet, /* the network could not be initialized */
  44.         eNetConnectRefused, /* connections was refused */
  45.         eNetProtocolNotSupported, /* they asked for an unsupported communication protocol */
  46.         eNetUnknownError /* who knows what went wrong */
  47.     } NetErrors;
  48.  
  49. /* events that can be returned from the network update function.  these are */
  50. /* NOT the same as those from EventLoop and should not be used. */
  51. typedef enum
  52.     {
  53.         eNetEventNone EXECUTE(= -412), /* nothing is happening right now */
  54.         eNetEventNewSession, /* new incoming session *SessionNumber has been established */
  55.         eNetEventSessionClosed, /* the session *SessionNumber has been closed by remote */
  56.         eNetEventDataIncoming, /* new data has arrived on session *SessionNumber */
  57.         eNetEventInternal /* there is more work to be done, so call back soon */
  58.     } NetEvents;
  59.  
  60. /* initialize the network interface.  the user calls this.  it is not called from */
  61. /* the standard Level 0 initialization routine because not all programs need */
  62. /* networking.  Could return eNetNoError, eNetNoMemory, eNetNetworkNotAvailable, */
  63. /* eNetCouldntInitNet, or eNetUnknownError */
  64. NetErrors                        InitializeNetwork(void);
  65.  
  66. /* discard any pending data, close any open connections, and clean internal data */
  67. void                                ShutdownNetwork(void);
  68.  
  69. /* Network update routine.  It handles periodic update tasks and should be called */
  70. /* frequently (preferably in the main event loop next to GetAnEvent). */
  71. NetEvents                        NetUpdate(SessionIDType** SessionNumber);
  72.  
  73. /* Listen at the specified port.  Returns the reference number of the port being */
  74. /* listened at.  PortString is a non-null-terminated heap block containing the string */
  75. /* identifying the port.  The port string format depends on the underlying network */
  76. /* scheme.  For instance, TCP/IP would be an integer between 128 and 9999. */
  77. /* for AppleTalk (NBP), it is a valid NBP name.  Could return eNetNoError, */
  78. /* eNetNoMemory, eNetPortInUse, eNetBadPortString, eNetUnknownError, or */
  79. /* eNetProtocolNotSupported. */
  80. NetErrors                        NetListenAtPort(char* PortString, PortIDType** PortOut,
  81.                                             NetworkTypes WhichNetwork);
  82.  
  83. /* Stop listening at a port and let the OS use it for someone else.  Sessions */
  84. /* established through this port are terminated. */
  85. void                                NetTerminatePortAndSessions(PortIDType* Port);
  86.  
  87. /* Open a session to another (or the same) machine.  Returns a session number in */
  88. /* *SessionOut.  PortString is the remote port to connect to, as described above, */
  89. /* and MachineString is a machine string determined by the network stack.  For */
  90. /* instance, TCP/IP would support standard a.b.c.d or machine.zone.domain format. */
  91. /* The Macintosh uses machine:type@zone.  Could return eNetNoError, eNetNoMemory, */
  92. /* eNetBadPortString, eNetBadMachineString, eNetMachineUnknown, eNetUnknownError, */
  93. /* eNetConnectRefused, or eNetProtocolNotSupported. */
  94. NetErrors                        NetOpenSession(char* PortString, char* MachineString,
  95.                                             SessionIDType** SessionOut, NetworkTypes WhichNetwork);
  96.  
  97. /* Close a session.  Any waiting data in either direction is discarded. */
  98. void                                NetCloseSession(SessionIDType* Session);
  99.  
  100. /* Verify that a session is still usable.  Returns True if the session is still */
  101. /* available, or False if the remote system disconnected it.  If it returns False, */
  102. /* then you should call NetCloseSession to dispose of the session record. */
  103. MyBoolean                        NetIsSessionStillAlive(SessionIDType* Session);
  104.  
  105. /* Obtain a string identifying the machine from which a session has been */
  106. /* established.  The string is a non-null-terminated heap block. */
  107. char*                                NetSessionGetRemoteMachineName(SessionIDType* Session);
  108.  
  109. /* Find out how much data is waiting to be read from the port. */
  110. long                                NetHowMuchDataToRead(SessionIDType* Session);
  111.  
  112. /* Find out how much data is waiting in local buffers to be written to a port. */
  113. long                                NetHowMuchDataToWrite(SessionIDType* Session);
  114.  
  115. /* Read data from a session.  It is an error to read more data than there is waiting. */
  116. void                                NetReadData(SessionIDType* Session, char* Buffer, long NumBytes);
  117.  
  118. /* Write data to a session.  If data could not be sent without blocking, then */
  119. /* it is locally buffered until it can be sent (that's what NetUpdate is for) */
  120. /* returns True if successful, or False if there isn't enough memory.  if it fails, */
  121. /* then NO data is written (i.e. data is never partially written) */
  122. MyBoolean                        NetWriteData(SessionIDType* Session, char* Buffer, long NumBytes);
  123.  
  124. #endif
  125.