Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Extensions |
|
Class using type families to represent abstract connection types that (in addition to the usual network operations) can be upgraded from insecure to secure.
Any instance must specify:
, the type of parameters that can be used to open a connection. (This might be a just a tuple containing just hostname and port, say, or might be some more complicated structure.)Params
, the constraints the methods require. For instance, aCstrt
Connection
using real network operations would likely haveMonadIO
as a constraint.- Implementations for
open
,close
,send
,recv
andupgrade
. These are typically very thin wrappers around the operations provided by a network library.
Synopsis
- class Connection c where
- withConnection :: (MonadMask m, Cstrt c m, Connection c) => Params c -> (c -> m b) -> m b
Documentation
class Connection c where Source #
Class for abstract connections over some
transport channel c
.
type Cstrt c :: (* -> *) -> Constraint Source #
Constraints an implementation must satisfy.
(e.g., MonadIO
for network-based connections.)
Parameters used to create a connection -- e.g. hostname, port, TLS settings, etc.
:: Cstrt c m | |
=> c | |
-> m () | close a connection |
:: Cstrt c m | |
=> c | |
-> ByteString | |
-> m () | send a bytestring |
:: Cstrt c m | |
=> c | |
-> m ByteString | receive a bytestring |
:: Cstrt c m | |
=> c | |
-> m () | upgrade security |
withConnection :: (MonadMask m, Cstrt c m, Connection c) => Params c -> (c -> m b) -> m b Source #
withConnection p a
bracket
for Connection
s.
Given some parameters p
for opening a connection:
open a connection, run some action a
with it, then
close.