gi-gio-2.0.19: Gio bindings

Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com)
Safe Haskell | None
Language | Haskell2010

GI.Gio.Objects.ThreadedSocketService

Contents

- Exported types
- Methods
  - new
- Properties
  - maxThreads
- Signals
  - run

Description

A `ThreadedSocketService` is a simple subclass of `SocketService` that handles incoming connections by creating a worker thread and dispatching the connection to it by emitting the `ThreadedSocketService`::`run` signal in the new thread.

The signal handler may perform blocking IO and need not return until the connection is closed.

The service is implemented using a thread pool, so there is a limited amount of threads available to serve incoming requests. The service automatically stops the `SocketService` from accepting new connections when all threads are busy.

As with `SocketService`, you may connect to `ThreadedSocketService`::`run`, or subclass and override the default handler.

Since: 2.22

Synopsis

- newtype ThreadedSocketService = ThreadedSocketService (ManagedPtr ThreadedSocketService)
- class GObject o => IsThreadedSocketService o
- toThreadedSocketService :: (MonadIO m, IsThreadedSocketService o) => o -> m ThreadedSocketService
- noThreadedSocketService :: Maybe ThreadedSocketService
- threadedSocketServiceNew :: (HasCallStack, MonadIO m) => Int32 -> m ThreadedSocketService
- constructThreadedSocketServiceMaxThreads :: IsThreadedSocketService o => Int32 -> IO (GValueConstruct o)
- getThreadedSocketServiceMaxThreads :: (MonadIO m, IsThreadedSocketService o) => o -> m Int32
- type C_ThreadedSocketServiceRunCallback = Ptr () -> Ptr SocketConnection -> Ptr Object -> Ptr () -> IO CInt
- type ThreadedSocketServiceRunCallback = SocketConnection -> Object -> IO Bool
- afterThreadedSocketServiceRun :: (IsThreadedSocketService a, MonadIO m) => a -> ThreadedSocketServiceRunCallback -> m SignalHandlerId
- genClosure_ThreadedSocketServiceRun :: ThreadedSocketServiceRunCallback -> IO Closure
- mk_ThreadedSocketServiceRunCallback :: C_ThreadedSocketServiceRunCallback -> IO (FunPtr C_ThreadedSocketServiceRunCallback)
- noThreadedSocketServiceRunCallback :: Maybe ThreadedSocketServiceRunCallback
- onThreadedSocketServiceRun :: (IsThreadedSocketService a, MonadIO m) => a -> ThreadedSocketServiceRunCallback -> m SignalHandlerId
- wrap_ThreadedSocketServiceRunCallback :: ThreadedSocketServiceRunCallback -> C_ThreadedSocketServiceRunCallback

# Exported types

newtype ThreadedSocketService Source #

Memory-managed wrapper type.

Constructors

ThreadedSocketService (ManagedPtr ThreadedSocketService) |

Instances

GObject ThreadedSocketService Source # |
Instance details Defined in GI.Gio.Objects.ThreadedSocketService Methods gobjectType :: ThreadedSocketService -> IO GType Source #
IsObject ThreadedSocketService Source # |
Instance details Defined in GI.Gio.Objects.ThreadedSocketService
IsSocketListener ThreadedSocketService Source # |
Instance details Defined in GI.Gio.Objects.ThreadedSocketService
IsSocketService ThreadedSocketService Source # |
Instance details Defined in GI.Gio.Objects.ThreadedSocketService
IsThreadedSocketService ThreadedSocketService Source # |
Instance details Defined in GI.Gio.Objects.ThreadedSocketService

class GObject o => IsThreadedSocketService o Source #

Type class for types which can be safely cast to `ThreadedSocketService`, for instance with `toThreadedSocketService`.

Instances

(GObject a, (UnknownAncestorError ThreadedSocketService a :: Constraint)) => IsThreadedSocketService a Source # |
Instance details Defined in GI.Gio.Objects.ThreadedSocketService
IsThreadedSocketService ThreadedSocketService Source # |
Instance details Defined in GI.Gio.Objects.ThreadedSocketService

toThreadedSocketService :: (MonadIO m, IsThreadedSocketService o) => o -> m ThreadedSocketService Source #

Cast to `ThreadedSocketService`, for types for which this is known to be safe. For general casts, use `castTo`.

noThreadedSocketService :: Maybe ThreadedSocketService Source #

A convenience alias for `Nothing` :: `Maybe` `ThreadedSocketService`.

# Methods

## new

threadedSocketServiceNew Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Int32 | `maxThreads`: the maximal number of threads to execute concurrently handling incoming clients, -1 means no limit
-> m ThreadedSocketService | Returns: a new `SocketService`.

Creates a new `ThreadedSocketService` with no listeners. Listeners must be added with one of the `SocketListener` "add" methods.

Since: 2.22

# Properties

## maxThreads

No description available in the introspection data.

constructThreadedSocketServiceMaxThreads :: IsThreadedSocketService o => Int32 -> IO (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`max-threads`” property. This is rarely needed directly, but it is used by `new`.

getThreadedSocketServiceMaxThreads :: (MonadIO m, IsThreadedSocketService o) => o -> m Int32 Source #

Get the value of the “`max-threads`” property. When overloading is enabled, this is equivalent to

    get threadedSocketService #maxThreads

# Signals

## run

type C_ThreadedSocketServiceRunCallback = Ptr () -> Ptr SocketConnection -> Ptr Object -> Ptr () -> IO CInt Source #

Type for the callback on the (unwrapped) C side.

type ThreadedSocketServiceRunCallback Source #

Arguments

= SocketConnection | `connection`: a new `SocketConnection` object.
-> Object | `sourceObject`: the source_object passed to `socketListenerAddAddress`.
-> IO Bool | Returns: `True` to stop further signal handlers from being called

The ::run signal is emitted in a worker thread in response to an incoming connection. This thread is dedicated to handling `connection` and may perform blocking IO. The signal handler need not return until the connection is closed.

afterThreadedSocketServiceRun :: (IsThreadedSocketService a, MonadIO m) => a -> ThreadedSocketServiceRunCallback -> m SignalHandlerId Source #

Connect a signal handler for the “`run`” signal, to be run after the default handler. When overloading is enabled, this is equivalent to

    after threadedSocketService #run callback

genClosure_ThreadedSocketServiceRun :: ThreadedSocketServiceRunCallback -> IO Closure Source #

Wrap the callback into a `Closure`.

mk_ThreadedSocketServiceRunCallback :: C_ThreadedSocketServiceRunCallback -> IO (FunPtr C_ThreadedSocketServiceRunCallback) Source #

Generate a function pointer callable from C code, from a `C_ThreadedSocketServiceRunCallback`.

noThreadedSocketServiceRunCallback :: Maybe ThreadedSocketServiceRunCallback Source #

A convenience synonym for ``Nothing` :: `Maybe` `ThreadedSocketServiceRunCallback``.

onThreadedSocketServiceRun :: (IsThreadedSocketService a, MonadIO m) => a -> ThreadedSocketServiceRunCallback -> m SignalHandlerId Source #

Connect a signal handler for the “`run`” signal, to be run before the default handler. When overloading is enabled, this is equivalent to

    on threadedSocketService #run callback

wrap_ThreadedSocketServiceRunCallback :: ThreadedSocketServiceRunCallback -> C_ThreadedSocketServiceRunCallback Source #

Wrap a `ThreadedSocketServiceRunCallback` into a `C_ThreadedSocketServiceRunCallback`.