sandwich-contexts-0.3.0.3: Contexts for the Sandwich test library
Safe HaskellNone
LanguageHaskell2010

Test.Sandwich.Contexts.Util.Ports

Description

Helper module for finding free ports, with various options for port ranges, retries, and excluded ports.

Synopsis

Documentation

Exception-throwing versions

findFreePortOrException :: (MonadIO m, MonadCatch m) => m PortNumber Source #

Find a free port in the ephemeral range, throwing an exception if one isn't found.

findFreePortOrException' :: (MonadIO m, MonadCatch m) => (PortNumber -> Bool) -> m PortNumber Source #

Same as findFreePortOrException, but with a callback to test if the port is acceptable or not.

Lower-level

findFreePortInRange Source #

Arguments

:: (MonadIO m, MonadCatch m) 
=> (PortNumber, PortNumber)

Candidate port range

-> [PortNumber]

Ports to exclude

-> m (Maybe PortNumber) 

Find an unused port in a given range, excluding certain ports. If the retries time out, returns Nothing.

findFreePortInRange' Source #

Arguments

:: (MonadIO m, MonadCatch m) 
=> RetryPolicy

Retry policy

-> (PortNumber, PortNumber)

Candidate port range

-> [PortNumber]

Ports to exclude

-> m (Maybe PortNumber) 

Same as findFreePortInRange, but with a configurable retry policy.

Lower-level

isPortFree :: (MonadIO m, MonadCatch m) => PortNumber -> m Bool Source #

Test if a given PortNumber is currently available.

tryOpenAndClosePort :: MonadIO m => PortNumber -> m PortNumber Source #

Test a given PortNumber availability by trying to open and close a socket on it. Throws an exception on failure.