reflex-backend-socket-0.2.0.0: Reflex bindings for TCP sockets

Copyright(c) 2018-2019 Commonwealth Scientific and Industrial Research Organisation
LicenseBSD3
Maintainerdave.laing.80@gmail.com, jack.kelly@data61.csiro.au
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Reflex.Backend.Socket

Contents

Description

Use socket to wrap a network Socket so that it sends out the firings of an Event t ByteString, and fires any data that it receives on another Event t ByteString.

Synopsis

Documentation

socket :: forall t m. (Reflex t, PerformEvent t m, PostBuild t m, TriggerEvent t m, MonadIO (Performable m), MonadIO m) => SocketConfig t -> m (Socket t) Source #

Wire a socket into the FRP network. You will likely use this to attach events to a socket that you just connected (from connect), or a socket that you just accepted (from the _aAcceptSocket event you got when you called accept).

Socket configuration

data SocketConfig t Source #

Holds the socket to wire into the FRP network, and events that drive it.

Constructors

SocketConfig 

Fields

  • _scInitSocket :: Socket

    Socket to wrap.

  • _scMaxRx :: Int

    Maximum number of bytes to read at a time.

  • _scSend :: Event t ByteString

    Data to send out on this socket.

  • _scClose :: Event t ()

    Ask to close the socket. The socket will stop trying to receive data (and the _sReceive event will stop firing), and the socket will be "drained": future events on _scSend will be ignored, and it will close after writing all pending data. If _scSend and _scClose fire in the same frame, the data will nevertheless be queued for sending.

Socket output events

data Socket t Source #

Events produced by an active socket.

Constructors

Socket 

Fields

  • _sReceive :: Event t ByteString

    Data has arrived.

  • _sOpen :: Event t ()

    The socket has opened, and its receive/send loops are running.

  • _sClose :: Event t ()

    The socket has closed. This will fire exactly once when the socket closes for any reason, including if your _scClose event fires, the other end disconnects, or if the socket closes in response to a caught exception.

  • _sError :: Event t IOException

    An exception occurred. Treat the socket as closed after you see this. If the socket was open, you will see the _sClose event fire as well, but not necessarily in the same frame.

Lenses

SocketConfig

scClose :: forall t. Lens' (SocketConfig t) (Event t ()) Source #

Socket

sOpen :: forall t. Lens' (Socket t) (Event t ()) Source #

sClose :: forall t. Lens' (Socket t) (Event t ()) Source #

sError :: forall t. Lens' (Socket t) (Event t IOException) Source #

Convenience re-exports