bert-1.2.2.5: BERT implementation

Safe HaskellNone
LanguageHaskell2010

Network.BERT.Transport

Contents

Description

Underlying transport abstraction

Synopsis

Core definitions

class Transport t where Source

The class for transports

Methods

runSession :: t -> TransportM a -> IO a Source

closeConnection :: t -> IO () Source

Instances

class Transport (ServerTransport s) => Server s where Source

Associated Types

type ServerTransport s Source

The underlying transport used by the server

Methods

runServer :: s -> (ServerTransport s -> IO ()) -> IO () Source

This method should listen for incoming requests, establish some sort of a connection (represented by the transport) and then invoke the handling function

cleanup :: s -> IO () Source

Free any resources that the server has acquired (such as the listening socket)

type TransportM = ReaderT SendPacketFn (ConduitM Packet Void IO) Source

The transport monad allows receiving packets through the conduit, and sending functions via the provided SendPacketFn

type SendPacketFn = Packet -> IO () Source

A function to send packets to the peer

Sending and receiving packets

sendt :: Term -> TransportM () Source

Send a term

recvt :: TransportM (Maybe Term) Source

Receive a term

recvtForever :: (Term -> TransportM a) -> TransportM () Source

Execute an action for every incoming term, until the connection is closed

TCP transport

data TCP Source

The TCP transport

Constructors

TCP 

Fields

getTcpSocket :: !Socket

The socket used for communication.

The connection is assumed to be already established when this structure is passed in.

Instances

tcpClient :: HostName -> PortNumber -> IO TCP Source

Establish a connection to the TCP server and return the resulting transport. It can be used to make multiple requests.

data TCPServer Source

The TCP server

Constructors

TCPServer 

Fields

getTcpListenSocket :: !Socket

The listening socket. Assumed to be bound but not listening yet.

tcpServer :: PortNumber -> IO TCPServer Source

A simple TCPServer constructor, listens on all local interfaces.

If you want to bind only to some of the interfaces, create the socket manually using the functions from Network.Socket.

Utilities

resolve :: HostName -> IO HostAddress Source

A simple address resolver