16 lines
20 KiB
HTML
16 lines
20 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Network.SocketServer</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
|
|
window.onload = function () {pageLoad();setSynopsis("mini_Network-SocketServer.html");};
|
|
//]]>
|
|
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">MissingH-1.3.0.1: Large utility library</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Copyright</th><td>Copyright (C) 2004-2011 John Goerzen</td></tr><tr><th>License</th><td>BSD3</td></tr><tr><th>Maintainer</th><td>John Goerzen <jgoerzen@complete.org> </td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Portability</th><td>systems with networking</td></tr><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell98</td></tr></table><p class="caption">Network.SocketServer</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Generic Options and Types</a></li><li><a href="#g:2">TCP server convenient setup</a></li><li><a href="#g:3">Lower-Level Processing</a></li><li><a href="#g:4">Combinators</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>This module provides an infrastructure to simplify server design.</p><p>Written by John Goerzen, jgoerzen@complete.org</p><p>Please note: this module is designed to work with TCP, UDP, and Unix domain
|
|
sockets, but only TCP sockets have been tested to date.</p><p>This module is presently under-documented. For an example of usage, please
|
|
see the description of <a href="Network-FTP-Server.html">Network.FTP.Server</a>.</p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span> <a href="#t:InetServerOptions">InetServerOptions</a> = <a href="#v:InetServerOptions">InetServerOptions</a> {<ul class="subs"><li><a href="#v:listenQueueSize">listenQueueSize</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></li><li><a href="#v:portNumber">portNumber</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:PortNumber">PortNumber</a></li><li><a href="#v:interface">interface</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:HostAddress">HostAddress</a></li><li><a href="#v:reuse">reuse</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:family">family</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:Family">Family</a></li><li><a href="#v:sockType">sockType</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket.html#t:SocketType">SocketType</a></li><li><a href="#v:protoStr">protoStr</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></li></ul>}</li><li class="src short"><a href="#v:simpleTCPOptions">simpleTCPOptions</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a> -> <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:SocketServer">SocketServer</a> = <a href="#v:SocketServer">SocketServer</a> {<ul class="subs"><li><a href="#v:optionsSS">optionsSS</a> :: <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a></li><li><a href="#v:sockSS">sockSS</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket.html#t:Socket">Socket</a></li></ul>}</li><li class="src short"><span class="keyword">type</span> <a href="#t:HandlerT">HandlerT</a> = <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket.html#t:Socket">Socket</a> -> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:SockAddr">SockAddr</a> -> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:SockAddr">SockAddr</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:serveTCPforever">serveTCPforever</a> :: <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a> -> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:setupSocketServer">setupSocketServer</a> :: <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a></li><li class="src short"><a href="#v:handleOne">handleOne</a> :: <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a> -> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:serveForever">serveForever</a> :: <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a> -> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:closeSocketServer">closeSocketServer</a> :: <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:loggingHandler">loggingHandler</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/hslogger-1.2.8/html/System-Log.html#t:Priority">Priority</a> -> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a> -> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a></li><li class="src short"><a href="#v:threadedHandler">threadedHandler</a> :: <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a> -> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a></li><li class="src short"><a href="#v:handleHandler">handleHandler</a> :: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:SockAddr">SockAddr</a> -> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:SockAddr">SockAddr</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()) -> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a></li></ul></div><div id="interface"><h1 id="g:1">Generic Options and Types</h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:InetServerOptions" class="def">InetServerOptions</a></p><div class="doc"><p>Options for your server. </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:InetServerOptions" class="def">InetServerOptions</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><dl><dt class="src"><a name="v:listenQueueSize" class="def">listenQueueSize</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></dt><dd class="doc empty"> </dd><dt class="src"><a name="v:portNumber" class="def">portNumber</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:PortNumber">PortNumber</a></dt><dd class="doc empty"> </dd><dt class="src"><a name="v:interface" class="def">interface</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:HostAddress">HostAddress</a></dt><dd class="doc empty"> </dd><dt class="src"><a name="v:reuse" class="def">reuse</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></dt><dd class="doc empty"> </dd><dt class="src"><a name="v:family" class="def">family</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:Family">Family</a></dt><dd class="doc empty"> </dd><dt class="src"><a name="v:sockType" class="def">sockType</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket.html#t:SocketType">SocketType</a></dt><dd class="doc empty"> </dd><dt class="src"><a name="v:protoStr" class="def">protoStr</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></dt><dd class="doc empty"> </dd></dl><div class="clear"></div></div></td></tr></table></div><div class="subs instances"><p id="control.i:InetServerOptions" class="caption collapser" onclick="toggleSection('i:InetServerOptions')">Instances</p><div id="section.i:InetServerOptions" class="show"><table><tr><td class="src"><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Eq.html#t:Eq">Eq</a> <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:simpleTCPOptions" class="def">simpleTCPOptions</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></td><td class="doc"><p>Port Number</p></td></tr><tr><td class="src">-> <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Get Default options. You can always modify it later. </p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:SocketServer" class="def">SocketServer</a></p><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:SocketServer" class="def">SocketServer</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><dl><dt class="src"><a name="v:optionsSS" class="def">optionsSS</a> :: <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a></dt><dd class="doc empty"> </dd><dt class="src"><a name="v:sockSS" class="def">sockSS</a> :: <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket.html#t:Socket">Socket</a></dt><dd class="doc empty"> </dd></dl><div class="clear"></div></div></td></tr></table></div><div class="subs instances"><p id="control.i:SocketServer" class="caption collapser" onclick="toggleSection('i:SocketServer')">Instances</p><div id="section.i:SocketServer" class="show"><table><tr><td class="src"><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Eq.html#t:Eq">Eq</a> <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:HandlerT" class="def">HandlerT</a> = <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket.html#t:Socket">Socket</a> -> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:SockAddr">SockAddr</a> -> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:SockAddr">SockAddr</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>The main handler type.</p><p>The first parameter is the socket itself.</p><p>The second is the address of the remote endpoint.</p><p>The third is the address of the local endpoint.</p></div></div><h1 id="g:2">TCP server convenient setup</h1><div class="top"><p class="src"><a name="v:serveTCPforever" class="def">serveTCPforever</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a></td><td class="doc"><p>Server options</p></td></tr><tr><td class="src">-> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a></td><td class="doc"><p>Handler function</p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Convenience function to completely set up a TCP
|
|
<code><a href="Network-SocketServer.html#t:SocketServer">SocketServer</a></code> and handle all incoming requests.</p><p>This function is literally this:</p><pre>serveTCPforever options func =
|
|
do sockserv <- setupSocketServer options
|
|
serveForever sockserv func</pre></div></div><h1 id="g:3">Lower-Level Processing</h1><div class="top"><p class="src"><a name="v:setupSocketServer" class="def">setupSocketServer</a> :: <a href="Network-SocketServer.html#t:InetServerOptions">InetServerOptions</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a></p><div class="doc"><p>Takes some options and sets up the <code><a href="Network-SocketServer.html#t:SocketServer">SocketServer</a></code>. I will bind
|
|
and begin listening, but will not accept any connections itself. </p></div></div><div class="top"><p class="src"><a name="v:handleOne" class="def">handleOne</a> :: <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a> -> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Handle one incoming request from the given <code><a href="Network-SocketServer.html#t:SocketServer">SocketServer</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:serveForever" class="def">serveForever</a> :: <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a> -> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Handle all incoming requests from the given <code><a href="Network-SocketServer.html#t:SocketServer">SocketServer</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:closeSocketServer" class="def">closeSocketServer</a> :: <a href="Network-SocketServer.html#t:SocketServer">SocketServer</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Close the socket server. Does not terminate active
|
|
handlers, if any. </p></div></div><h1 id="g:4">Combinators</h1><div class="top"><p class="src"><a name="v:loggingHandler" class="def">loggingHandler</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></td><td class="doc"><p>Name of logger to use</p></td></tr><tr><td class="src">-> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/hslogger-1.2.8/html/System-Log.html#t:Priority">Priority</a></td><td class="doc"><p>Priority of logged messages</p></td></tr><tr><td class="src">-> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a></td><td class="doc"><p>Handler to call after logging</p></td></tr><tr><td class="src">-> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a></td><td class="doc"><p>Resulting handler</p></td></tr></table></div><div class="doc"><p>Log each incoming connection using the interface in
|
|
<a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/hslogger-1.2.8/html/System-Log-Logger.html">System.Log.Logger</a>.</p><p>Log when the incoming connection disconnects.</p><p>Also, log any failures that may occur in the child handler. </p></div></div><div class="top"><p class="src"><a name="v:threadedHandler" class="def">threadedHandler</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a></td><td class="doc"><p>Handler to call in the new thread</p></td></tr><tr><td class="src">-> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a></td><td class="doc"><p>Resulting handler</p></td></tr></table></div><div class="doc"><p>Handle each incoming connection in its own thread to
|
|
make the server multi-tasking.</p></div></div><div class="top"><p class="src"><a name="v:handleHandler" class="def">handleHandler</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:SockAddr">SockAddr</a> -> <a href="file:///Users/sidharta/.cabal/share/doc/x86_64-osx-ghc-7.10.1/network-2.6.0.2/html/Network-Socket-Internal.html#t:SockAddr">SockAddr</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ())</td><td class="doc"><p>Handler to call</p></td></tr><tr><td class="src">-> <a href="Network-SocketServer.html#t:HandlerT">HandlerT</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Give your handler function a Handle instead of a Socket.</p><p>The Handle will be opened with ReadWriteMode (you use one handle for both
|
|
directions of the Socket). Also, it will be initialized with LineBuffering.</p><p>Unlike other handlers, the handle will be closed when the function returns.
|
|
Therefore, if you are doing threading, you should to it before you call this
|
|
handler.</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.16.0</p></div></body></html> |