úÎo l¯     An iteratee for sendfile 9In general, a whole file is not sent by a single call to A sendfile(), but a series of calls which send successive pieces. AThe high-level API in this sendfile library has calls which will E send the entire file (or an entire requested offset+length), before  returning. =However, there are instances where you want to be a bit more D involved in the sending loop. For example, if you want to tickle a < timeout after each chunk is sent or update a progress bar. The 5 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. ;A call to sendfile() can result in three different states:  ; the requested number of bytes for that iteration was sent 3 successfully, there are more bytes left to send. < some (possibly 0) bytes were sent, but the file descriptor C would now block if more bytes were written. There are more bytes  left to send. = All the bytes were sent, and there is nothing left to send. 7We handle these three cases by using a type with three  constructors:    data Iter & = Sent Int64 (IO Iter) & | WouldBlock Int64 Fd (IO Iter) & | Done Int64 "All three constructors provide an  which represents the D number of bytes sent for that particular iteration. (Not the total  byte count). The  and  constructors provide   as their D final argument. Running this IO action will send the next block of  data. The  constructor also provides the  for the output 4 socket. You should not send anymore data until the  would not - block. The easiest way to do that is to use  to  suspend the thread until the  is available. :A very simple function to drive the Iter might look like:    runIter :: IO Iter -> IO ()  runIter iter =  do r <- iter  case r of % (Done _n) -> return () ( (Sent _n cont) -> runIter cont % (WouldBlock _n fd cont) -> # do threadWaitWrite fd  runIter cont EYou would use it as the first argument to a *IterWith function, e.g.   ( sendFileIterWith runIter outputSocket "/path/to/file" 2^16 The _ function provided by this module is similar, but also returns the total number of bytes sent. NOTE: You must not use the  or the   after the call A to *IterWith has returned. When the *IterWith functions return, ? the file descriptors may be closed due to finalizers running. &number of bytes sent, no more to send «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 ?number of bytes sent this pass and a continuation to send more 4A simple function to drive the *IterWith functions. , It returns the total number of bytes sent. 'automatically loop and send everything a way to send things in chunks 0file descriptor corresponding to network socket &file descriptor corresponding to file (maximum number of bytes to send at once offset into file total number of bytes to send 0file descriptor corresponding to network socket &file descriptor corresponding to file (maximum number of bytes to send at once offset into file total number of bytes to send !"low-level wrapper around sendfile  non-blocking N returns number of bytes written and whether the fd would block (aka, EAGAIN)  does not call threadWaitWrite "#$!!%&'() The output handle The input filepath The offset to start at The number of bytes to send The output handle The input filepath maximum block size The offset to start at The number of bytes to send *wraps sendFile' to check arguments      +The length (in bytes) which should be sent )The file offset (in bytes) to start from 1The simplest interface. Simply give it an output + and the , to the input file. The output socket &The path where the input file resides 1The simplest interface. Simply give it an output + and the , to the input file. ?This variant takes a function to drive the iteration loop. See  for more information. The output socket &The path where the input file resides 0Maximum bytes to send per block (may send less) ÿRA more powerful interface than sendFile which accepts a starting offset, and the bytecount to send; the offset and the count must be a positive integer. The initial position of the input file handle matters not since the offset is absolute, and the final position may be different depending on the platform -- no assumptions can be made. The output socket The input file handle The offset to start at The number of bytes to send ÿRA more powerful interface than sendFile which accepts a starting offset, and the bytecount to send; the offset and the count must be a positive integer. The initial position of the input file handle matters not since the offset is absolute, and the final position may be different depending on the platform -- no assumptions can be made. ?This variant takes a function to drive the iteration loop. See  for more information. The output socket The input file handle 0Maximum bytes to send per block (may send less) The offset to start at The number of bytes to send /The unsafe version of sendFile which accepts a - instead of a +P for the output. It will flush the output handle before sending any file data. The output handle &The path where the input file resides /The unsafe version of sendFile which accepts a - instead of a +P for the output. It will flush the output handle before sending any file data. ?This variant takes a function to drive the iteration loop. See  for more information. The output handle &The path where the input file resides 0Maximum bytes to send per block (may send less) The unsafe version of sendFile' which accepts a - instead of a +O for the output. It will flush the output handle before sending any file data. The output handle The input filepath The offset to start at The number of bytes to send The unsafe version of sendFile' which accepts a - instead of a +O for the output. It will flush the output handle before sending any file data. ?This variant takes a function to drive the iteration loop. See  for more information. The output handle The input filepath The number of bytes to send The offset to start at The number of bytes to send LReturns the mode that sendfile was compiled with. Mainly for debugging use.  Possible values are WIN32_SENDFILE, LINUX_SENDFILE, FREEBSD_SENDFILE,  DARWIN_SENDFILE, and PORTABLE_SENDFILE. )The mode that sendfile was compiled with  .          !"#$%&'()*+,-./01234sendfile-0.7.0Network.Socket.SendFile.Iter Network.Socket.SendFile.InternalNetwork.Socket.SendFileNetwork.Socket.SendFile.LinuxIterDone WouldBlockSentrunIter sendFileModesendFilesendFileIterWith sendFile'sendFileIterWith'unsafeSendFileunsafeSendFileIterWithunsafeSendFile'unsafeSendFileIterWith' ByteCountOffsetbaseGHC.IntInt64ghc-prim GHC.TypesIOSystem.Posix.TypesFdControl.ConcurrentthreadWaitWrite c_sendfile _sendFile sendFileIter sendFileIterIsendfile sendfileI safeMinusmaxBytes sendFile''sendFileIterWith''unsafeSendFile''unsafeSendFileIterWith''withFd wrapSendFile'network-2.2.1.7Network.SocketSocketGHC.IOFilePathGHC.IO.Handle.TypesHandle