gi-gio
CopyrightWill Thompson and Iñaki García Etxebarria
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellNone
LanguageHaskell2010

GI.Gio.Objects.SocketService

Description

A GSocketService is an object that represents a service that is provided to the network or over local sockets. When a new connection is made to the service the SocketService::incoming signal is emitted.

A GSocketService is a subclass of SocketListener and you need to add the addresses you want to accept connections on with the SocketListener APIs.

There are two options for implementing a network service based on GSocketService. The first is to create the service using socketServiceNew and to connect to the SocketService::incoming signal. The second is to subclass GSocketService and override the default signal handler implementation.

In either case, the handler must immediately return, or else it will block additional incoming connections from being serviced. If you are interested in writing connection handlers that contain blocking code then see ThreadedSocketService.

The socket service runs on the main loop of the thread-default context (see mainContextPushThreadDefault) of the thread it is created in, and is not threadsafe in general. However, the calls to start and stop the service are thread-safe so these can be used from threads that handle incoming clients.

Since: 2.22

Synopsis

Exported types

newtype SocketService Source #

Memory-managed wrapper type.

Instances

Instances details
Eq SocketService Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

GObject SocketService Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

ManagedPtrNewtype SocketService Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

TypedObject SocketService Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

Methods

glibType :: IO GType #

HasParentTypes SocketService Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

HasAttributeList SocketService Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

(info ~ ResolveSocketServiceMethod t SocketService, OverloadedMethod info SocketService p, HasField t SocketService p) => HasField (t :: Symbol) SocketService (p :: Type) Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

Methods

getField :: SocketService -> p #

(info ~ ResolveSocketServiceMethod t SocketService, OverloadedMethodInfo info SocketService) => IsLabel t (MethodProxy info SocketService) Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

(info ~ ResolveSocketServiceMethod t SocketService, OverloadedMethod info SocketService p) => IsLabel t (SocketService -> p) Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

Methods

fromLabel :: SocketService -> p #

IsGValue (Maybe SocketService) Source #

Convert SocketService to and from GValue. See toGValue and fromGValue.

Instance details

Defined in GI.Gio.Objects.SocketService

type AttributeList SocketService Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type ParentTypes SocketService Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type SignalList SocketService Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

class (GObject o, IsDescendantOf SocketService o) => IsSocketService o Source #

Type class for types which can be safely cast to SocketService, for instance with toSocketService.

Instances

Instances details
(GObject o, IsDescendantOf SocketService o) => IsSocketService o Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

toSocketService :: (MonadIO m, IsSocketService o) => o -> m SocketService Source #

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

Methods

type family ResolveSocketServiceMethod (t :: Symbol) o where ... Source #

Equations

ResolveSocketServiceMethod "accept" o = SocketListenerAcceptMethodInfo 
ResolveSocketServiceMethod "acceptAsync" o = SocketListenerAcceptAsyncMethodInfo 
ResolveSocketServiceMethod "acceptFinish" o = SocketListenerAcceptFinishMethodInfo 
ResolveSocketServiceMethod "acceptSocket" o = SocketListenerAcceptSocketMethodInfo 
ResolveSocketServiceMethod "acceptSocketAsync" o = SocketListenerAcceptSocketAsyncMethodInfo 
ResolveSocketServiceMethod "acceptSocketFinish" o = SocketListenerAcceptSocketFinishMethodInfo 
ResolveSocketServiceMethod "addAddress" o = SocketListenerAddAddressMethodInfo 
ResolveSocketServiceMethod "addAnyInetPort" o = SocketListenerAddAnyInetPortMethodInfo 
ResolveSocketServiceMethod "addInetPort" o = SocketListenerAddInetPortMethodInfo 
ResolveSocketServiceMethod "addSocket" o = SocketListenerAddSocketMethodInfo 
ResolveSocketServiceMethod "bindProperty" o = ObjectBindPropertyMethodInfo 
ResolveSocketServiceMethod "bindPropertyFull" o = ObjectBindPropertyFullMethodInfo 
ResolveSocketServiceMethod "close" o = SocketListenerCloseMethodInfo 
ResolveSocketServiceMethod "forceFloating" o = ObjectForceFloatingMethodInfo 
ResolveSocketServiceMethod "freezeNotify" o = ObjectFreezeNotifyMethodInfo 
ResolveSocketServiceMethod "getv" o = ObjectGetvMethodInfo 
ResolveSocketServiceMethod "isActive" o = SocketServiceIsActiveMethodInfo 
ResolveSocketServiceMethod "isFloating" o = ObjectIsFloatingMethodInfo 
ResolveSocketServiceMethod "notify" o = ObjectNotifyMethodInfo 
ResolveSocketServiceMethod "notifyByPspec" o = ObjectNotifyByPspecMethodInfo 
ResolveSocketServiceMethod "ref" o = ObjectRefMethodInfo 
ResolveSocketServiceMethod "refSink" o = ObjectRefSinkMethodInfo 
ResolveSocketServiceMethod "runDispose" o = ObjectRunDisposeMethodInfo 
ResolveSocketServiceMethod "start" o = SocketServiceStartMethodInfo 
ResolveSocketServiceMethod "stealData" o = ObjectStealDataMethodInfo 
ResolveSocketServiceMethod "stealQdata" o = ObjectStealQdataMethodInfo 
ResolveSocketServiceMethod "stop" o = SocketServiceStopMethodInfo 
ResolveSocketServiceMethod "thawNotify" o = ObjectThawNotifyMethodInfo 
ResolveSocketServiceMethod "unref" o = ObjectUnrefMethodInfo 
ResolveSocketServiceMethod "watchClosure" o = ObjectWatchClosureMethodInfo 
ResolveSocketServiceMethod "getData" o = ObjectGetDataMethodInfo 
ResolveSocketServiceMethod "getProperty" o = ObjectGetPropertyMethodInfo 
ResolveSocketServiceMethod "getQdata" o = ObjectGetQdataMethodInfo 
ResolveSocketServiceMethod "setBacklog" o = SocketListenerSetBacklogMethodInfo 
ResolveSocketServiceMethod "setData" o = ObjectSetDataMethodInfo 
ResolveSocketServiceMethod "setDataFull" o = ObjectSetDataFullMethodInfo 
ResolveSocketServiceMethod "setProperty" o = ObjectSetPropertyMethodInfo 
ResolveSocketServiceMethod l o = MethodResolutionFailed l o :: Type 

isActive

socketServiceIsActive Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocketService a) 
=> a

service: a SocketService

-> m Bool

Returns: True if the service is active, False otherwise

Check whether the service is active or not. An active service will accept new clients that connect, while a non-active service will let connecting clients queue up until the service is started.

Since: 2.22

new

socketServiceNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> m SocketService

Returns: a new SocketService.

Creates a new SocketService with no sockets to listen for. New listeners can be added with e.g. socketListenerAddAddress or socketListenerAddInetPort.

New services are created active, there is no need to call socketServiceStart, unless socketServiceStop has been called before.

Since: 2.22

start

socketServiceStart Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocketService a) 
=> a

service: a SocketService

-> m () 

Restarts the service, i.e. start accepting connections from the added sockets when the mainloop runs. This only needs to be called after the service has been stopped from socketServiceStop.

This call is thread-safe, so it may be called from a thread handling an incoming client request.

Since: 2.22

stop

data SocketServiceStopMethodInfo Source #

Instances

Instances details
(signature ~ m (), MonadIO m, IsSocketService a) => OverloadedMethod SocketServiceStopMethodInfo a signature Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

Methods

overloadedMethod :: a -> signature #

OverloadedMethodInfo SocketServiceStopMethodInfo (a :: Type) Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

socketServiceStop Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocketService a) 
=> a

service: a SocketService

-> m () 

Stops the service, i.e. stops accepting connections from the added sockets when the mainloop runs.

This call is thread-safe, so it may be called from a thread handling an incoming client request.

Note that this only stops accepting new connections; it does not close the listening sockets, and you can call socketServiceStart again later to begin listening again. To close the listening sockets, call socketListenerClose. (This will happen automatically when the SocketService is finalized.)

This must be called before calling socketListenerClose as the socket service will start accepting connections immediately when a new socket is added.

Since: 2.22

Properties

active

Whether the service is currently accepting connections.

Since: 2.46

data SocketServiceActivePropertyInfo Source #

Instances

Instances details
AttrInfo SocketServiceActivePropertyInfo Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type AttrAllowedOps SocketServiceActivePropertyInfo Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type AttrBaseTypeConstraint SocketServiceActivePropertyInfo Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type AttrGetType SocketServiceActivePropertyInfo Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type AttrLabel SocketServiceActivePropertyInfo Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type AttrOrigin SocketServiceActivePropertyInfo Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type AttrSetTypeConstraint SocketServiceActivePropertyInfo Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type AttrTransferType SocketServiceActivePropertyInfo Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

type AttrTransferTypeConstraint SocketServiceActivePropertyInfo Source # 
Instance details

Defined in GI.Gio.Objects.SocketService

constructSocketServiceActive :: (IsSocketService o, MonadIO m) => Bool -> m (GValueConstruct o) Source #

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

getSocketServiceActive :: (MonadIO m, IsSocketService o) => o -> m Bool Source #

Get the value of the “active” property. When overloading is enabled, this is equivalent to

get socketService #active

setSocketServiceActive :: (MonadIO m, IsSocketService o) => o -> Bool -> m () Source #

Set the value of the “active” property. When overloading is enabled, this is equivalent to

set socketService [ #active := value ]

Signals

incoming

type SocketServiceIncomingCallback Source #

Arguments

 = SocketConnection

connection: a new SocketConnection object

-> Maybe Object

sourceObject: the source_object passed to socketListenerAddAddress

-> IO Bool

Returns: True to stop other handlers from being called

The incoming signal is emitted when a new incoming connection to service needs to be handled. The handler must initiate the handling of connection, but may not block; in essence, asynchronous operations must be used.

connection will be unreffed once the signal handler returns, so you need to ref it yourself if you are planning to use it.

Since: 2.22

afterSocketServiceIncoming :: (IsSocketService a, MonadIO m) => a -> ((?self :: a) => SocketServiceIncomingCallback) -> m SignalHandlerId Source #

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

after socketService #incoming callback

By default the object invoking the signal is not passed to the callback. If you need to access it, you can use the implit ?self parameter. Note that this requires activating the ImplicitParams GHC extension.

onSocketServiceIncoming :: (IsSocketService a, MonadIO m) => a -> ((?self :: a) => SocketServiceIncomingCallback) -> m SignalHandlerId Source #

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

on socketService #incoming callback