PageRenderTime 76ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/src/doc/helpsigs/htmlsigs/Socket.html

https://github.com/bluegnu/mosml
HTML | 306 lines | 261 code | 45 blank | 0 comment | 0 complexity | b76bec41d45d2b64f1ae8c253f517e37 MD5 | raw file
Possible License(s): GPL-2.0
  1. <HTML><HEAD><TITLE>Structure Socket</TITLE></HEAD>
  2. <BODY BGCOLOR="#fbf2e7">
  3. <H1>Structure Socket</H1>
  4. <HR><TABLE WIDTH=100%><TR ALIGN = CENTER>
  5. <TH><A HREF="idIndex.html">Identifier index</A>
  6. <TH><A HREF="index.html">Structure index</A>
  7. </TABLE><HR>
  8. <PRE>
  9. <A NAME="line0"></A>(* Socket -- SML Basis Library -- requires Dynlib *)
  10. <A NAME="line1"></A>
  11. <A NAME="line2"></A>type ('addressfam, 'socktype) <A HREF="#sock-typ">sock</A>
  12. <A NAME="line3"></A>type 'addressfam <A HREF="#sock_addr-typ">sock_addr</A>
  13. <A NAME="line4"></A>
  14. <A NAME="line5"></A>(* Socket types *)
  15. <A NAME="line6"></A>type dgram (* A datagram socket *)
  16. <A NAME="line7"></A>type 'a stream (* A stream socket *)
  17. <A NAME="line8"></A>type passive (* A passive stream *)
  18. <A NAME="line9"></A>type active (* An active, connected, stream *)
  19. <A NAME="line10"></A>
  20. <A NAME="line11"></A>(* Socket protocol families *)
  21. <A NAME="line12"></A>type pf_file (* The Unix file protocol family *)
  22. <A NAME="line13"></A>type pf_inet (* The Internet protocol family *)
  23. <A NAME="line14"></A>
  24. <A NAME="line15"></A>(* Address constructors *)
  25. <A NAME="line16"></A>val <A HREF="#fileAddr-val">fileAddr</A> : string -&gt; pf_file sock_addr
  26. <A NAME="line17"></A>val <A HREF="#inetAddr-val">inetAddr</A> : string -&gt; int -&gt; pf_inet sock_addr
  27. <A NAME="line18"></A>
  28. <A NAME="line19"></A>(* Socket constructors *)
  29. <A NAME="line20"></A>val <A HREF="#fileStream-val">fileStream</A> : unit -&gt; (pf_file, 'a stream) sock
  30. <A NAME="line21"></A>val <A HREF="#fileDgram-val">fileDgram</A> : unit -&gt; (pf_file, dgram) sock
  31. <A NAME="line22"></A>val <A HREF="#inetStream-val">inetStream</A> : unit -&gt; (pf_inet, 'a stream) sock
  32. <A NAME="line23"></A>val <A HREF="#inetDgram-val">inetDgram</A> : unit -&gt; (pf_inet, dgram) sock
  33. <A NAME="line24"></A>
  34. <A NAME="line25"></A>val <A HREF="#accept-val">accept</A> : ('a, passive stream) sock
  35. <A NAME="line26"></A> -&gt; ('a, active stream) sock * 'a sock_addr
  36. <A NAME="line27"></A>val <A HREF="#bind-val">bind</A> : ('a, 'b) sock * 'a sock_addr -&gt; unit
  37. <A NAME="line28"></A>val <A HREF="#connect-val">connect</A> : ('a, 'b) sock * 'a sock_addr -&gt; unit
  38. <A NAME="line29"></A>val <A HREF="#listen-val">listen</A> : ('a, passive stream) sock * int -&gt; unit
  39. <A NAME="line30"></A>val <A HREF="#close-val">close</A> : ('a, 'b) sock -&gt; unit
  40. <A NAME="line31"></A>
  41. <A NAME="line32"></A>(* Socket management *)
  42. <A NAME="line33"></A>datatype shutdown_mode =
  43. <A NAME="line34"></A> NO_RECVS (* No further receives *)
  44. <A NAME="line35"></A> | NO_SENDS (* No further sends *)
  45. <A NAME="line36"></A> | NO_RECVS_OR_SENDS (* No receives nor sends *)
  46. <A NAME="line37"></A>
  47. <A NAME="line38"></A>val <A HREF="#shutdown-val">shutdown</A> : ('a, 'b stream) sock * shutdown_mode -&gt; unit
  48. <A NAME="line39"></A>
  49. <A NAME="line40"></A>type sock_desc
  50. <A NAME="line41"></A>
  51. <A NAME="line42"></A>val <A HREF="#sockDesc-val">sockDesc</A> : ('a, 'b) sock -&gt; sock_desc
  52. <A NAME="line43"></A>val <A HREF="#sameDesc-val">sameDesc</A> : sock_desc * sock_desc -&gt; bool
  53. <A NAME="line44"></A>val <A HREF="#compare-val">compare</A> : sock_desc * sock_desc -&gt; order
  54. <A NAME="line45"></A>val <A HREF="#select-val">select</A> :
  55. <A NAME="line46"></A> { rds : sock_desc list, wrs : sock_desc list, exs : sock_desc list,
  56. <A NAME="line47"></A> timeout : Time.time option }
  57. <A NAME="line48"></A> -&gt; { rds : sock_desc list, wrs : sock_desc list, exs : sock_desc list }
  58. <A NAME="line49"></A>
  59. <A NAME="line50"></A>val <A HREF="#getinetaddr-val">getinetaddr</A> : pf_inet sock_addr -&gt; string
  60. <A NAME="line51"></A>
  61. <A NAME="line52"></A>(* Sock I/O option types *)
  62. <A NAME="line53"></A>type <A HREF="#out_flags-typ">out_flags</A> = { don't_route : bool, oob : bool }
  63. <A NAME="line54"></A>type <A HREF="#in_flags-typ">in_flags</A> = { peek : bool, oob : bool }
  64. <A NAME="line55"></A>
  65. <A NAME="line56"></A>type 'a <A HREF="#buf-typ">buf</A> = { buf : 'a, ofs : int, size : int option }
  66. <A NAME="line57"></A>
  67. <A NAME="line58"></A>
  68. <A NAME="line59"></A>(* Socket output operations *)
  69. <A NAME="line60"></A>val <A HREF="#sendVec-val">sendVec</A> : ('a, active stream) sock * Word8Vector.vector buf -&gt; int
  70. <A NAME="line61"></A>val <A HREF="#sendArr-val">sendArr</A> : ('a, active stream) sock * Word8Array.array buf -&gt; int
  71. <A NAME="line62"></A>val <A HREF="#sendVec%27-val">sendVec'</A> : ('a, active stream) sock * Word8Vector.vector buf
  72. <A NAME="line63"></A> * out_flags -&gt; int
  73. <A NAME="line64"></A>val <A HREF="#sendArr%27-val">sendArr'</A> : ('a, active stream) sock * Word8Array.array buf
  74. <A NAME="line65"></A> * out_flags -&gt; int
  75. <A NAME="line66"></A>val <A HREF="#sendVecTo-val">sendVecTo</A> : ('a, dgram) sock * 'a sock_addr * Word8Vector.vector buf
  76. <A NAME="line67"></A> -&gt; int
  77. <A NAME="line68"></A>val <A HREF="#sendArrTo-val">sendArrTo</A> : ('a, dgram) sock * 'a sock_addr * Word8Array.array buf
  78. <A NAME="line69"></A> -&gt; int
  79. <A NAME="line70"></A>val <A HREF="#sendVecTo%27-val">sendVecTo'</A> : ('a, dgram) sock * 'a sock_addr * Word8Vector.vector buf
  80. <A NAME="line71"></A> * out_flags -&gt; int
  81. <A NAME="line72"></A>val <A HREF="#sendArrTo%27-val">sendArrTo'</A> : ('a, dgram) sock * 'a sock_addr * Word8Array.array buf
  82. <A NAME="line73"></A> * out_flags -&gt; int
  83. <A NAME="line74"></A>
  84. <A NAME="line75"></A>(* Socket input operations *)
  85. <A NAME="line76"></A>val <A HREF="#recvVec-val">recvVec</A> : ('a, active stream) sock * int -&gt; Word8Vector.vector
  86. <A NAME="line77"></A>val <A HREF="#recvArr-val">recvArr</A> : ('a, active stream) sock * Word8Array.array buf -&gt; int
  87. <A NAME="line78"></A>val <A HREF="#recvVec%27-val">recvVec'</A> : ('a, active stream) sock * int * in_flags
  88. <A NAME="line79"></A> -&gt; Word8Vector.vector
  89. <A NAME="line80"></A>val <A HREF="#recvArr%27-val">recvArr'</A> : ('a, active stream) sock * Word8Array.array buf * in_flags
  90. <A NAME="line81"></A> -&gt; int
  91. <A NAME="line82"></A>val <A HREF="#recvVecFrom-val">recvVecFrom</A> : ('a, dgram) sock * int
  92. <A NAME="line83"></A> -&gt; Word8Vector.vector * 'a sock_addr
  93. <A NAME="line84"></A>val <A HREF="#recvArrFrom-val">recvArrFrom</A> : ('a, dgram) sock * Word8Array.array buf
  94. <A NAME="line85"></A> -&gt; int * 'a sock_addr
  95. <A NAME="line86"></A>val <A HREF="#recvVecFrom%27-val">recvVecFrom'</A> : ('a, dgram) sock * int * in_flags
  96. <A NAME="line87"></A> -&gt; Word8Vector.vector * 'a sock_addr
  97. <A NAME="line88"></A>val <A HREF="#recvArrFrom%27-val">recvArrFrom'</A> : ('a, dgram) sock * Word8Array.array buf * in_flags
  98. <A NAME="line89"></A> -&gt; int * 'a sock_addr
  99. <A NAME="line90"></A>
  100. <A NAME="line91"></A>(*
  101. <A NAME="line92"></A> Structure Socket defines functions for creating and using sockets,
  102. <A NAME="line93"></A> a means for communication between SML processes on the same machine
  103. <A NAME="line94"></A> or via a network.
  104. <A NAME="line95"></A>
  105. [('addressfam, 'socktype) <A NAME="sock-typ"><B>sock</B></A>] is the type of sockets with address
  106. family 'addressfam and having type 'socktype.
  107. ['addressfam <A NAME="sock_addr-typ"><B>sock_addr</B></A>] is the type of sockets addresses.
  108. The possible address (protocol) families are
  109. type pf_file The Unix address family (file)
  110. type pf_inet The Internet address family
  111. The possible socket types are
  112. type dgram datagram sockets
  113. type 'a stream stream sockets
  114. type passive passive stream sockets
  115. type active active, or connected, stream sockets
  116. [<A NAME="fileAddr-val"><B>fileAddr</B></A> fname] returns a socket address for the Unix protocol
  117. family, created from the given file name fname.
  118. [<A NAME="inetAddr-val"><B>inetAddr</B></A> inetaddr portno] returns a socket address for the
  119. Internet protocol family, created from the given Internet number
  120. (e.g. "130.225.40.253") and port number (e.g. 8080).
  121. [<A NAME="fileStream-val"><B>fileStream</B></A> ()] returns a new stream socket for the Unix protocol
  122. family.
  123. [<A NAME="fileDgram-val"><B>fileDgram</B></A> ()] returns a new datagram socket for the Unix protocol
  124. family.
  125. [<A NAME="inetStream-val"><B>inetStream</B></A> ()] returns a new stream socket for the Internet
  126. protocol family.
  127. [<A NAME="inetDgram-val"><B>inetDgram</B></A> ()] returns a new datagram socket for the Internet
  128. protocol family.
  129. [<A NAME="accept-val"><B>accept</B></A> sock] extracts the first connection on the queue of pending
  130. connections to sock. Returns (sock', addr) where sock' is a copy
  131. of the socket sock, bound to that connection, and addr is the
  132. address of the communications counterpart (the other end of the
  133. connection). Blocks if no connections are pending. The stream
  134. socket sock must have been assigned a name (with bind) and must be
  135. listening for connections (following a call to listen).
  136. [<A NAME="bind-val"><B>bind</B></A> sock addr] binds the socket sock to the address addr, that
  137. is, assigns the name addr to the socket. Binding a name in the
  138. Unix protocol family creates a socket in the file system that must
  139. be deleted when it is no longer needed
  140. [<A NAME="connect-val"><B>connect</B></A> (sock, addr)] attempts to connect socket sock to the
  141. communications peer at address addr. If sock is a datagram socket,
  142. then addr is the address to which datagrams is to be sent, and the
  143. only address from which datagrams will be accepted. If sock is a
  144. stream socket, then addr specifies another socket to which to
  145. connect.
  146. [<A NAME="listen-val"><B>listen</B></A> (sock, queuelen)] enables the passive stream socket sock to
  147. accept incoming connections. The parameter queuelen specifies the
  148. maximal number of pending connections. Further connections from
  149. clients may be refused when this limit is reached.
  150. [<A NAME="close-val"><B>close</B></A> sock] closes the socket.
  151. [<A NAME="shutdown-val"><B>shutdown</B></A> sock shutdown_mode] shuts down socket sock for further
  152. communication, as specified by the shutdown_mode parameter:
  153. [<A NAME="NO_RECVS-con"><B>NO_RECVS</B></A>] no further receives are allowed;
  154. [<A NAME="NO_SENDS-con"><B>NO_SENDS</B></A>] no further sends are allowed;
  155. [<A NAME="NO_RECVS_OR_SENDS-con"><B>NO_RECVS_OR_SENDS</B></A>] no further receives or sends are allowed.
  156. [<A NAME="getinetaddr-val"><B>getinetaddr</B></A> addr] returns the Internet number
  157. (e.g. "130.225.40.253") of the Internet socket address addr.
  158. ['a <A NAME="buf-typ"><B>buf</B></A>] is the type of records { buf, ofs, size } which represent
  159. subvectors or subarrays:
  160. if size = SOME s it represents buf[ofs..ofs+s-1];
  161. if size = NONE it represents buf[ofs..len-1] where len is buf's length.
  162. When the subbuffer is used in a call, exception Subscript will be raised
  163. if ofs &lt; 0 or size &lt; 0 or ofs+size &gt; len.
  164. [<A NAME="sendVec-val"><B>sendVec</B></A> (sock, vecbuf)] transmits the bytes from buffer vecbuf on
  165. the active stream socket sock. Returns the number of bytes sent.
  166. Blocks until sufficient space is available at the socket.
  167. [<A NAME="sendArr-val"><B>sendArr</B></A> (sock, arrbuf)] is analogous til sendVec.
  168. [<A NAME="sendVec%27-val"><B>sendVec'</B></A> (sock, vecbuf, out_flags)] transmits the bytes from
  169. buffer vecbuf on the active stream socket sock, observing the
  170. out_flags. Returns the number of bytes sent. Blocks until
  171. sufficient space is available at the socket.
  172. [<A NAME="out_flags-typ"><B>out_flags</B></A>] is the type of records { don't_route, oob } in which
  173. the field don't_route specifies whether routing should be bypassed,
  174. and the field oob specifies whether data should be sent out-of-band.
  175. [<A NAME="sendArr%27-val"><B>sendArr'</B></A> (sock, arrbuf, out_flags)] is analogous til sendVec'.
  176. [<A NAME="sendVecTo-val"><B>sendVecTo</B></A> (sock, addr, vecbuf)] transmits the bytes from buffer
  177. vecbuf on the datagram socket sock to the target address addr.
  178. Returns the number of bytes sent. Blocks until sufficient space is
  179. available at the socket.
  180. [<A NAME="sendArrTo-val"><B>sendArrTo</B></A> (sock, addr, arrbuf)] is analogous til sendVecTo.
  181. [<A NAME="sendVecTo%27-val"><B>sendVecTo'</B></A> (sock, addr, vecbuf, out_flags)] transmits the bytes
  182. from buffer vecbuf on the datagram socket sock to the target
  183. address addr, observing the out_flags. Returns the number of bytes
  184. sent. Blocks until sufficient space is available at the socket.
  185. See above for a description of vecbuf and out_flags.
  186. [<A NAME="sendArrTo%27-val"><B>sendArrTo'</B></A> (sock, addr, arrbuf, out_flags)] is analogous til sendVecTo'.
  187. [<A NAME="recvVec-val"><B>recvVec</B></A> (sock, n)] receives up to n bytes from the active stream
  188. socket sock. Returns a byte vector containing the bytes actually
  189. received. Blocks until some data become available at the socket,
  190. then returns any available data, up to n bytes. Excess data are
  191. not lost; they are available for subsequent receive calls.
  192. [<A NAME="recvArr-val"><B>recvArr</B></A> (sock, arrbuf)] receives bytes from the active stream
  193. socket sock into the subarray arrbuf, up to the available space.
  194. If #size(arrbuf) = SOME(s) the available space is s bytes; if
  195. #size(arrbuf) = NONE the available space is len - #ofs(arrbuf)
  196. bytes. Returns the number of bytes actually received. Blocks
  197. until some data become available at the socket. Excess data are
  198. not lost; they are available for subsequent receive calls.
  199. [<A NAME="recvVec%27-val"><B>recvVec'</B></A> (sock, n, in_flags)] receives up to n bytes from the
  200. active stream socket sock, observing the in_flags. Returns a byte
  201. vector containing the bytes actually received. Blocks until some
  202. data become available at the socket, then returns any available
  203. data, up to n bytes. Data in excess of n bytes are not lost; they
  204. are available for subsequent receive calls.
  205. [<A NAME="in_flags-typ"><B>in_flags</B></A>] is the type of records { peek, oob } in which the field
  206. peek specifies that the data read should not be removed from the
  207. receive queue, and the field oob specifies that data may be
  208. received out-of-band.
  209. [<A NAME="recvArr%27-val"><B>recvArr'</B></A> (sock, arrbuf, in_flags)] receives bytes from the active
  210. stream socket sock into the subarray arrbuf, observing the
  211. in_flags, up to the available space.. Returns the number of bytes
  212. actually received. Blocks until some data become available at the
  213. socket. Excess data are not lost; they are available for
  214. subsequent receive calls.
  215. [<A NAME="recvVecFrom-val"><B>recvVecFrom</B></A> (sock, n)] receives up to n bytes from the datagram
  216. socket sock. Returns a byte vector containing the bytes actually
  217. received. Blocks until some data become available at the socket,
  218. then returns any available data, up to n bytes.
  219. [<A NAME="recvArrFrom-val"><B>recvArrFrom</B></A> (sock, arrbuf)] receives bytes from the datagram
  220. socket sock into the subarray arrbuf. Returns the number of bytes
  221. actually received. Blocks until some data become available at the
  222. socket.
  223. [<A NAME="recvVecFrom%27-val"><B>recvVecFrom'</B></A> (sock, n, in_flags)] receives up to n bytes from the
  224. datagram socket sock, observing the in_flags (see above). Returns
  225. (vec, addr) where vec is a byte vector containing the bytes
  226. actually received, and addr is the source address of the message.
  227. Blocks until some data become available at the socket, then returns
  228. any available data, up to n bytes.
  229. [<A NAME="recvArrFrom%27-val"><B>recvArrFrom'</B></A> (sock, arrbuf, in_flags)] receives bytes from the
  230. datagram socket sock into the array buffer arrbuf, observing the
  231. in_flags (see above). Returns (n, addr) where n is the number of
  232. bytes actually received, and addr is the source address of the
  233. message. Blocks until some data become available at the socket.
  234. [<A NAME="sockDesc-val"><B>sockDesc</B></A> sock] returns a descriptor for the socket sock, to be
  235. used in a call to select.
  236. [<A NAME="compare-val"><B>compare</B></A> (sd1, sd2)] compares sd1 and sd2 according to an
  237. unspecified total ordering, and returns LESS if sd1 precedes sd2,
  238. returns GREATER is sd1 precedes sd2, and returns EQUAL otherwise.
  239. [<A NAME="sameDesc-val"><B>sameDesc</B></A> (sd1, sd2)] returns true if sd1 and sd2 describe the same
  240. socket. Equivalent to compare(sd1, sd2) = EQUAL.
  241. [<A NAME="select-val"><B>select</B></A> { rds, wrs, exs, timeout }] blocks the calling process
  242. until some input/output operations become possible on some sockets.
  243. The call will check the sockets described in rds for reading, those
  244. in wrs for writing, and those in exs for exceptional conditions.
  245. Returns { rds, wrs, exs } where rds now is a list of descriptors of
  246. sockets ready for reading, wrs are ready for writing, and exs have
  247. exceptional conditions. The order of the socket descriptors in the
  248. results is the same as their order in the corresponding arguments.
  249. If timeout is NONE then the call blocks until some input/output
  250. operations become possible; if timeout is SOME(t) then the call
  251. blocks for at most time t.
  252. A server socket is considered ready for reading if there is a
  253. pending connection which can be accepted with `accept'. A client
  254. socket is ready for writing when its connection is fully
  255. established.
  256. *)
  257. </PRE><HR><TABLE WIDTH=100%><TR ALIGN = CENTER>
  258. <TH><A HREF="idIndex.html">Identifier index</A>
  259. <TH><A HREF="index.html">Structure index</A>
  260. </TABLE><HR>
  261. <BR><EM><A HREF="http://www.dina.kvl.dk/~sestoft/mosml.html">Moscow ML</A> 2.00.1</EM></BODY></HTML>