home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / comm / amitcp-3.0ß2.lha / AmiTCP / src / amitcp / api / auto_socket.c < prev    next >
Text File  |  1994-02-28  |  46KB  |  1,140 lines

  1. /****** bsdsocket.library/accept ********************************************
  2. *
  3. *   NAME
  4. *        accept - accept a connection on a socket
  5. *
  6. *   SYNOPSIS
  7. *        #include <sys/types.h>
  8. *        #include <sys/socket.h>
  9. *
  10. *        ns = accept(s, addr, addrlen)
  11. *        D0          D0 A0    A1
  12. *
  13. *        long accept(long, struct sockaddr *, long *);
  14. *
  15. *   FUNCTION
  16.  
  17. *        The  argument  s  is a  socket  that  has  been created with
  18. *        socket(), bound to an  address  with bind(), and  is listen-
  19. *        ing for connections after a listen().  accept() extracts the
  20. *        first  connection  on  the  queue  of  pending  connections,
  21. *        creates a new socket with the same properties of s and allo-
  22. *        cates a new socket descriptor for the socket.  If no pending
  23. *        connections are present on the  queue, and the socket is not
  24. *        marked  as non-blocking, accept() blocks the caller  until a
  25. *        connection is present.  If the socket is marked non-blocking
  26. *        and  no  pending  connections  are  present  on  the  queue,
  27. *        accept() returns  an error as described below.  The accepted
  28. *        socket is used to read and write data to and from the socket
  29. *        which connected to  this one; it is not used to  accept more
  30. *        connections.  The original socket s remains open for accept-
  31. *        ing further connections.
  32. *
  33. *        The argument addr is a result parameter that  is  filled  in
  34. *        with  the  address of the connecting entity, as known to the
  35. *        communications layer.  The exact format of the addr  parame-
  36. *        ter  is  determined by the domain in which the communication
  37. *        is occurring.  The addrlen is a value-result  parameter;  it
  38. *        should  initially  contain the amount of space pointed to by
  39. *        addr; on return it will contain the actual length (in bytes)
  40. *        of   the   address   returned.    This  call  is  used  with
  41. *        connection-based socket types, currently with SOCK_STREAM.
  42. *
  43. *        It is possible to select() a socket  for  the  purposes  of
  44. *        doing an accept() by selecting it for read.
  45. *
  46. *   RETURN VALUES
  47. *        accept() returns a non-negative descriptor for the  accepted
  48. *        socket on success.  On failure, it returns -1 and sets errno
  49. *        to indicate the error.
  50. *
  51. *   ERRORS
  52. *        EBADF        - The descriptor is invalid.
  53. *
  54. *        EINTR        - The operation was interrupted by a break 
  55. *                       signal.
  56. *        EOPNOTSUPP   - The referenced socket is not of type
  57. *                       SOCK_STREAM.
  58. *
  59. *        EWOULDBLOCK  - The socket is marked non-blocking and no con-
  60. *                       nections are present to be accepted.
  61. *
  62. *   SEE ALSO
  63. *        bind(), connect(), listen(), select(), SetSocketSignals(),
  64. *        socket()
  65. *****************************************************************************
  66. *
  67. */
  68.  
  69. /****** bsdsocket.library/bind **********************************************
  70. *
  71. *   NAME
  72. *        bind - bind a name to a socket
  73. *
  74. *   SYNOPSIS
  75. *        #include <sys/types.h>
  76. *        #include <sys/socket.h>
  77. *
  78. *        success = bind(s, name, namelen)
  79. *        D0             D0 A0    D1
  80. *
  81. *        long bind(long, struct sockaddr *, long);
  82. *
  83. *   FUNCTION
  84. *        bind() assigns a name to an unnamed socket.  When  a  socket
  85. *        is created with socket(2) it exists in a name space (address
  86. *        family) but has no name assigned.  bind() requests that  the
  87. *        name pointed to by name be assigned to the socket.
  88. *
  89. *   RETURN VALUES
  90. *        0  - on success.
  91. *
  92. *        -1 - on failure and sets errno to indicate the error.
  93. *
  94. *   ERRORS
  95. *        EACCES            - The requested address is protected,  and
  96. *                            the  current user has inadequate permis-
  97. *                            sion to access it.
  98. *
  99. *        EADDRINUSE        - The specified address is already in use.
  100. *
  101. *        EADDRNOTAVAIL     - The specified address is  not  available
  102. *                            from the local machine.
  103. *
  104. *        EBADF             - s is not a valid descriptor.
  105. *
  106. *        EINVAL            - namelen is  not  the  size  of  a  valid
  107. *                            address  for  the specified address fam-
  108. *                            ily.
  109. *
  110. *                            The  socket  is  already  bound  to   an
  111. *                            address.
  112. *
  113. *   SEE ALSO
  114. *        connect(), getsockname(), listen(), socket()
  115. *
  116. *   NOTES
  117. *        The rules used in name binding  vary  between  communication
  118. *        domains.
  119. *****************************************************************************
  120. *
  121. */
  122.  
  123.  
  124. /****** bsdsocket.library/CloseSocket ***************************************
  125. *
  126. *   NAME
  127. *        CloseSocket - delete a socket descriptor
  128. *
  129. *   SYNOPSIS
  130. *        success = CloseSocket(s)
  131. *        D0                    D0
  132. *
  133. *        long CloseSocket(long);
  134. *
  135. *   FUNCTION 
  136. *        CloseSocket() deletes  a  descriptor  from the  library base
  137. *        socket reference table.   If s is the last reference  to the
  138. *        underlying object, then the object  will  be deactivated and
  139. *        socket  (see socket()),  associated naming  information  and
  140. *        queued data are discarded.
  141. *
  142. *        All sockets are automatically closed when the socket library
  143. *        is closed, but closing sockets as soon as possible is
  144. *        recommended to save system resources.
  145. *
  146. *   RETURN VALUES
  147. *         0   on success.
  148. *
  149. *        -1   on failure and sets errno to indicate the error.
  150. *
  151. *   ERRORS
  152. *        EBADF             - s is not an active socket descriptor.
  153. *
  154. *        EINTR             - linger on close was interrupted.
  155. *                            The socket is closed, however.
  156. *
  157. *   SEE ALSO
  158. *        accept(), SocketBaseTagList(), shutdown(), socket(),
  159. *        exec.library/CloseLibrary()
  160. *****************************************************************************
  161. *
  162. */
  163.  
  164.  
  165.  
  166. /****** bsdsocket.library/connect *******************************************
  167. *
  168. *   NAME
  169. *        connect - initiate a connection on a socket
  170. *   
  171. *   SYNOPSIS
  172. *        #include <sys/types.h>
  173. *        #include <sys/socket.h>
  174. *   
  175. *        success = connect(s, name, namelen)
  176. *        D0                D0 A0    D1
  177. *   
  178. *        long connect(long, struct sockaddr *, long);
  179. *   
  180. *   FUNCTION
  181. *        The parameter s is a socket.  If it  is of  type SOCK_DGRAM,
  182. *        then  this call specifies the peer with which the  socket is
  183. *        to be associated;  this address  is that  to which datagrams
  184. *        are  to be sent, and  the only address from which  datagrams
  185. *        are to be received.  If it is of type SOCK_STREAM, then this
  186. *        call attempts  to make a connection  to another socket.  The
  187. *        other socket is specified by name which is an address in the
  188. *        communications space of  the  socket.   Each  communications
  189. *        space interprets the  name parameter in  its  own way.  Gen-
  190. *        erally, stream sockets may successfully connect() only once;
  191. *        datagram sockets may use connect() multiple  times to change
  192. *        their association.  Datagram sockets may dissolve the  asso-
  193. *        ciation by connecting to  an invalid address, such as a null
  194. *        address.
  195. *   
  196. *   RETURN VALUES
  197. *         0   on success.
  198. *   
  199. *        -1   on failure and sets errno to indicate the error.
  200. *   
  201. *   ERRORS
  202. *        EADDRINUSE        - The address is already in use.
  203. *   
  204. *        EADDRNOTAVAIL     - The specified address is  not  available
  205. *                            on the remote machine.
  206. *   
  207. *        EAFNOSUPPORT      - Addresses in the specified address  fam-
  208. *                            ily cannot be used with this socket.
  209. *   
  210. *        EALREADY          - The socket is non-blocking and a  previ-
  211. *                            ous  connection attempt has not yet been
  212. *                            completed.
  213. *   
  214. *        EBADF             - s is not a valid descriptor.
  215. *   
  216. *        ECONNREFUSED      - The attempt to  connect  was  forcefully
  217. *                            rejected.   The  calling  program should
  218. *                            CloseSocket() the socket descriptor, and
  219. *