network-stream-0.1.0: ByteString and Text streams for networking

Network.ByteString.Stream

Description

Network streams for use with strict ByteStrings. For lazy ByteString's, see Network.ByteString.Lazy.Stream. Use this module with Serialize to send data over a stream without worrying about sending and receiving the lengths.

One can also send data in chunks, sending data whenever it is ready, and the data will be collected transparently to the client interface.

Synopsis

Documentation

data Result a Source

Represents whether the stream transaction was a success or a failure; nothing is done by the library with the attached value. If you do not need to send back a value to the caller of withStream, you can use a Result ().

Constructors

Success a 
Failure a 

Instances

Read a => Read (Result a) 
Show a => Show (Result a) 

data Stream Source

The core data type for a Stream. It can only be created using withStream.

invalidate :: Stream -> IO ()Source

Doesn't fail, but tells the client that all the data sent by the stream so far has been invalidated, and hence the queue of messages to be sent is cleared.

withStream :: Handle -> (Stream -> IO (Result a)) -> IO aSource

Opens a stream using the given handle and passes it to the function, and then unwraps the result given and gives any user data that the specific function wants to give back.

write :: Stream -> ByteString -> IO ()Source

Writes partial or full data over a Stream, placing it in the queue of all of the partial data.

send :: Serialize a => Handle -> a -> IO ()Source

Serializes data and sends it over a newly created Stream.

receive :: Handle -> IO (Maybe ByteString)Source

Receives a ByteString sent via a Stream.

receiveE :: MonadIO m => Handle -> Iteratee ByteString m b -> m (Maybe b)Source

Enumerator-based version of receive that allows the client to fold over the data as it is being received. Each ByteString is a single chunk sent from write. Keep in mind that any IO performed is dangerous if you are possibly expected an Invalidation, since then that IO could end up being incorrect. Hence, it is more useful to simply use this in a pure manner to build up some result data as the bytes are being streamed in.