<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <link rel="Start" href="index.html"> <link rel="previous" href="Std.Shutdown.html"> <link rel="next" href="Std.Signal.html"> <link rel="Up" href="Std.html"> <link title="Index of types" rel=Appendix href="index_types.html"> <link title="Index of exceptions" rel=Appendix href="index_exceptions.html"> <link title="Index of values" rel=Appendix href="index_values.html"> <link title="Index of modules" rel=Appendix href="index_modules.html"> <link title="Index of module types" rel=Appendix href="index_module_types.html"> <link title="Async_print" rel="Chapter" href="Async_print.html"> <link title="Async_sys" rel="Chapter" href="Async_sys.html"> <link title="Epoll_file_descr_watcher" rel="Chapter" href="Epoll_file_descr_watcher.html"> <link title="Fd" rel="Chapter" href="Fd.html"> <link title="Fd_by_descr" rel="Chapter" href="Fd_by_descr.html"> <link title="File_descr_watcher_intf" rel="Chapter" href="File_descr_watcher_intf.html"> <link title="Import" rel="Chapter" href="Import.html"> <link title="Interruptor" rel="Chapter" href="Interruptor.html"> <link title="In_thread" rel="Chapter" href="In_thread.html"> <link title="Io_stats" rel="Chapter" href="Io_stats.html"> <link title="Process" rel="Chapter" href="Process.html"> <link title="Raw_fd" rel="Chapter" href="Raw_fd.html"> <link title="Raw_scheduler" rel="Chapter" href="Raw_scheduler.html"> <link title="Raw_signal_manager" rel="Chapter" href="Raw_signal_manager.html"> <link title="Reader" rel="Chapter" href="Reader.html"> <link title="Read_write" rel="Chapter" href="Read_write.html"> <link title="Scheduler" rel="Chapter" href="Scheduler.html"> <link title="Select_file_descr_watcher" rel="Chapter" href="Select_file_descr_watcher.html"> <link title="Shutdown" rel="Chapter" href="Shutdown.html"> <link title="Signal" rel="Chapter" href="Signal.html"> <link title="Signal_manager" rel="Chapter" href="Signal_manager.html"> <link title="Std" rel="Chapter" href="Std.html"> <link title="Syscall" rel="Chapter" href="Syscall.html"> <link title="Thread_pool" rel="Chapter" href="Thread_pool.html"> <link title="Thread_safe" rel="Chapter" href="Thread_safe.html"> <link title="Thread_safe_pipe" rel="Chapter" href="Thread_safe_pipe.html"> <link title="Unix_syscalls" rel="Chapter" href="Unix_syscalls.html"> <link title="Writer" rel="Chapter" href="Writer.html"><title>Std.Socket</title> </head> <body> <div class="navbar"><a class="pre" href="Std.Shutdown.html" title="Std.Shutdown">Previous</a> <a class="up" href="Std.html" title="Std">Up</a> <a class="post" href="Std.Signal.html" title="Std.Signal">Next</a> </div> <h1>Module <a href="type_Std.Socket.html">Std.Socket</a></h1> <pre><span class="keyword">module</span> Socket: <code class="type"><a href="Unix_syscalls.Socket.html">Unix_syscalls.Socket</a></code></pre><hr width="100%"> <pre><span class="keyword">module</span> <a href="Unix_syscalls.Socket.Address.html">Address</a>: <code class="code">sig</code> <a href="Unix_syscalls.Socket.Address.html">..</a> <code class="code">end</code></pre> <pre><span class="keyword">module</span> <a href="Unix_syscalls.Socket.Family.html">Family</a>: <code class="code">sig</code> <a href="Unix_syscalls.Socket.Family.html">..</a> <code class="code">end</code></pre> <pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">([< `Active | `Bound | `Passive | `Unconnected ]<br> , [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ])</code> t</span> </pre> <div class="info "> Sockets have a phantom type parameter that tracks the state of the socket in order to eliminate certain errors in which socket functions are called in the wrong order. Initially, a socket is `Unconnected. As various socket functions are called, they return a socket with a new phantom state. Here is a chart of the allowed state transitions. <p> <pre class="verbatim"> Unconnected ---connect--> Active | | ---bind--> Bound ---listen--> Passive ---accept---> Active </pre><br> </div> <pre><span class="keyword">module</span> <a href="Unix_syscalls.Socket.Type.html">Type</a>: <code class="code">sig</code> <a href="Unix_syscalls.Socket.Type.html">..</a> <code class="code">end</code></pre> <pre><span id="VALcreate"><span class="keyword">val</span> create</span> : <code class="type">([< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a) <a href="Unix_syscalls.Socket.Type.html#TYPEt">Type.t</a> -><br> ([ `Unconnected ], 'a) <a href="Unix_syscalls.Socket.html#TYPEt">t</a></code></pre> <pre><span id="VALconnect"><span class="keyword">val</span> connect</span> : <code class="type">([ `Unconnected ], [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a)<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -><br> 'a -> ([ `Active ], 'a) <a href="Unix_syscalls.Socket.html#TYPEt">t</a> Import.Deferred.t</code></pre> <pre><span id="VALconnect_interruptible"><span class="keyword">val</span> connect_interruptible</span> : <code class="type">([ `Unconnected ], [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a)<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -><br> 'a -><br> interrupt:unit Import.Deferred.t -><br> [ `Interrupted | `Ok of ([ `Active ], 'a) <a href="Unix_syscalls.Socket.html#TYPEt">t</a> ]<br> Import.Deferred.t</code></pre> <pre><span id="VALbind"><span class="keyword">val</span> bind</span> : <code class="type">([ `Unconnected ], [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a)<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -><br> 'a -> ([ `Bound ], 'a) <a href="Unix_syscalls.Socket.html#TYPEt">t</a> Import.Deferred.t</code></pre><div class="info "> <code class="code">bind socket addr</code> sets close_on_exec for the fd of <code class="code">socket</code>.<br> </div> <pre><span id="VALlisten"><span class="keyword">val</span> listen</span> : <code class="type">?max_pending_connections:int -><br> ([ `Bound ], [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a)<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -> ([ `Passive ], 'a) <a href="Unix_syscalls.Socket.html#TYPEt">t</a></code></pre> <pre><span id="VALaccept"><span class="keyword">val</span> accept</span> : <code class="type">([ `Passive ], [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a)<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -><br> [ `Ok of ([ `Active ], 'a) <a href="Unix_syscalls.Socket.html#TYPEt">t</a> * 'a | `Socket_closed ]<br> Import.Deferred.t</code></pre> <pre><span id="VALaccept_interruptible"><span class="keyword">val</span> accept_interruptible</span> : <code class="type">([ `Passive ], [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a)<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -><br> interrupt:unit Import.Deferred.t -><br> [ `Interrupted<br> | `Ok of ([ `Active ], 'a) <a href="Unix_syscalls.Socket.html#TYPEt">t</a> * 'a<br> | `Socket_closed ] Import.Deferred.t</code></pre> <pre><span id="VALshutdown"><span class="keyword">val</span> shutdown</span> : <code class="type">([< `Active | `Bound | `Passive | `Unconnected ],<br> [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ])<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -> [ `Both | `Receive | `Send ] -> unit</code></pre> <pre><span id="VALfd"><span class="keyword">val</span> fd</span> : <code class="type">([< `Active | `Bound | `Passive | `Unconnected ],<br> [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ])<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -> <a href="Fd.html#TYPEt">Fd.t</a></code></pre> <pre><span id="VALof_fd"><span class="keyword">val</span> of_fd</span> : <code class="type"><a href="Fd.html#TYPEt">Fd.t</a> -><br> ([< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a) <a href="Unix_syscalls.Socket.Type.html#TYPEt">Type.t</a> -><br> ([< `Active | `Bound | `Passive | `Unconnected ], 'a) <a href="Unix_syscalls.Socket.html#TYPEt">t</a></code></pre> <pre><span id="VALgetsockname"><span class="keyword">val</span> getsockname</span> : <code class="type">([< `Active | `Bound | `Passive | `Unconnected ],<br> [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a)<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -> 'a</code></pre> <pre><span id="VALgetpeername"><span class="keyword">val</span> getpeername</span> : <code class="type">([< `Active | `Bound | `Passive | `Unconnected ],<br> [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'a)<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -> 'a</code></pre> <pre><span class="keyword">module</span> <a href="Unix_syscalls.Socket.Opt.html">Opt</a>: <code class="code">sig</code> <a href="Unix_syscalls.Socket.Opt.html">..</a> <code class="code">end</code></pre> <pre><span id="VALgetopt"><span class="keyword">val</span> getopt</span> : <code class="type">([< `Active | `Bound | `Passive | `Unconnected ],<br> [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ])<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -> 'c <a href="Unix_syscalls.Socket.Opt.html#TYPEt">Opt.t</a> -> 'c</code></pre> <pre><span id="VALsetopt"><span class="keyword">val</span> setopt</span> : <code class="type">([< `Active | `Bound | `Passive | `Unconnected ],<br> [< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ])<br> <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -> 'c <a href="Unix_syscalls.Socket.Opt.html#TYPEt">Opt.t</a> -> 'c -> unit</code></pre> <pre><span id="VALsexp_of_t"><span class="keyword">val</span> sexp_of_t</span> : <code class="type">(([< `Active | `Bound | `Passive | `Unconnected ] as 'a) -> Sexplib.Sexp.t) -><br> (([< <a href="Unix_syscalls.Socket.Address.html#TYPEt">Address.t</a> ] as 'b) -> Sexplib.Sexp.t) -><br> ('a, 'b) <a href="Unix_syscalls.Socket.html#TYPEt">t</a> -> Sexplib.Sexp.t</code></pre><br> <code class="code">bind socket addr</code> sets close_on_exec for the fd of <code class="code">socket</code>.<br> </body></html>