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 |
A SocketService
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 SocketService
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
SocketService
. The first is to create the service using
socketServiceNew
and to connect to the SocketService
::incoming
signal. The second is to subclass SocketService
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][g-main-context-push-thread-default-context] 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.
- newtype SocketService = SocketService (ManagedPtr SocketService)
- class GObject o => IsSocketService o
- toSocketService :: (MonadIO m, IsSocketService o) => o -> m SocketService
- noSocketService :: Maybe SocketService
- socketServiceIsActive :: (HasCallStack, MonadIO m, IsSocketService a) => a -> m Bool
- socketServiceNew :: (HasCallStack, MonadIO m) => m SocketService
- socketServiceStart :: (HasCallStack, MonadIO m, IsSocketService a) => a -> m ()
- socketServiceStop :: (HasCallStack, MonadIO m, IsSocketService a) => a -> m ()
- constructSocketServiceActive :: IsSocketService o => Bool -> IO (GValueConstruct o)
- getSocketServiceActive :: (MonadIO m, IsSocketService o) => o -> m Bool
- setSocketServiceActive :: (MonadIO m, IsSocketService o) => o -> Bool -> m ()
- type C_SocketServiceIncomingCallback = Ptr () -> Ptr SocketConnection -> Ptr Object -> Ptr () -> IO CInt
- type SocketServiceIncomingCallback = SocketConnection -> Maybe Object -> IO Bool
- afterSocketServiceIncoming :: (IsSocketService a, MonadIO m) => a -> SocketServiceIncomingCallback -> m SignalHandlerId
- genClosure_SocketServiceIncoming :: SocketServiceIncomingCallback -> IO Closure
- mk_SocketServiceIncomingCallback :: C_SocketServiceIncomingCallback -> IO (FunPtr C_SocketServiceIncomingCallback)
- noSocketServiceIncomingCallback :: Maybe SocketServiceIncomingCallback
- onSocketServiceIncoming :: (IsSocketService a, MonadIO m) => a -> SocketServiceIncomingCallback -> m SignalHandlerId
- wrap_SocketServiceIncomingCallback :: SocketServiceIncomingCallback -> Ptr () -> Ptr SocketConnection -> Ptr Object -> Ptr () -> IO CInt
Exported types
newtype SocketService Source #
class GObject o => IsSocketService o Source #
toSocketService :: (MonadIO m, IsSocketService o) => o -> m SocketService Source #
Methods
isActive
socketServiceIsActive Source #
:: (HasCallStack, MonadIO m, IsSocketService a) | |
=> a |
|
-> m Bool |
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
:: (HasCallStack, MonadIO m) | |
=> m SocketService | Returns: a new |
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
:: (HasCallStack, MonadIO m, IsSocketService a) | |
=> a |
|
-> 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
:: (HasCallStack, MonadIO m, IsSocketService a) | |
=> a |
|
-> 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
constructSocketServiceActive :: IsSocketService o => Bool -> IO (GValueConstruct o) Source #
getSocketServiceActive :: (MonadIO m, IsSocketService o) => o -> m Bool Source #
setSocketServiceActive :: (MonadIO m, IsSocketService o) => o -> Bool -> m () Source #
Signals
incoming
type C_SocketServiceIncomingCallback = Ptr () -> Ptr SocketConnection -> Ptr Object -> Ptr () -> IO CInt Source #
type SocketServiceIncomingCallback = SocketConnection -> Maybe Object -> IO Bool Source #
afterSocketServiceIncoming :: (IsSocketService a, MonadIO m) => a -> SocketServiceIncomingCallback -> m SignalHandlerId Source #
mk_SocketServiceIncomingCallback :: C_SocketServiceIncomingCallback -> IO (FunPtr C_SocketServiceIncomingCallback) Source #
onSocketServiceIncoming :: (IsSocketService a, MonadIO m) => a -> SocketServiceIncomingCallback -> m SignalHandlerId Source #
wrap_SocketServiceIncomingCallback :: SocketServiceIncomingCallback -> Ptr () -> Ptr SocketConnection -> Ptr Object -> Ptr () -> IO CInt Source #