Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | None |
Language | Haskell2010 |
GI.Gio.Objects.SocketListener
Description
A GSocketListener
is an object that keeps track of a set
of server sockets and helps you accept sockets from any of the
socket, either sync or async.
Add addresses and ports to listen on using
socketListenerAddAddress
and
socketListenerAddInetPort
. These will be listened on until
socketListenerClose
is called. Dropping your final reference to
the GSocketListener
will not cause socketListenerClose
to be
called implicitly, as some references to the GSocketListener
may be held
internally.
If you want to implement a network server, also look at
SocketService
and ThreadedSocketService
which are
subclasses of GSocketListener
that make this even easier.
Since: 2.22
Synopsis
- newtype SocketListener = SocketListener (ManagedPtr SocketListener)
- class (GObject o, IsDescendantOf SocketListener o) => IsSocketListener o
- toSocketListener :: (MonadIO m, IsSocketListener o) => o -> m SocketListener
- type family ResolveSocketListenerMethod (t :: Symbol) o where ...
- data SocketListenerAcceptMethodInfo
- socketListenerAccept :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> m (SocketConnection, Maybe Object)
- data SocketListenerAcceptAsyncMethodInfo
- socketListenerAcceptAsync :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- data SocketListenerAcceptFinishMethodInfo
- socketListenerAcceptFinish :: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) => a -> b -> m (SocketConnection, Maybe Object)
- data SocketListenerAcceptSocketMethodInfo
- socketListenerAcceptSocket :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> m (Socket, Maybe Object)
- data SocketListenerAcceptSocketAsyncMethodInfo
- socketListenerAcceptSocketAsync :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- data SocketListenerAcceptSocketFinishMethodInfo
- socketListenerAcceptSocketFinish :: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) => a -> b -> m (Socket, Maybe Object)
- data SocketListenerAddAddressMethodInfo
- socketListenerAddAddress :: (HasCallStack, MonadIO m, IsSocketListener a, IsSocketAddress b, IsObject c) => a -> b -> SocketType -> SocketProtocol -> Maybe c -> m SocketAddress
- data SocketListenerAddAnyInetPortMethodInfo
- socketListenerAddAnyInetPort :: (HasCallStack, MonadIO m, IsSocketListener a, IsObject b) => a -> Maybe b -> m Word16
- data SocketListenerAddInetPortMethodInfo
- socketListenerAddInetPort :: (HasCallStack, MonadIO m, IsSocketListener a, IsObject b) => a -> Word16 -> Maybe b -> m ()
- data SocketListenerAddSocketMethodInfo
- socketListenerAddSocket :: (HasCallStack, MonadIO m, IsSocketListener a, IsSocket b, IsObject c) => a -> b -> Maybe c -> m ()
- data SocketListenerCloseMethodInfo
- socketListenerClose :: (HasCallStack, MonadIO m, IsSocketListener a) => a -> m ()
- socketListenerNew :: (HasCallStack, MonadIO m) => m SocketListener
- data SocketListenerSetBacklogMethodInfo
- socketListenerSetBacklog :: (HasCallStack, MonadIO m, IsSocketListener a) => a -> Int32 -> m ()
- data SocketListenerListenBacklogPropertyInfo
- constructSocketListenerListenBacklog :: (IsSocketListener o, MonadIO m) => Int32 -> m (GValueConstruct o)
- getSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> m Int32
- setSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> Int32 -> m ()
- socketListenerListenBacklog :: AttrLabelProxy "listenBacklog"
- type SocketListenerEventCallback = SocketListenerEvent -> Socket -> IO ()
- data SocketListenerEventSignalInfo
- afterSocketListenerEvent :: (IsSocketListener a, MonadIO m) => a -> ((?self :: a) => SocketListenerEventCallback) -> m SignalHandlerId
- onSocketListenerEvent :: (IsSocketListener a, MonadIO m) => a -> ((?self :: a) => SocketListenerEventCallback) -> m SignalHandlerId
Exported types
newtype SocketListener Source #
Memory-managed wrapper type.
Constructors
SocketListener (ManagedPtr SocketListener) |
Instances
class (GObject o, IsDescendantOf SocketListener o) => IsSocketListener o Source #
Type class for types which can be safely cast to SocketListener
, for instance with toSocketListener
.
Instances
(GObject o, IsDescendantOf SocketListener o) => IsSocketListener o Source # | |
Defined in GI.Gio.Objects.SocketListener |
toSocketListener :: (MonadIO m, IsSocketListener o) => o -> m SocketListener Source #
Cast to SocketListener
, for types for which this is known to be safe. For general casts, use castTo
.
Methods
Click to display all available methods, including inherited ones
Methods
accept, acceptAsync, acceptFinish, acceptSocket, acceptSocketAsync, acceptSocketFinish, addAddress, addAnyInetPort, addInetPort, addSocket, bindProperty, bindPropertyFull, close, forceFloating, freezeNotify, getv, isFloating, notify, notifyByPspec, ref, refSink, runDispose, stealData, stealQdata, thawNotify, unref, watchClosure.
Getters
getData, getProperty, getQdata.
Setters
type family ResolveSocketListenerMethod (t :: Symbol) o where ... Source #
Equations
accept
data SocketListenerAcceptMethodInfo Source #
Instances
(signature ~ (Maybe b -> m (SocketConnection, Maybe Object)), MonadIO m, IsSocketListener a, IsCancellable b) => OverloadedMethod SocketListenerAcceptMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAcceptMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> m (SocketConnection, Maybe Object) | Returns: a |
Blocks waiting for a client to connect to any of the sockets added
to the listener. Returns a SocketConnection
for the socket that was
accepted.
If sourceObject
is not Nothing
it will be filled out with the source
object specified when the corresponding socket or address was added
to the listener.
If cancellable
is not Nothing
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error IOErrorEnumCancelled
will be returned.
Since: 2.22
acceptAsync
data SocketListenerAcceptAsyncMethodInfo Source #
Instances
(signature ~ (Maybe b -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsSocketListener a, IsCancellable b) => OverloadedMethod SocketListenerAcceptAsyncMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAcceptAsyncMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerAcceptAsync Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
This is the asynchronous version of socketListenerAccept
.
When the operation is finished callback
will be
called. You can then call socketListenerAcceptFinish
to get the result of the operation.
Since: 2.22
acceptFinish
data SocketListenerAcceptFinishMethodInfo Source #
Instances
(signature ~ (b -> m (SocketConnection, Maybe Object)), MonadIO m, IsSocketListener a, IsAsyncResult b) => OverloadedMethod SocketListenerAcceptFinishMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAcceptFinishMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerAcceptFinish Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m (SocketConnection, Maybe Object) | Returns: a |
Finishes an async accept operation. See socketListenerAcceptAsync
Since: 2.22
acceptSocket
data SocketListenerAcceptSocketMethodInfo Source #
Instances
(signature ~ (Maybe b -> m (Socket, Maybe Object)), MonadIO m, IsSocketListener a, IsCancellable b) => OverloadedMethod SocketListenerAcceptSocketMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAcceptSocketMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerAcceptSocket Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> m (Socket, Maybe Object) | Returns: a |
Blocks waiting for a client to connect to any of the sockets added
to the listener. Returns the Socket
that was accepted.
If you want to accept the high-level SocketConnection
, not a Socket
,
which is often the case, then you should use socketListenerAccept
instead.
If sourceObject
is not Nothing
it will be filled out with the source
object specified when the corresponding socket or address was added
to the listener.
If cancellable
is not Nothing
, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error IOErrorEnumCancelled
will be returned.
Since: 2.22
acceptSocketAsync
data SocketListenerAcceptSocketAsyncMethodInfo Source #
Instances
(signature ~ (Maybe b -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsSocketListener a, IsCancellable b) => OverloadedMethod SocketListenerAcceptSocketAsyncMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAcceptSocketAsyncMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerAcceptSocketAsync Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
This is the asynchronous version of socketListenerAcceptSocket
.
When the operation is finished callback
will be
called. You can then call socketListenerAcceptSocketFinish
to get the result of the operation.
Since: 2.22
acceptSocketFinish
data SocketListenerAcceptSocketFinishMethodInfo Source #
Instances
(signature ~ (b -> m (Socket, Maybe Object)), MonadIO m, IsSocketListener a, IsAsyncResult b) => OverloadedMethod SocketListenerAcceptSocketFinishMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAcceptSocketFinishMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerAcceptSocketFinish Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m (Socket, Maybe Object) | Returns: a |
Finishes an async accept operation. See socketListenerAcceptSocketAsync
Since: 2.22
addAddress
data SocketListenerAddAddressMethodInfo Source #
Instances
(signature ~ (b -> SocketType -> SocketProtocol -> Maybe c -> m SocketAddress), MonadIO m, IsSocketListener a, IsSocketAddress b, IsObject c) => OverloadedMethod SocketListenerAddAddressMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAddAddressMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerAddAddress Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsSocketAddress b, IsObject c) | |
=> a |
|
-> b |
|
-> SocketType |
|
-> SocketProtocol |
|
-> Maybe c |
|
-> m SocketAddress | (Can throw |
Creates a socket of type type
and protocol protocol
, binds
it to address
and adds it to the set of sockets we're accepting
sockets from.
Note that adding an IPv6 address, depending on the platform,
may or may not result in a listener that also accepts IPv4
connections. For more deterministic behavior, see
socketListenerAddInetPort
.
sourceObject
will be passed out in the various calls
to accept to identify this particular source, which is
useful if you're listening on multiple addresses and do
different things depending on what address is connected to.
If successful and effectiveAddress
is non-Nothing
then it will
be set to the address that the binding actually occurred at. This
is helpful for determining the port number that was used for when
requesting a binding to port 0 (ie: "any port"). This address, if
requested, belongs to the caller and must be freed.
Call socketListenerClose
to stop listening on address
; this will not
be done automatically when you drop your final reference to listener
, as
references may be held internally.
Since: 2.22
addAnyInetPort
data SocketListenerAddAnyInetPortMethodInfo Source #
Instances
(signature ~ (Maybe b -> m Word16), MonadIO m, IsSocketListener a, IsObject b) => OverloadedMethod SocketListenerAddAnyInetPortMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAddAnyInetPortMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerAddAnyInetPort Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsObject b) | |
=> a |
|
-> Maybe b |
|
-> m Word16 | Returns: the port number, or 0 in case of failure. (Can throw |
Listens for TCP connections on any available port number for both IPv6 and IPv4 (if each is available).
This is useful if you need to have a socket for incoming connections but don't care about the specific port number.
sourceObject
will be passed out in the various calls
to accept to identify this particular source, which is
useful if you're listening on multiple addresses and do
different things depending on what address is connected to.
Since: 2.24
addInetPort
data SocketListenerAddInetPortMethodInfo Source #
Instances
(signature ~ (Word16 -> Maybe b -> m ()), MonadIO m, IsSocketListener a, IsObject b) => OverloadedMethod SocketListenerAddInetPortMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAddInetPortMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerAddInetPort Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsObject b) | |
=> a |
|
-> Word16 |
|
-> Maybe b |
|
-> m () | (Can throw |
Helper function for socketListenerAddAddress
that
creates a TCP/IP socket listening on IPv4 and IPv6 (if
supported) on the specified port on all interfaces.
sourceObject
will be passed out in the various calls
to accept to identify this particular source, which is
useful if you're listening on multiple addresses and do
different things depending on what address is connected to.
Call socketListenerClose
to stop listening on port
; this will not
be done automatically when you drop your final reference to listener
, as
references may be held internally.
Since: 2.22
addSocket
data SocketListenerAddSocketMethodInfo Source #
Instances
(signature ~ (b -> Maybe c -> m ()), MonadIO m, IsSocketListener a, IsSocket b, IsObject c) => OverloadedMethod SocketListenerAddSocketMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerAddSocketMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerAddSocket Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a, IsSocket b, IsObject c) | |
=> a |
|
-> b |
|
-> Maybe c |
|
-> m () | (Can throw |
Adds socket
to the set of sockets that we try to accept
new clients from. The socket must be bound to a local
address and listened to.
sourceObject
will be passed out in the various calls
to accept to identify this particular source, which is
useful if you're listening on multiple addresses and do
different things depending on what address is connected to.
The socket
will not be automatically closed when the listener
is finalized
unless the listener held the final reference to the socket. Before GLib 2.42,
the socket
was automatically closed on finalization of the listener
, even
if references to it were held elsewhere.
Since: 2.22
close
data SocketListenerCloseMethodInfo Source #
Instances
(signature ~ m (), MonadIO m, IsSocketListener a) => OverloadedMethod SocketListenerCloseMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerCloseMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a) | |
=> a |
|
-> m () |
Closes all the sockets in the listener.
Since: 2.22
new
Arguments
:: (HasCallStack, MonadIO m) | |
=> m SocketListener | Returns: a new |
Creates a new SocketListener
with no sockets to listen for.
New listeners can be added with e.g. socketListenerAddAddress
or socketListenerAddInetPort
.
Since: 2.22
setBacklog
data SocketListenerSetBacklogMethodInfo Source #
Instances
(signature ~ (Int32 -> m ()), MonadIO m, IsSocketListener a) => OverloadedMethod SocketListenerSetBacklogMethodInfo a signature Source # | |
Defined in GI.Gio.Objects.SocketListener Methods overloadedMethod :: a -> signature # | |
OverloadedMethodInfo SocketListenerSetBacklogMethodInfo (a :: Type) Source # | |
Defined in GI.Gio.Objects.SocketListener Methods |
socketListenerSetBacklog Source #
Arguments
:: (HasCallStack, MonadIO m, IsSocketListener a) | |
=> a |
|
-> Int32 |
|
-> m () |
Sets the listen backlog on the sockets in the listener. This must be called
before adding any sockets, addresses or ports to the SocketListener
(for
example, by calling socketListenerAddInetPort
) to be effective.
See socketSetListenBacklog
for details
Since: 2.22
Properties
listenBacklog
The number of outstanding connections in the listen queue.
Since: 2.22
data SocketListenerListenBacklogPropertyInfo Source #
Instances
constructSocketListenerListenBacklog :: (IsSocketListener o, MonadIO m) => Int32 -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “listen-backlog
” property. This is rarely needed directly, but it is used by new
.
getSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> m Int32 Source #
Get the value of the “listen-backlog
” property.
When overloading is enabled, this is equivalent to
get
socketListener #listenBacklog
setSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> Int32 -> m () Source #
Set the value of the “listen-backlog
” property.
When overloading is enabled, this is equivalent to
set
socketListener [ #listenBacklog:=
value ]
socketListenerListenBacklog :: AttrLabelProxy "listenBacklog" Source #
Signals
event
type SocketListenerEventCallback Source #
Arguments
= SocketListenerEvent |
|
-> Socket |
|
-> IO () |
Emitted when listener
's activity on socket
changes state.
Note that when listener
is used to listen on both IPv4 and
IPv6, a separate set of signals will be emitted for each, and
the order they happen in is undefined.
Since: 2.46
data SocketListenerEventSignalInfo Source #
Instances
SignalInfo SocketListenerEventSignalInfo Source # | |||||
Defined in GI.Gio.Objects.SocketListener Associated Types
Methods connectSignal :: GObject o => o -> (o -> HaskellCallbackType SocketListenerEventSignalInfo) -> SignalConnectMode -> Maybe Text -> IO SignalHandlerId # | |||||
type HaskellCallbackType SocketListenerEventSignalInfo Source # | |||||
afterSocketListenerEvent :: (IsSocketListener a, MonadIO m) => a -> ((?self :: a) => SocketListenerEventCallback) -> m SignalHandlerId Source #
Connect a signal handler for the event signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
socketListener #event 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.
onSocketListenerEvent :: (IsSocketListener a, MonadIO m) => a -> ((?self :: a) => SocketListenerEventCallback) -> m SignalHandlerId Source #
Connect a signal handler for the event signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
socketListener #event callback