Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Ouroboros.Network.Server.Socket
Synopsis
- data AcceptedConnectionsLimit = AcceptedConnectionsLimit {}
- data AcceptConnectionsPolicyTrace
- type BeginConnection addr channel st r = Time → addr → st → STM (HandleConnection channel st r)
- data HandleConnection channel st r where
- Reject ∷ !st → HandleConnection channel st r
- Accept ∷ !st → !(channel → IO r) → HandleConnection channel st r
- type ApplicationStart addr st = addr → Async () → st → STM st
- type CompleteConnection addr st tr r = Result addr r → st → STM (CompleteApplicationResult IO addr st)
- data CompleteApplicationResult m addr s = CompleteApplicationResult {
- carState ∷ !s
- carThreads ∷ Set (Async m ())
- carTrace ∷ Maybe (WithAddr addr ErrorPolicyTrace)
- data Result addr r = Result {
- resultThread ∷ !(Async ())
- resultAddr ∷ !addr
- resultTime ∷ !Time
- resultValue ∷ !(Either SomeException r)
- type Main st t = st → STM t
- run ∷ Tracer IO (WithAddr addr ErrorPolicyTrace) → Tracer IO AcceptConnectionsPolicyTrace → Socket addr channel → AcceptedConnectionsLimit → (IOException → IO ()) → BeginConnection addr channel st r → ApplicationStart addr st → CompleteConnection addr st tr r → Main st t → TVar st → IO t
- data Socket addr channel = Socket {
- acceptConnection ∷ IO (addr, channel, IO (), Socket addr channel)
- ioSocket ∷ IO (addr, channel) → Socket addr channel
Documentation
data AcceptedConnectionsLimit Source #
Policy which governs how to limit the number of accepted connections.
Constructors
AcceptedConnectionsLimit | |
Fields
|
Instances
data AcceptConnectionsPolicyTrace Source #
Trace for the AcceptConnectionsLimit
policy.
Constructors
ServerTraceAcceptConnectionRateLimiting DiffTime Int | |
ServerTraceAcceptConnectionHardLimit Word32 | |
ServerTraceAcceptConnectionResume Int |
Instances
type BeginConnection addr channel st r = Time → addr → st → STM (HandleConnection channel st r) Source #
What to do on a new connection: accept and run this IO
, or reject.
data HandleConnection channel st r where Source #
What to do with a new connection: reject it and give a new state, or
accept it and give a new state with a continuation to run against the
resulting channel.
See also CompleteConnection
, which is run for every connection when it finishes, and
can also update the state.
Constructors
Reject ∷ !st → HandleConnection channel st r | |
Accept ∷ !st → !(channel → IO r) → HandleConnection channel st r |
type ApplicationStart addr st = addr → Async () → st → STM st Source #
A call back which runs when application starts;
It is needed only because BeginConnection
does not have access to the
thread which runs the application.
type CompleteConnection addr st tr r = Result addr r → st → STM (CompleteApplicationResult IO addr st) Source #
How to update state when a connection finishes. Can use throwSTM
to
terminate the server.
TODO: remove async
, use `Async m ()` from MonadAsync
.
data CompleteApplicationResult m addr s Source #
Constructors
CompleteApplicationResult | |
Fields
|
Instances
Functor (CompleteApplicationResult m addr) Source # | |
Defined in Ouroboros.Network.ErrorPolicy Methods fmap ∷ (a → b) → CompleteApplicationResult m addr a → CompleteApplicationResult m addr b Source # (<$) ∷ a → CompleteApplicationResult m addr b → CompleteApplicationResult m addr a Source # |
The product of a spawned thread. We catch all (even async) exceptions.
Constructors
Result | |
Fields
|
type Main st t = st → STM t Source #
Given a current state, retry
unless you want to stop the server.
When this transaction returns, any running threads spawned by the server
will be killed.
It's possible that a connection is accepted after the main thread
returns, but before the server stops. In that case, it will be killed, and
the CompleteConnection
will not run against it.
run ∷ Tracer IO (WithAddr addr ErrorPolicyTrace) → Tracer IO AcceptConnectionsPolicyTrace → Socket addr channel → AcceptedConnectionsLimit → (IOException → IO ()) → BeginConnection addr channel st r → ApplicationStart addr st → CompleteConnection addr st tr r → Main st t → TVar st → IO t Source #
Run a server.
data Socket addr channel Source #
Abstraction of something that can provide connections.
A Socket
can be used to get a
`Socket SockAddr (Channel IO Lazy.ByteString)`
It's not defined in here, though, because we don't want the dependency
on typed-protocols or even on network.
Constructors
Socket | |
Fields
|