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.
- newtype SocketListener = SocketListener (ManagedPtr SocketListener)
- class GObject o => IsSocketListener o
- toSocketListener :: IsSocketListener o => o -> IO SocketListener
- noSocketListener :: Maybe SocketListener
- data SocketListenerAcceptMethodInfo
- socketListenerAccept :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> m (SocketConnection, 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, Object)
- data SocketListenerAcceptSocketMethodInfo
- socketListenerAcceptSocket :: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) => a -> Maybe b -> m (Socket, 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, 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 => Int32 -> IO (GValueConstruct o)
- getSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> m Int32
- setSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> Int32 -> m ()
- socketListenerListenBacklog :: AttrLabelProxy "listenBacklog"
- type C_SocketListenerEventCallback = Ptr () -> CUInt -> Ptr Socket -> Ptr () -> IO ()
- type SocketListenerEventCallback = SocketListenerEvent -> Socket -> IO ()
- data SocketListenerEventSignalInfo
- 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 -> Ptr () -> CUInt -> Ptr Socket -> Ptr () -> IO ()
Exported types
newtype SocketListener Source #
GObject SocketListener Source # | |
IsObject SocketListener Source # | |
IsSocketListener SocketListener Source # | |
((~) * info (ResolveSocketListenerMethod t SocketListener), MethodInfo * info SocketListener p) => IsLabel t (SocketListener -> p) Source # | |
((~) * info (ResolveSocketListenerMethod t SocketListener), MethodInfo * info SocketListener p) => IsLabelProxy t (SocketListener -> p) Source # | |
HasAttributeList * SocketListener Source # | |
type AttributeList SocketListener Source # | |
type SignalList SocketListener Source # | |
class GObject o => IsSocketListener o Source #
toSocketListener :: IsSocketListener o => o -> IO SocketListener Source #
Methods
accept
data SocketListenerAcceptMethodInfo Source #
((~) * signature (Maybe b -> m (SocketConnection, Object)), MonadIO m, IsSocketListener a, IsCancellable b) => MethodInfo * SocketListenerAcceptMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> m (SocketConnection, 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 #
((~) * signature (Maybe b -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsSocketListener a, IsCancellable b) => MethodInfo * SocketListenerAcceptAsyncMethodInfo a signature Source # | |
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
data SocketListenerAcceptFinishMethodInfo Source #
((~) * signature (b -> m (SocketConnection, Object)), MonadIO m, IsSocketListener a, IsAsyncResult b) => MethodInfo * SocketListenerAcceptFinishMethodInfo a signature Source # | |
socketListenerAcceptFinish Source #
:: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m (SocketConnection, Object) | Returns: a |
Finishes an async accept operation. See socketListenerAcceptAsync
Since: 2.22
acceptSocket
data SocketListenerAcceptSocketMethodInfo Source #
((~) * signature (Maybe b -> m (Socket, Object)), MonadIO m, IsSocketListener a, IsCancellable b) => MethodInfo * SocketListenerAcceptSocketMethodInfo a signature Source # | |
socketListenerAcceptSocket Source #
:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) | |
=> a |
|
-> Maybe b |
|
-> m (Socket, 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 #
((~) * signature (Maybe b -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsSocketListener a, IsCancellable b) => MethodInfo * SocketListenerAcceptSocketAsyncMethodInfo a signature Source # | |
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
data SocketListenerAcceptSocketFinishMethodInfo Source #
((~) * signature (b -> m (Socket, Object)), MonadIO m, IsSocketListener a, IsAsyncResult b) => MethodInfo * SocketListenerAcceptSocketFinishMethodInfo a signature Source # | |
socketListenerAcceptSocketFinish Source #
:: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m (Socket, Object) | Returns: a |
Finishes an async accept operation. See socketListenerAcceptSocketAsync
Since: 2.22
addAddress
data SocketListenerAddAddressMethodInfo Source #
((~) * signature (b -> SocketType -> SocketProtocol -> Maybe c -> m SocketAddress), MonadIO m, IsSocketListener a, IsSocketAddress b, IsObject c) => MethodInfo * SocketListenerAddAddressMethodInfo a signature Source # | |
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
data SocketListenerAddAnyInetPortMethodInfo Source #
((~) * signature (Maybe b -> m Word16), MonadIO m, IsSocketListener a, IsObject b) => MethodInfo * SocketListenerAddAnyInetPortMethodInfo a signature Source # | |
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
data SocketListenerAddInetPortMethodInfo Source #
((~) * signature (Word16 -> Maybe b -> m ()), MonadIO m, IsSocketListener a, IsObject b) => MethodInfo * SocketListenerAddInetPortMethodInfo a signature Source # | |
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
data SocketListenerAddSocketMethodInfo Source #
((~) * signature (b -> Maybe c -> m ()), MonadIO m, IsSocketListener a, IsSocket b, IsObject c) => MethodInfo * SocketListenerAddSocketMethodInfo a signature Source # | |
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
data SocketListenerCloseMethodInfo Source #
((~) * signature (m ()), MonadIO m, IsSocketListener a) => MethodInfo * SocketListenerCloseMethodInfo a signature Source # | |
:: (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
data SocketListenerSetBacklogMethodInfo Source #
((~) * signature (Int32 -> m ()), MonadIO m, IsSocketListener a) => MethodInfo * SocketListenerSetBacklogMethodInfo a signature Source # | |
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
data SocketListenerListenBacklogPropertyInfo Source #
constructSocketListenerListenBacklog :: IsSocketListener o => Int32 -> IO (GValueConstruct o) Source #
getSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> m Int32 Source #
setSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> Int32 -> m () Source #
socketListenerListenBacklog :: AttrLabelProxy "listenBacklog" Source #
Signals
event
type SocketListenerEventCallback = SocketListenerEvent -> Socket -> IO () Source #
afterSocketListenerEvent :: (IsSocketListener a, MonadIO m) => a -> SocketListenerEventCallback -> m SignalHandlerId Source #
mk_SocketListenerEventCallback :: C_SocketListenerEventCallback -> IO (FunPtr C_SocketListenerEventCallback) Source #
onSocketListenerEvent :: (IsSocketListener a, MonadIO m) => a -> SocketListenerEventCallback -> m SignalHandlerId Source #
wrap_SocketListenerEventCallback :: SocketListenerEventCallback -> Ptr () -> CUInt -> Ptr Socket -> Ptr () -> IO () Source #