gi-gio-2.0.18: Gio bindings

CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.Gio.Objects.SocketListener

Contents

Description

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

Exported types

newtype SocketListener Source #

Memory-managed wrapper type.

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

accept

socketListenerAccept Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) 
=> a

listener: a SocketListener

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore.

-> m (SocketConnection, Maybe Object)

Returns: a SocketConnection on success, Nothing on error. (Can throw GError)

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 #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) 
=> a

listener: a SocketListener

-> Maybe b

cancellable: a Cancellable, or Nothing

-> Maybe AsyncReadyCallback

callback: a 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 #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) 
=> a

listener: a SocketListener

-> b

result: a AsyncResult.

-> m (SocketConnection, Maybe Object)

Returns: a SocketConnection on success, Nothing on error. (Can throw GError)

Finishes an async accept operation. See socketListenerAcceptAsync

Since: 2.22

acceptSocket

socketListenerAcceptSocket Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) 
=> a

listener: a SocketListener

-> Maybe b

cancellable: optional Cancellable object, Nothing to ignore.

-> m (Socket, Maybe Object)

Returns: a Socket on success, Nothing on error. (Can throw GError)

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 #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsCancellable b) 
=> a

listener: a SocketListener

-> Maybe b

cancellable: a Cancellable, or Nothing

-> Maybe AsyncReadyCallback

callback: a 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 #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsAsyncResult b) 
=> a

listener: a SocketListener

-> b

result: a AsyncResult.

-> m (Socket, Maybe Object)

Returns: a Socket on success, Nothing on error. (Can throw GError)

Finishes an async accept operation. See socketListenerAcceptSocketAsync

Since: 2.22

addAddress

socketListenerAddAddress Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsSocketAddress b, IsObject c) 
=> a

listener: a SocketListener

-> b

address: a SocketAddress

-> SocketType

type: a SocketType

-> SocketProtocol

protocol: a SocketProtocol

-> Maybe c

sourceObject: Optional Object identifying this source

-> m SocketAddress

(Can throw GError)

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 #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsObject b) 
=> a

listener: a SocketListener

-> Maybe b

sourceObject: Optional Object identifying this source

-> m Word16

Returns: the port number, or 0 in case of failure. (Can throw GError)

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 #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsObject b) 
=> a

listener: a SocketListener

-> Word16

port: an IP port number (non-zero)

-> Maybe b

sourceObject: Optional Object identifying this source

-> m ()

(Can throw GError)

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 #

Arguments

:: (HasCallStack, MonadIO m, IsSocketListener a, IsSocket b, IsObject c) 
=> a

listener: a SocketListener

-> b

socket: a listening Socket

-> Maybe c

sourceObject: Optional Object identifying this source

-> m ()

(Can throw GError)

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

socketListenerClose Source #

Arguments

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

listener: a SocketListener

-> m () 

Closes all the sockets in the listener.

Since: 2.22

new

socketListenerNew Source #

Arguments

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

Returns: a new SocketListener.

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 #

Arguments

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

listener: a SocketListener

-> Int32

listenBacklog: an integer

-> 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 #

Arguments

 = SocketListenerEvent

event: the event that is occurring

-> Socket

socket: the Socket the event is occurring on

-> 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

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