websockets-0.13.0.0: A sensible and clean way to write WebSocket-capable servers in Haskell.

Safe Haskell | None
Language | Haskell2010

Network.WebSockets.Stream

Description

Lightweight abstraction over an input/output stream.

Synopsis

- data Stream
- makeStream :: IO (Maybe ByteString) -> (Maybe ByteString -> IO ()) -> IO Stream
- makeSocketStream :: Socket -> IO Stream
- makeEchoStream :: IO Stream
- parse :: Stream -> Parser a -> IO (Maybe a)
- parseBin :: Stream -> Get a -> IO (Maybe a)
- write :: Stream -> ByteString -> IO ()
- close :: Stream -> IO ()

# Documentation

data Stream Source #

Lightweight abstraction over an input/output stream.

makeStream Source #

Arguments

:: IO (Maybe ByteString) | Reading
-> (Maybe ByteString -> IO ()) | Writing
-> IO Stream | Resulting stream

Create a stream from a "receive" and "send" action. The following properties apply:

- Regardless of the provided "receive" and "send" functions, reading and writing from the stream will be thread-safe, i.e. this function will create a receive and write lock to be used internally.
- Reading from or writing to a closed `Stream` will always throw an exception, even if the underlying "receive" and "send" functions do not (we do the bookkeeping).
- Streams should always be closed.

makeSocketStream :: Socket -> IO Stream Source #

makeEchoStream :: IO Stream Source #

parse :: Stream -> Parser a -> IO (Maybe a) Source #

parseBin :: Stream -> Get a -> IO (Maybe a) Source #

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

close :: Stream -> IO () Source #