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 SocketListener
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.
If you want to implement a network server, also look at SocketService
and ThreadedSocketService
which are subclass of SocketListener
that makes this even easier.
Since: 2.22
Synopsis
- newtype SocketListener = SocketListener (ManagedPtr SocketListener)
- class GObject o => IsSocketListener o
- toSocketListener :: (MonadIO m, IsSocketListener o) => o -> m SocketListener
- noSocketListener :: Maybe SocketListener
- socketListenerAccept :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> m (SocketConnection, Maybe Object)
- socketListenerAcceptAsync :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- socketListenerAcceptFinish :: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) => a -> b -> m (SocketConnection, Maybe Object)
- socketListenerAcceptSocket :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> m (Socket, Maybe Object)
- socketListenerAcceptSocketAsync :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- socketListenerAcceptSocketFinish :: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) => a -> b -> m (Socket, Maybe Object)
- socketListenerAddAddress :: (HasCallStack, MonadIO m, IsSocketListener a, IsSocketAddress b, IsObject c) => a -> b -> SocketType -> SocketProtocol -> Maybe c -> m SocketAddress
- socketListenerAddAnyInetPort :: (HasCallStack, MonadIO m, IsSocketListener a, IsObject b) => a -> Maybe b -> m Word16
- socketListenerAddInetPort :: (HasCallStack, MonadIO m, IsSocketListener a, IsObject b) => a -> Word16 -> Maybe b -> m ()
- socketListenerAddSocket :: (HasCallStack, MonadIO m, IsSocketListener a, IsSocket b, IsObject c) => a -> b -> Maybe c -> m ()
- socketListenerClose :: (HasCallStack, MonadIO m, IsSocketListener a) => a -> m ()
- socketListenerNew :: (HasCallStack, MonadIO m) => m SocketListener
- socketListenerSetBacklog :: (HasCallStack, MonadIO m, IsSocketListener a) => a -> Int32 -> m ()
- constructSocketListenerListenBacklog :: IsSocketListener o => Int32 -> IO (GValueConstruct o)
- getSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> m Int32
- setSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> Int32 -> m ()
- type C_SocketListenerEventCallback = Ptr () -> CUInt -> Ptr Socket -> Ptr () -> IO ()
- type SocketListenerEventCallback = SocketListenerEvent -> Socket -> IO ()
- afterSocketListenerEvent :: (IsSocketListener a, MonadIO m) => a -> SocketListenerEventCallback -> m SignalHandlerId
- genClosure_SocketListenerEvent :: SocketListenerEventCallback -> IO Closure
- mk_SocketListenerEventCallback :: C_SocketListenerEventCallback -> IO (FunPtr C_SocketListenerEventCallback)
- noSocketListenerEventCallback :: Maybe SocketListenerEventCallback
- onSocketListenerEvent :: (IsSocketListener a, MonadIO m) => a -> SocketListenerEventCallback -> m SignalHandlerId
- wrap_SocketListenerEventCallback :: SocketListenerEventCallback -> C_SocketListenerEventCallback
Exported types
newtype SocketListener Source #
Memory-managed wrapper type.
Instances
GObject SocketListener Source # | |
Defined in GI.Gio.Objects.SocketListener gobjectType :: SocketListener -> IO GType # | |
IsObject SocketListener Source # | |
Defined in GI.Gio.Objects.SocketListener | |
IsSocketListener SocketListener Source # | |
Defined in GI.Gio.Objects.SocketListener |
class GObject o => IsSocketListener o Source #
Type class for types which can be safely cast to SocketListener
, for instance with toSocketListener
.
Instances
(GObject a, (UnknownAncestorError SocketListener a :: Constraint)) => IsSocketListener a Source # | |
Defined in GI.Gio.Objects.SocketListener | |
IsSocketListener SocketListener Source # | |
Defined in GI.Gio.Objects.SocketListener | |
IsSocketListener SocketService Source # | |
Defined in GI.Gio.Objects.SocketService | |
IsSocketListener ThreadedSocketService Source # | |
Defined in GI.Gio.Objects.ThreadedSocketService |
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
.
noSocketListener :: Maybe SocketListener Source #
A convenience alias for Nothing
:: Maybe
SocketListener
.
Methods
accept
:: (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
socketListenerAcceptAsync Source #
:: (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 socketListenerAcceptSocket
to get the result of the operation.
Since: 2.22
acceptFinish
socketListenerAcceptFinish Source #
:: (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
socketListenerAcceptSocket Source #
:: (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
socketListenerAcceptSocketAsync Source #
:: (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
socketListenerAcceptSocketFinish Source #
:: (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
socketListenerAddAddress Source #
:: (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.
Since: 2.22
addAnyInetPort
socketListenerAddAnyInetPort Source #
:: (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
socketListenerAddInetPort Source #
:: (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.
Since: 2.22
addSocket
socketListenerAddSocket Source #
:: (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
:: (HasCallStack, MonadIO m, IsSocketListener a) | |
=> a |
|
-> m () |
Closes all the sockets in the listener.
Since: 2.22
new
:: (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
socketListenerSetBacklog Source #
:: (HasCallStack, MonadIO m, IsSocketListener a) | |
=> a |
|
-> Int32 |
|
-> m () |
Sets the listen backlog on the sockets in the listener.
See socketSetListenBacklog
for details
Since: 2.22
Properties
listenBacklog
No description available in the introspection data.
constructSocketListenerListenBacklog :: IsSocketListener o => Int32 -> IO (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 ]
Signals
event
type C_SocketListenerEventCallback = Ptr () -> CUInt -> Ptr Socket -> Ptr () -> IO () Source #
Type for the callback on the (unwrapped) C side.
type SocketListenerEventCallback Source #
= 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
afterSocketListenerEvent :: (IsSocketListener a, MonadIO m) => 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
genClosure_SocketListenerEvent :: SocketListenerEventCallback -> IO Closure Source #
Wrap the callback into a Closure
.
mk_SocketListenerEventCallback :: C_SocketListenerEventCallback -> IO (FunPtr C_SocketListenerEventCallback) Source #
Generate a function pointer callable from C code, from a C_SocketListenerEventCallback
.
noSocketListenerEventCallback :: Maybe SocketListenerEventCallback Source #
A convenience synonym for
.Nothing
:: Maybe
SocketListenerEventCallback
onSocketListenerEvent :: (IsSocketListener a, MonadIO m) => 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