Pipelining is sending multiple requests over a socket and receiving the responses later, in the same order. This is faster than sending one request, waiting for the response, then sending the next request, and so on. This implementation returns a promise (future) response for each request that when invoked waits for the response if not already arrived. Multiple threads can send on the same pipe (and get promises back); the pipe will pipeline each thread's request right away without waiting.
- data Pipe handle bytes
- newPipe :: (Stream h b, Resource IO h) => (Size -> b) -> (b -> Size) -> h -> IO (Pipe h b)
- send :: Stream h b => Pipe h b -> [b] -> IO ()
- call :: Stream h b => Pipe h b -> [b] -> IO (IO b)
- type Size = Int
- class Length list where
- class Resource m r where
- class Flush handle where
- class (Length bytes, Monoid bytes, Flush handle) => Stream handle bytes where
- getN :: Stream h b => h -> Int -> IO b
Thread-safe and pipelined socket
|:: (Stream h b, Resource IO h)|
|=> (Size -> b)|
Convert Size to bytes of fixed length. Every Int must translate to same number of bytes.
|-> (b -> Size)|
Convert bytes of fixed length to Size. Must be exact inverse of encodeSize.
Underlying socket (handle) this pipe will read/write from
|-> IO (Pipe h b)|
Create new Pipe with given encodeInt, decodeInt, and handle. You should
close pipe when finished, which will also close handle. If pipe is not closed but eventually garbage collected, it will be closed along with handle.
Send messages all together to destination (no messages will be interleaved between them). None of the messages can induce a response, i.e. the destination must not reply to any of these messages (otherwise future
calls will get these responses instead of their own).
Each message is preceeded by its length when written to socket.
Send messages all together to destination (no messages will be interleaved between them), and return promise of response from one message only. One and only one message in the list must induce a response, i.e. the destination must reply to exactly one message only (otherwise promises will have the wrong responses in them). Each message is preceeded by its length when written to socket. Likewise, the response must be preceeded by its length.
Write bytes to handle
Read up to N bytes from handle, block until at least 1 byte is available