base-4.18.1.0: Basic libraries

Safe Haskell | Trustworthy
Language | Haskell2010

GHC.Event

Contents

- Types
- Creation
- Registering interest in I/O events
- Registering interest in timeout events

Description

This module provides scalable event notification for file descriptors and timeouts.

This module should be considered GHC internal.

- ---------------------------------------------------------------------------

Synopsis

- data EventManager
- data TimerManager
- getSystemEventManager :: IO (Maybe EventManager)
- new :: IO EventManager
- getSystemTimerManager :: IO TimerManager
- data Event
- evtRead :: Event
- evtWrite :: Event
- type IOCallback = FdKey -> Event -> IO ()
- data FdKey
- data Lifetime
  - = OneShot
  - | MultiShot
- registerFd :: EventManager -> IOCallback -> Fd -> Event -> Lifetime -> IO FdKey
- unregisterFd :: EventManager -> FdKey -> IO ()
- unregisterFd_ :: EventManager -> FdKey -> IO Bool
- closeFd :: EventManager -> (Fd -> IO ()) -> Fd -> IO ()
- type TimeoutCallback = IO ()
- data TimeoutKey
- registerTimeout :: TimerManager -> Int -> TimeoutCallback -> IO TimeoutKey
- updateTimeout :: TimerManager -> TimeoutKey -> Int -> IO ()
- unregisterTimeout :: TimerManager -> TimeoutKey -> IO ()

# Types

data EventManager Source #

The event manager state.

data TimerManager Source #

The event manager state.

# Creation

getSystemEventManager :: IO (Maybe EventManager) Source #

Retrieve the system event manager for the capability on which the calling thread is running.

This function always returns `Just` the current thread's event manager when using the threaded RTS and `Nothing` otherwise.

new :: IO EventManager Source #

Create a new event manager.

getSystemTimerManager :: IO TimerManager Source #

# Registering interest in I/O events

data Event Source #

An I/O event.

#### Instances

Instances details

Monoid Event Source # | Since: base-4.4.0.0
Instance details Defined in GHC.Event.Internal.Types Methods mempty :: Event Source # mappend :: Event -> Event -> Event Source # mconcat :: [Event] -> Event Source #
Semigroup Event Source # | Since: base-4.10.0.0
Instance details Defined in GHC.Event.Internal.Types Methods (<>) :: Event -> Event -> Event Source # sconcat :: NonEmpty Event -> Event Source # stimes :: Integral b => b -> Event -> Event Source #
Show Event Source # | Since: base-4.4.0.0
Instance details Defined in GHC.Event.Internal.Types Methods showsPrec :: Int -> Event -> ShowS Source # show :: Event -> String Source # showList :: [Event] -> ShowS Source #
Eq Event Source # | Since: base-4.4.0.0
Instance details Defined in GHC.Event.Internal.Types Methods (==) :: Event -> Event -> Bool Source # (/=) :: Event -> Event -> Bool Source #

evtRead :: Event Source #

Data is available to be read.

evtWrite :: Event Source #

The file descriptor is ready to accept a write.

type IOCallback = FdKey -> Event -> IO () Source #

Callback invoked on I/O events.

data FdKey Source #

A file descriptor registration cookie.

#### Instances

Instances details

Show FdKey Source # | Since: base-4.4.0.0
Instance details Defined in GHC.Event.Manager Methods showsPrec :: Int -> FdKey -> ShowS Source # show :: FdKey -> String Source # showList :: [FdKey] -> ShowS Source #
Eq FdKey Source # | Since: base-4.4.0.0
Instance details Defined in GHC.Event.Manager Methods (==) :: FdKey -> FdKey -> Bool Source # (/=) :: FdKey -> FdKey -> Bool Source #

data Lifetime Source #

The lifetime of an event registration.

Since: base-4.8.1.0

Constructors

OneShot | the registration will be active for only one event
MultiShot | the registration will trigger multiple times

#### Instances

Instances details

Monoid Lifetime Source # | `mappend` takes the longer of two lifetimes. Since: base-4.8.0.0
Instance details Defined in GHC.Event.Internal.Types Methods mempty :: Lifetime Source # mappend :: Lifetime -> Lifetime -> Lifetime Source # mconcat :: [Lifetime] -> Lifetime Source #
Semigroup Lifetime Source # | Since: base-4.10.0.0
Instance details Defined in GHC.Event.Internal.Types Methods (<>) :: Lifetime -> Lifetime -> Lifetime Source # sconcat :: NonEmpty Lifetime -> Lifetime Source # stimes :: Integral b => b -> Lifetime -> Lifetime Source #
Show Lifetime Source # | Since: base-4.8.1.0
Instance details Defined in GHC.Event.Internal.Types Methods showsPrec :: Int -> Lifetime -> ShowS Source # show :: Lifetime -> String Source # showList :: [Lifetime] -> ShowS Source #
Eq Lifetime Source # | Since: base-4.8.1.0
Instance details Defined in GHC.Event.Internal.Types Methods (==) :: Lifetime -> Lifetime -> Bool Source # (/=) :: Lifetime -> Lifetime -> Bool Source #

registerFd :: EventManager -> IOCallback -> Fd -> Event -> Lifetime -> IO FdKey Source #

`registerFd mgr cb fd evs lt` registers interest in the events `evs` on the file descriptor `fd` for lifetime `lt`. `cb` is called for each event that occurs. Returns a cookie that can be handed to `unregisterFd`.

unregisterFd :: EventManager -> FdKey -> IO () Source #

Drop a previous file descriptor registration.

unregisterFd_ :: EventManager -> FdKey -> IO Bool Source #

Drop a previous file descriptor registration, without waking the event manager thread. The return value indicates whether the event manager ought to be woken.

closeFd :: EventManager -> (Fd -> IO ()) -> Fd -> IO () Source #

Close a file descriptor in a race-safe way. It might block, although for a very short time; and thus it is interruptible by asynchronous exceptions.

# Registering interest in timeout events

type TimeoutCallback = IO () Source #

Warning: since the `TimeoutCallback` is called from the I/O manager, it must not throw an exception or block for a long period of time. In particular, be wary of `throwTo` and `killThread`: if the target thread is making a foreign call, these functions will block until the call completes.

data TimeoutKey Source #

A timeout registration cookie.

#### Instances

Instances details

Eq TimeoutKey Source # |
Instance details Defined in GHC.Event.TimeOut Methods (==) :: TimeoutKey -> TimeoutKey -> Bool Source # (/=) :: TimeoutKey -> TimeoutKey -> Bool Source #
Ord TimeoutKey Source # |

Instance details

Defined in GHC.Event.TimeOut

Methods

compare :: TimeoutKey -> TimeoutKey -> Ordering Source #

(<) :: TimeoutKey -> TimeoutKey -> Bool Source #

(<=) :: TimeoutKey -> TimeoutKey -> Bool Source #

(>) :: TimeoutKey -> TimeoutKey -> Bool Source #

(>=) :: TimeoutKey -> TimeoutKey -> Bool Source #

max :: TimeoutKey -> TimeoutKey -> TimeoutKey Source #

min :: TimeoutKey -> TimeoutKey -> TimeoutKey Source #

registerTimeout :: TimerManager -> Int -> TimeoutCallback -> IO TimeoutKey Source #

Register a timeout in the given number of microseconds. The returned `TimeoutKey` can be used to later unregister or update the timeout. The timeout is automatically unregistered after the given time has passed.

Be careful not to exceed `maxBound :: Int`, which on 32-bit machines is only 2147483647 μs, less than 36 minutes.

updateTimeout :: TimerManager -> TimeoutKey -> Int -> IO () Source #

Update an active timeout to fire in the given number of microseconds.

Be careful not to exceed `maxBound :: Int`, which on 32-bit machines is only 2147483647 μs, less than 36 minutes.

unregisterTimeout :: TimerManager -> TimeoutKey -> IO () Source #

Unregister an active timeout.