Sophie

Sophie

distrib > Fedora > 16 > i386 > by-pkgid > 6048cee8a558eec9d1d34eac70346535 > files > 31

ghc-sendfile-devel-0.7.6-1.fc16.i686.rpm

<!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.Socket.SendFile.Handle</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-Socket-SendFile-Handle.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Network-Socket-SendFile-Handle.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">sendfile-0.7.6: A portable sendfile library</p></div><div id="content"><div id="module-header"><p class="caption">Network.Socket.SendFile.Handle</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Handle-based sendFiles
</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Handle-based versions of some of the functions exported by
 Network.Socket.SendFile. 
</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">type</span> <a href="#t:ByteCount">ByteCount</a> = <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Prelude.html#t:Integer">Integer</a></li><li class="src short"><span class="keyword">type</span> <a href="#t:Offset">Offset</a> = <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Prelude.html#t:Integer">Integer</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:Iter">Iter</a> <ul class="subs"><li>= <a href="#v:Sent">Sent</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int64">Int64</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a>)  </li><li>| <a href="#v:WouldBlock">WouldBlock</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int64">Int64</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-Posix-Types.html#t:Fd">Fd</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a>)  </li><li>| <a href="#v:Done">Done</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int64">Int64</a>  </li></ul></li><li class="src short"><a href="#v:runIter">runIter</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int64">Int64</a></li><li class="src short"><a href="#v:sendFile">sendFile</a> :: <a href="/usr/share/doc/ghc/html/libraries/network-2.3.0.2/Network-Socket.html#t:Socket">Socket</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:sendFileIterWith">sendFileIterWith</a> ::  (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a) -&gt; <a href="/usr/share/doc/ghc/html/libraries/network-2.3.0.2/Network-Socket.html#t:Socket">Socket</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:ByteCount">ByteCount</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:sendFile-39-">sendFile'</a> :: <a href="/usr/share/doc/ghc/html/libraries/network-2.3.0.2/Network-Socket.html#t:Socket">Socket</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:Offset">Offset</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:ByteCount">ByteCount</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:sendFileIterWith-39-">sendFileIterWith'</a> ::  (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a) -&gt; <a href="/usr/share/doc/ghc/html/libraries/network-2.3.0.2/Network-Socket.html#t:Socket">Socket</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:ByteCount">ByteCount</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:Offset">Offset</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:ByteCount">ByteCount</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a</li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:ByteCount" class="def">ByteCount</a> = <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Prelude.html#t:Integer">Integer</a><a href="src/Network-Socket-SendFile.html#ByteCount" class="link">Source</a></p><div class="doc"><p>The length (in bytes) which should be sent
</p></div></div><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:Offset" class="def">Offset</a> = <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Prelude.html#t:Integer">Integer</a><a href="src/Network-Socket-SendFile.html#Offset" class="link">Source</a></p><div class="doc"><p>The file offset (in bytes) to start from
</p></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:Iter" class="def">Iter</a>  <a href="src/Network-Socket-SendFile-Iter.html#Iter" class="link">Source</a></p><div class="doc"><p>An iteratee for sendfile
</p><p>In general, a whole file is not sent by a single call to
 sendfile(), but a series of calls which send successive pieces.
</p><p>The high-level API in this sendfile library has calls which will
 send the entire file (or an entire requested offset+length), before
 returning.
</p><p>However, there are instances where you want to be a bit more
 involved in the sending loop. For example, if you want to tickle a
 timeout after each chunk is sent or update a progress bar.
</p><p>The <code><a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a></code> type gives you that power with out requiring you to
 manage all the low-level details of the sendfile loop. The
 interface is simple and consistant across all platforms.
</p><p>A call to sendfile() can result in three different states:
</p><ol><li> the requested number of bytes for that iteration was sent
  successfully, there are more bytes left to send.
</li><li> some (possibly 0) bytes were sent, but the file descriptor
  would now block if more bytes were written. There are more bytes
  left to send.
</li><li> All the bytes were sent, and there is nothing left to send.
</li></ol><p>We handle these three cases by using a type with three
 constructors:
</p><pre>
  data Iter
      = Sent       Int64    (IO Iter)
      | WouldBlock Int64 Fd (IO Iter)
      | Done       Int64             
</pre><p>All three constructors provide an <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int64">Int64</a></code> which represents the
 number of bytes sent for that particular iteration. (Not the total
 byte count).
</p><p>The <code><a href="Network-Socket-SendFile-Handle.html#v:Sent">Sent</a></code> and <code><a href="Network-Socket-SendFile-Handle.html#v:WouldBlock">WouldBlock</a></code> constructors provide <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></code> <code><a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a></code> as their
 final argument. Running this IO action will send the next block of
 data.
</p><p>The <code><a href="Network-Socket-SendFile-Handle.html#v:WouldBlock">WouldBlock</a></code> constructor also provides the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-Posix-Types.html#t:Fd">Fd</a></code> for the output
 socket. You should not send anymore data until the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-Posix-Types.html#t:Fd">Fd</a></code> would not
 block. The easiest way to do that is to use <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Control-Concurrent.html#v:threadWaitWrite">threadWaitWrite</a></code> to
 suspend the thread until the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-Posix-Types.html#t:Fd">Fd</a></code> is available.
</p><p>A very simple function to drive the Iter might look like:
</p><pre>
 runIter :: IO Iter -&gt; IO ()
 runIter iter =
    do r &lt;- iter
       case r of
         (Done _n)      -&gt; return ()
         (Sent _n cont) -&gt; runIter cont
         (WouldBlock _n fd cont) -&gt; 
             do threadWaitWrite fd
                runIter cont
</pre><p>You would use it as the first argument to a *IterWith function, e.g.
</p><pre>
  sendFileIterWith runIter outputSocket &quot;/path/to/file&quot; 2^16 
</pre><p>The <code><a href="Network-Socket-SendFile-Handle.html#v:runIter">runIter</a></code> function provided by this module is similar, but also returns the total number of bytes sent.
</p><p>NOTE: You must not use the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-Posix-Types.html#t:Fd">Fd</a></code> or the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a></code> <code><a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a></code> after the call
 to *IterWith has returned. When the *IterWith functions return,
 the file descriptors may be closed due to finalizers running.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:Sent" class="def">Sent</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int64">Int64</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a>)</td><td class="doc"><p>number of bytes sent this pass and a continuation to send more
</p></td></tr><tr><td class="src"><a name="v:WouldBlock" class="def">WouldBlock</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int64">Int64</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-Posix-Types.html#t:Fd">Fd</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a>)</td><td class="doc"><p>number of bytes sent, Fd that blocked, continuation to send more. NOTE: The Fd should not be used outside the running of the Iter as it may be freed when the Iter is done
</p></td></tr><tr><td class="src"><a name="v:Done" class="def">Done</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int64">Int64</a></td><td class="doc"><p>number of bytes sent, no more to send
</p></td></tr></table></div></div><div class="top"><p class="src"><a name="v:runIter" class="def">runIter</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int64">Int64</a><a href="src/Network-Socket-SendFile-Iter.html#runIter" class="link">Source</a></p><div class="doc"><p>A simple function to drive the *IterWith functions.
 It returns the total number of bytes sent.
</p></div></div><h1 id="g:1">Handle-based sendFiles
</h1><div class="top"><p class="src"><a name="v:sendFile" class="def">sendFile</a> :: <a href="/usr/share/doc/ghc/html/libraries/network-2.3.0.2/Network-Socket.html#t:Socket">Socket</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a><a href="src/Network-Socket-SendFile-Handle.html#sendFile" class="link">Source</a></p><div class="doc"><p>Simple sendFile - give it a Socket and a Handle, and it sends the entire
 file through the socket.
</p><p>WARNING: This function will raise <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO-Error.html#t:IOError">IOError</a></code> <code>IllegalOperation</code>
 if the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code> is not for an <code>Fd</code>.
</p></div></div><div class="top"><p class="src"><a name="v:sendFileIterWith" class="def">sendFileIterWith</a> ::  (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a) -&gt; <a href="/usr/share/doc/ghc/html/libraries/network-2.3.0.2/Network-Socket.html#t:Socket">Socket</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:ByteCount">ByteCount</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a<a href="src/Network-Socket-SendFile-Handle.html#sendFileIterWith" class="link">Source</a></p><div class="doc"><p>A more interactive version of sendFile, which accepts a callback function
 in addition to the socket and handle.  The callback will be called for each
 chunk of data the sendFileIterWith function acts on.
</p><p>WARNING: This function will raise <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO-Error.html#t:IOError">IOError</a></code> <code>IllegalOperation</code>
 if the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code> is not for an <code>Fd</code>.
</p></div></div><div class="top"><p class="src"><a name="v:sendFile-39-" class="def">sendFile'</a> :: <a href="/usr/share/doc/ghc/html/libraries/network-2.3.0.2/Network-Socket.html#t:Socket">Socket</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:Offset">Offset</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:ByteCount">ByteCount</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a><a href="src/Network-Socket-SendFile-Handle.html#sendFile%27" class="link">Source</a></p><div class="doc"><p>A sendFile that allows the user to send a subset of the file associated
 with the given handle.
</p><p>WARNING: This function will raise <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO-Error.html#t:IOError">IOError</a></code> <code>IllegalOperation</code>
 if the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code> is not for an <code>Fd</code>.
</p></div></div><div class="top"><p class="src"><a name="v:sendFileIterWith-39-" class="def">sendFileIterWith'</a> ::  (<a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> <a href="Network-Socket-SendFile-Handle.html#t:Iter">Iter</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a) -&gt; <a href="/usr/share/doc/ghc/html/libraries/network-2.3.0.2/Network-Socket.html#t:Socket">Socket</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:ByteCount">ByteCount</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:Offset">Offset</a> -&gt; <a href="Network-Socket-SendFile-Handle.html#t:ByteCount">ByteCount</a> -&gt; <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO.html#t:IO">IO</a> a<a href="src/Network-Socket-SendFile-Handle.html#sendFileIterWith%27" class="link">Source</a></p><div class="doc"><p>A more powerful version of sendFileIterWith, which allows the sending of a
 subset of the given file.
</p><p>WARNING: This function will raise <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/System-IO-Error.html#t:IOError">IOError</a></code> <code>IllegalOperation</code>
 if the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code> is not for an <code>Fd</code>.
</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.9.2</p></div></body></html>