mongoDB-0.7.1: A driver for MongoDB

Control.Pipeline

Contents

Description

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.

Synopsis

Pipe

data Pipe handle bytes Source

Thread-safe and pipelined socket

Instances

Resource IO h => Resource IO (Pipe h b) 

newPipeSource

Arguments

:: (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.

-> h

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 :: Stream h b => Pipe h b -> [b] -> IO ()Source

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.

call :: Stream h b => Pipe h b -> [b] -> IO (IO b)Source

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.

Util

class Length list whereSource

Methods

length :: list -> SizeSource

class Resource m r whereSource

Methods

close :: r -> m ()Source

Close resource

isClosed :: r -> m BoolSource

Is resource closed

Instances

class Flush handle whereSource

Methods

flush :: handle -> IO ()Source

Flush written bytes to destination

Instances

class (Length bytes, Monoid bytes, Flush handle) => Stream handle bytes whereSource

Methods

put :: handle -> bytes -> IO ()Source

Write bytes to handle

get :: handle -> Int -> IO bytesSource

Read up to N bytes from handle; if EOF return empty bytes, otherwise block until at least 1 byte is available

getN :: Stream h b => h -> Int -> IO bSource

Read N bytes from hande, blocking until all N bytes are read. If EOF is reached before N bytes then throw EOF exception.