PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mosmllib/Socket.sig

https://github.com/bluegnu/mosml
Unknown | 292 lines | 230 code | 62 blank | 0 comment | 0 complexity | 69a45656bd2af4ad408afcbc069d95c7 MD5 | raw file
Possible License(s): GPL-2.0
  1. (* Socket -- SML Basis Library -- requires Dynlib *)
  2. type ('addressfam, 'socktype) sock
  3. type 'addressfam sock_addr
  4. (* Socket types *)
  5. type dgram (* A datagram socket *)
  6. type 'a stream (* A stream socket *)
  7. type passive (* A passive stream *)
  8. type active (* An active, connected, stream *)
  9. (* Socket protocol families *)
  10. type pf_file (* The Unix file protocol family *)
  11. type pf_inet (* The Internet protocol family *)
  12. (* Address constructors *)
  13. val fileAddr : string -> pf_file sock_addr
  14. val inetAddr : string -> int -> pf_inet sock_addr
  15. (* Socket constructors *)
  16. val fileStream : unit -> (pf_file, 'a stream) sock
  17. val fileDgram : unit -> (pf_file, dgram) sock
  18. val inetStream : unit -> (pf_inet, 'a stream) sock
  19. val inetDgram : unit -> (pf_inet, dgram) sock
  20. val accept : ('a, passive stream) sock
  21. -> ('a, active stream) sock * 'a sock_addr
  22. val bind : ('a, 'b) sock * 'a sock_addr -> unit
  23. val connect : ('a, 'b) sock * 'a sock_addr -> unit
  24. val listen : ('a, passive stream) sock * int -> unit
  25. val close : ('a, 'b) sock -> unit
  26. (* Socket management *)
  27. datatype shutdown_mode =
  28. NO_RECVS (* No further receives *)
  29. | NO_SENDS (* No further sends *)
  30. | NO_RECVS_OR_SENDS (* No receives nor sends *)
  31. val shutdown : ('a, 'b stream) sock * shutdown_mode -> unit
  32. type sock_desc
  33. val sockDesc : ('a, 'b) sock -> sock_desc
  34. val sameDesc : sock_desc * sock_desc -> bool
  35. val compare : sock_desc * sock_desc -> order
  36. val select :
  37. { rds : sock_desc list, wrs : sock_desc list, exs : sock_desc list,
  38. timeout : Time.time option }
  39. -> { rds : sock_desc list, wrs : sock_desc list, exs : sock_desc list }
  40. val getinetaddr : pf_inet sock_addr -> string
  41. (* Sock I/O option types *)
  42. type out_flags = { don't_route : bool, oob : bool }
  43. type in_flags = { peek : bool, oob : bool }
  44. type 'a buf = { buf : 'a, ofs : int, size : int option }
  45. (* Socket output operations *)
  46. val sendVec : ('a, active stream) sock * Word8Vector.vector buf -> int
  47. val sendArr : ('a, active stream) sock * Word8Array.array buf -> int
  48. val sendVec' : ('a, active stream) sock * Word8Vector.vector buf
  49. * out_flags -> int
  50. val sendArr' : ('a, active stream) sock * Word8Array.array buf
  51. * out_flags -> int
  52. val sendVecTo : ('a, dgram) sock * 'a sock_addr * Word8Vector.vector buf
  53. -> int
  54. val sendArrTo : ('a, dgram) sock * 'a sock_addr * Word8Array.array buf
  55. -> int
  56. val sendVecTo' : ('a, dgram) sock * 'a sock_addr * Word8Vector.vector buf
  57. * out_flags -> int
  58. val sendArrTo' : ('a, dgram) sock * 'a sock_addr * Word8Array.array buf
  59. * out_flags -> int
  60. (* Socket input operations *)
  61. val recvVec : ('a, active stream) sock * int -> Word8Vector.vector
  62. val recvArr : ('a, active stream) sock * Word8Array.array buf -> int
  63. val recvVec' : ('a, active stream) sock * int * in_flags
  64. -> Word8Vector.vector
  65. val recvArr' : ('a, active stream) sock * Word8Array.array buf * in_flags
  66. -> int
  67. val recvVecFrom : ('a, dgram) sock * int
  68. -> Word8Vector.vector * 'a sock_addr
  69. val recvArrFrom : ('a, dgram) sock * Word8Array.array buf
  70. -> int * 'a sock_addr
  71. val recvVecFrom' : ('a, dgram) sock * int * in_flags
  72. -> Word8Vector.vector * 'a sock_addr
  73. val recvArrFrom' : ('a, dgram) sock * Word8Array.array buf * in_flags
  74. -> int * 'a sock_addr
  75. (*
  76. Structure Socket defines functions for creating and using sockets,
  77. a means for communication between SML processes on the same machine
  78. or via a network.
  79. [('addressfam, 'socktype) sock] is the type of sockets with address
  80. family 'addressfam and having type 'socktype.
  81. ['addressfam sock_addr] is the type of sockets addresses.
  82. The possible address (protocol) families are
  83. type pf_file The Unix address family (file)
  84. type pf_inet The Internet address family
  85. The possible socket types are
  86. type dgram datagram sockets
  87. type 'a stream stream sockets
  88. type passive passive stream sockets
  89. type active active, or connected, stream sockets
  90. [fileAddr fname] returns a socket address for the Unix protocol
  91. family, created from the given file name fname.
  92. [inetAddr inetaddr portno] returns a socket address for the
  93. Internet protocol family, created from the given Internet number
  94. (e.g. "130.225.40.253") and port number (e.g. 8080).
  95. [fileStream ()] returns a new stream socket for the Unix protocol
  96. family.
  97. [fileDgram ()] returns a new datagram socket for the Unix protocol
  98. family.
  99. [inetStream ()] returns a new stream socket for the Internet
  100. protocol family.
  101. [inetDgram ()] returns a new datagram socket for the Internet
  102. protocol family.
  103. [accept sock] extracts the first connection on the queue of pending
  104. connections to sock. Returns (sock', addr) where sock' is a copy
  105. of the socket sock, bound to that connection, and addr is the
  106. address of the communications counterpart (the other end of the
  107. connection). Blocks if no connections are pending. The stream
  108. socket sock must have been assigned a name (with bind) and must be
  109. listening for connections (following a call to listen).
  110. [bind sock addr] binds the socket sock to the address addr, that
  111. is, assigns the name addr to the socket. Binding a name in the
  112. Unix protocol family creates a socket in the file system that must
  113. be deleted when it is no longer needed
  114. [connect (sock, addr)] attempts to connect socket sock to the
  115. communications peer at address addr. If sock is a datagram socket,
  116. then addr is the address to which datagrams is to be sent, and the
  117. only address from which datagrams will be accepted. If sock is a
  118. stream socket, then addr specifies another socket to which to
  119. connect.
  120. [listen (sock, queuelen)] enables the passive stream socket sock to
  121. accept incoming connections. The parameter queuelen specifies the
  122. maximal number of pending connections. Further connections from
  123. clients may be refused when this limit is reached.
  124. [close sock] closes the socket.
  125. [shutdown sock shutdown_mode] shuts down socket sock for further
  126. communication, as specified by the shutdown_mode parameter:
  127. [NO_RECVS] no further receives are allowed;
  128. [NO_SENDS] no further sends are allowed;
  129. [NO_RECVS_OR_SENDS] no further receives or sends are allowed.
  130. [getinetaddr addr] returns the Internet number
  131. (e.g. "130.225.40.253") of the Internet socket address addr.
  132. ['a buf] is the type of records { buf, ofs, size } which represent
  133. subvectors or subarrays:
  134. if size = SOME s it represents buf[ofs..ofs+s-1];
  135. if size = NONE it represents buf[ofs..len-1] where len is buf's length.
  136. When the subbuffer is used in a call, exception Subscript will be raised
  137. if ofs < 0 or size < 0 or ofs+size > len.
  138. [sendVec (sock, vecbuf)] transmits the bytes from buffer vecbuf on
  139. the active stream socket sock. Returns the number of bytes sent.
  140. Blocks until sufficient space is available at the socket.
  141. [sendArr (sock, arrbuf)] is analogous til sendVec.
  142. [sendVec' (sock, vecbuf, out_flags)] transmits the bytes from
  143. buffer vecbuf on the active stream socket sock, observing the
  144. out_flags. Returns the number of bytes sent. Blocks until
  145. sufficient space is available at the socket.
  146. [out_flags] is the type of records { don't_route, oob } in which
  147. the field don't_route specifies whether routing should be bypassed,
  148. and the field oob specifies whether data should be sent out-of-band.
  149. [sendArr' (sock, arrbuf, out_flags)] is analogous til sendVec'.
  150. [sendVecTo (sock, addr, vecbuf)] transmits the bytes from buffer
  151. vecbuf on the datagram socket sock to the target address addr.
  152. Returns the number of bytes sent. Blocks until sufficient space is
  153. available at the socket.
  154. [sendArrTo (sock, addr, arrbuf)] is analogous til sendVecTo.
  155. [sendVecTo' (sock, addr, vecbuf, out_flags)] transmits the bytes
  156. from buffer vecbuf on the datagram socket sock to the target
  157. address addr, observing the out_flags. Returns the number of bytes
  158. sent. Blocks until sufficient space is available at the socket.
  159. See above for a description of vecbuf and out_flags.
  160. [sendArrTo' (sock, addr, arrbuf, out_flags)] is analogous til sendVecTo'.
  161. [recvVec (sock, n)] receives up to n bytes from the active stream
  162. socket sock. Returns a byte vector containing the bytes actually
  163. received. Blocks until some data become available at the socket,
  164. then returns any available data, up to n bytes. Excess data are
  165. not lost; they are available for subsequent receive calls.
  166. [recvArr (sock, arrbuf)] receives bytes from the active stream
  167. socket sock into the subarray arrbuf, up to the available space.
  168. If #size(arrbuf) = SOME(s) the available space is s bytes; if
  169. #size(arrbuf) = NONE the available space is len - #ofs(arrbuf)
  170. bytes. Returns the number of bytes actually received. Blocks
  171. until some data become available at the socket. Excess data are
  172. not lost; they are available for subsequent receive calls.
  173. [recvVec' (sock, n, in_flags)] receives up to n bytes from the
  174. active stream socket sock, observing the in_flags. Returns a byte
  175. vector containing the bytes actually received. Blocks until some
  176. data become available at the socket, then returns any available
  177. data, up to n bytes. Data in excess of n bytes are not lost; they
  178. are available for subsequent receive calls.
  179. [in_flags] is the type of records { peek, oob } in which the field
  180. peek specifies that the data read should not be removed from the
  181. receive queue, and the field oob specifies that data may be
  182. received out-of-band.
  183. [recvArr' (sock, arrbuf, in_flags)] receives bytes from the active
  184. stream socket sock into the subarray arrbuf, observing the
  185. in_flags, up to the available space.. Returns the number of bytes
  186. actually received. Blocks until some data become available at the
  187. socket. Excess data are not lost; they are available for
  188. subsequent receive calls.
  189. [recvVecFrom (sock, n)] receives up to n bytes from the datagram
  190. socket sock. Returns a byte vector containing the bytes actually
  191. received. Blocks until some data become available at the socket,
  192. then returns any available data, up to n bytes.
  193. [recvArrFrom (sock, arrbuf)] receives bytes from the datagram
  194. socket sock into the subarray arrbuf. Returns the number of bytes
  195. actually received. Blocks until some data become available at the
  196. socket.
  197. [recvVecFrom' (sock, n, in_flags)] receives up to n bytes from the
  198. datagram socket sock, observing the in_flags (see above). Returns
  199. (vec, addr) where vec is a byte vector containing the bytes
  200. actually received, and addr is the source address of the message.
  201. Blocks until some data become available at the socket, then returns
  202. any available data, up to n bytes.
  203. [recvArrFrom' (sock, arrbuf, in_flags)] receives bytes from the
  204. datagram socket sock into the array buffer arrbuf, observing the
  205. in_flags (see above). Returns (n, addr) where n is the number of
  206. bytes actually received, and addr is the source address of the
  207. message. Blocks until some data become available at the socket.
  208. [sockDesc sock] returns a descriptor for the socket sock, to be
  209. used in a call to select.
  210. [compare (sd1, sd2)] compares sd1 and sd2 according to an
  211. unspecified total ordering, and returns LESS if sd1 precedes sd2,
  212. returns GREATER is sd1 precedes sd2, and returns EQUAL otherwise.
  213. [sameDesc (sd1, sd2)] returns true if sd1 and sd2 describe the same
  214. socket. Equivalent to compare(sd1, sd2) = EQUAL.
  215. [select { rds, wrs, exs, timeout }] blocks the calling process
  216. until some input/output operations become possible on some sockets.
  217. The call will check the sockets described in rds for reading, those
  218. in wrs for writing, and those in exs for exceptional conditions.
  219. Returns { rds, wrs, exs } where rds now is a list of descriptors of
  220. sockets ready for reading, wrs are ready for writing, and exs have
  221. exceptional conditions. The order of the socket descriptors in the
  222. results is the same as their order in the corresponding arguments.
  223. If timeout is NONE then the call blocks until some input/output
  224. operations become possible; if timeout is SOME(t) then the call
  225. blocks for at most time t.
  226. A server socket is considered ready for reading if there is a
  227. pending connection which can be accepted with `accept'. A client
  228. socket is ready for writing when its connection is fully
  229. established.
  230. *)