glibmm 2.66.5
Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gio::SocketListener Class Reference

Helper for accepting network client connections. More...

#include <giomm/socketlistener.h>

Inheritance diagram for Gio::SocketListener:
Inheritance graph
[legend]

Public Member Functions

 SocketListener (SocketListener && src) noexcept
 
SocketListeneroperator= (SocketListener && src) noexcept
 
 ~SocketListener () noexcept override
 
GSocketListener * gobj ()
 Provides access to the underlying C GObject. More...
 
const GSocketListener * gobj () const
 Provides access to the underlying C GObject. More...
 
GSocketListener * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
void set_backlog (int listen_backlog)
 Sets the listen backlog on the sockets in the listener. More...
 
bool add_socket (const Glib::RefPtr< Socket > & socket, const Glib::RefPtr< Glib::Object > & source_object)
 Adds socket to the set of sockets that we try to accept new clients from. More...
 
bool add_socket (const Glib::RefPtr< Socket > & socket)
 Adds socket to the set of sockets that we try to accept new clients from. More...
 
bool add_address (const Glib::RefPtr< SocketAddress > & address, SocketType type, SocketProtocol protocol, const Glib::RefPtr< Glib::Object > & source_object, Glib::RefPtr< SocketAddress > & effective_address)
 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. More...
 
bool add_address (const Glib::RefPtr< SocketAddress > & address, SocketType type, SocketProtocol protocol, Glib::RefPtr< SocketAddress > & effective_address)
 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. More...
 
bool add_inet_port (guint16 port, const Glib::RefPtr< Glib::Object > & source_object)
 Helper function for g_socket_listener_add_address() that creates a TCP/IP socket listening on IPv4 and IPv6 (if supported) on the specified port on all interfaces. More...
 
bool add_inet_port (guint16 port)
 Helper function for g_socket_listener_add_address() that creates a TCP/IP socket listening on IPv4 and IPv6 (if supported) on the specified port on all interfaces. More...
 
guint16 add_any_inet_port (const Glib::RefPtr< Glib::Object > & source_object)
 Listens for TCP connections on any available port number for both IPv6 and IPv4 (if each is available). More...
 
guint16 add_any_inet_port ()
 Listens for TCP connections on any available port number for both IPv6 and IPv4 (if each is available). More...
 
Glib::RefPtr< Socketaccept_socket (Glib::RefPtr< Glib::Object > & source_object, const Glib::RefPtr< Cancellable > & cancellable)
 Blocks waiting for a client to connect to any of the sockets added to the listener. More...
 
Glib::RefPtr< Socketaccept_socket (Glib::RefPtr< Glib::Object > & source_object)
 Blocks waiting for a client to connect to any of the sockets added to the listener. More...
 
Glib::RefPtr< Socketaccept_socket (const Glib::RefPtr< Cancellable > & cancellable)
 Blocks waiting for a client to connect to any of the sockets added to the listener. More...
 
Glib::RefPtr< Socketaccept_socket ()
 Blocks waiting for a client to connect to any of the sockets added to the listener. More...
 
void accept_socket_async (const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot)
 This is the asynchronous version of g_socket_listener_accept_socket(). More...
 
void accept_socket_async (const SlotAsyncReady & slot)
 This is the asynchronous version of g_socket_listener_accept_socket(). More...
 
Glib::RefPtr< Socketaccept_socket_finish (const Glib::RefPtr< AsyncResult > & result, Glib::RefPtr< Glib::Object > & source_object)
 Finishes an async accept operation. More...
 
Glib::RefPtr< Socketaccept_socket_finish (const Glib::RefPtr< AsyncResult > & result)
 Finishes an async accept operation. More...
 
Glib::RefPtr< SocketConnectionaccept (Glib::RefPtr< Object > & source_object, const Glib::RefPtr< Cancellable > & cancellable)
 Blocks waiting for a client to connect to any of the sockets added to the listener. More...
 
Glib::RefPtr< SocketConnectionaccept (Glib::RefPtr< Object > & source_object)
 Blocks waiting for a client to connect to any of the sockets added to the listener. More...
 
Glib::RefPtr< SocketConnectionaccept (const Glib::RefPtr< Cancellable > & cancellable)
 Blocks waiting for a client to connect to any of the sockets added to the listener. More...
 
Glib::RefPtr< SocketConnectionaccept ()
 Blocks waiting for a client to connect to any of the sockets added to the listener. More...
 
void accept_async (const SlotAsyncReady & slot)
 This is the asynchronous version of g_socket_listener_accept(). More...
 
void accept_async (const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot)
 This is the asynchronous version of g_socket_listener_accept(). More...
 
Glib::RefPtr< SocketConnectionaccept_finish (const Glib::RefPtr< AsyncResult > & result, Glib::RefPtr< Glib::Object > & source_object)
 Finishes an async accept operation. More...
 
Glib::RefPtr< SocketConnectionaccept_finish (const Glib::RefPtr< AsyncResult > & result)
 Finishes an async accept operation. More...
 
void close ()
 Closes all the sockets in the listener. More...
 
Glib::PropertyProxy< int > property_listen_backlog ()
 outstanding connections in the listen queue. More...
 
Glib::PropertyProxy_ReadOnly< int > property_listen_backlog () const
 outstanding connections in the listen queue. More...
 
- Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object && src) noexcept
 
Objectoperator= (Object && src) noexcept
 
void * get_data (const QueryQuark & key)
 
void set_data (const Quark & key, void *data)
 
void set_data (const Quark & key, void *data, DestroyNotify notify)
 
void remove_data (const QueryQuark & quark)
 
void * steal_data (const QueryQuark & quark)
 
- Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase &)=delete
 
ObjectBaseoperator= (const ObjectBase &)=delete
 
void set_property_value (const Glib::ustring & property_name, const Glib::ValueBase & value)
 You probably want to use a specific property_*() accessor method instead. More...
 
void get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const
 You probably want to use a specific property_*() accessor method instead. More...
 
template<class PropertyType >
void set_property (const Glib::ustring & property_name, const PropertyType & value)
 You probably want to use a specific property_*() accessor method instead. More...
 
template<class PropertyType >
void get_property (const Glib::ustring & property_name, PropertyType & value) const
 You probably want to use a specific property_*() accessor method instead. More...
 
void connect_property_changed (const Glib::ustring & property_name, const sigc::slot< void > & slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
void connect_property_changed (const Glib::ustring & property_name, sigc::slot< void > && slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
sigc::connection connect_property_changed_with_return (const Glib::ustring & property_name, const sigc::slot< void > & slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
sigc::connection connect_property_changed_with_return (const Glib::ustring & property_name, sigc::slot< void > && slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
void freeze_notify ()
 Increases the freeze count on object. More...
 
void thaw_notify ()
 Reverts the effect of a previous call to freeze_notify(). More...
 
virtual void reference () const
 Increment the reference count for this object. More...
 
virtual void unreference () const
 Decrement the reference count for this object. More...
 
GObject * gobj ()
 Provides access to the underlying C GObject. More...
 
const GObject * gobj () const
 Provides access to the underlying C GObject. More...
 
GObject * gobj_copy () const
 Give a ref-ed copy to someone. Use for direct struct access. More...
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< SocketListenercreate ()
 

Protected Member Functions

 SocketListener ()
 
- Protected Member Functions inherited from Glib::Object
 Object ()
 
 Object (const Glib::ConstructParams & construct_params)
 
 Object (GObject * castitem)
 
 ~Object () noexcept override
 
- Protected Member Functions inherited from Glib::ObjectBase
 ObjectBase ()
 This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
 
 ObjectBase (const char * custom_type_name)
 A derived constructor always overrides this choice. More...
 
 ObjectBase (const std::type_info & custom_type_info)
 This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
 
 ObjectBase (ObjectBase && src) noexcept
 
ObjectBaseoperator= (ObjectBase && src) noexcept
 
virtual ~ObjectBase () noexcept=0
 
void initialize (GObject * castitem)
 
void initialize_move (GObject * castitem, Glib::ObjectBase * previous_wrapper)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gio::SocketListenerwrap (GSocketListener * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Additional Inherited Members

- Public Types inherited from Glib::Object
using DestroyNotify = void(*)(gpointer data)
 

Detailed Description

Helper for accepting network client connections.

See also
ThreadedSocketService, SocketService.

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 glibmm 2.24:

Constructor & Destructor Documentation

◆ SocketListener() [1/2]

Gio::SocketListener::SocketListener ( SocketListener &&  src)
noexcept

◆ ~SocketListener()

Gio::SocketListener::~SocketListener ( )
overridenoexcept

◆ SocketListener() [2/2]

Gio::SocketListener::SocketListener ( )
protected

Member Function Documentation

◆ accept() [1/4]

Glib::RefPtr< SocketConnection > Gio::SocketListener::accept ( )

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 source_object is not nullptr 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 nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IO_ERROR_CANCELLED will be returned.

Since glibmm 2.22:
Parameters
source_objectLocation where Object pointer will be stored, or nullptr.
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A SocketConnection on success, nullptr on error.

◆ accept() [2/4]

Glib::RefPtr< SocketConnection > Gio::SocketListener::accept ( const Glib::RefPtr< Cancellable > &  cancellable)

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 source_object is not nullptr 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 nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IO_ERROR_CANCELLED will be returned.

Since glibmm 2.22:
Parameters
source_objectLocation where Object pointer will be stored, or nullptr.
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A SocketConnection on success, nullptr on error.

◆ accept() [3/4]

Glib::RefPtr< SocketConnection > Gio::SocketListener::accept ( Glib::RefPtr< Object > &  source_object)

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 source_object is not nullptr 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 nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IO_ERROR_CANCELLED will be returned.

Since glibmm 2.22:
Parameters
source_objectLocation where Object pointer will be stored, or nullptr.
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A SocketConnection on success, nullptr on error.

◆ accept() [4/4]

Glib::RefPtr< SocketConnection > Gio::SocketListener::accept ( Glib::RefPtr< Object > &  source_object,
const Glib::RefPtr< Cancellable > &  cancellable 
)

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 source_object is not nullptr 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 nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IO_ERROR_CANCELLED will be returned.

Since glibmm 2.22:
Parameters
source_objectLocation where Object pointer will be stored, or nullptr.
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A SocketConnection on success, nullptr on error.

◆ accept_async() [1/2]

void Gio::SocketListener::accept_async ( const Glib::RefPtr< Cancellable > &  cancellable,
const SlotAsyncReady &  slot 
)

This is the asynchronous version of g_socket_listener_accept().

When the operation is finished slot will be called. You can then call g_socket_listener_accept_socket() to get the result of the operation.

Since glibmm 2.22:
Parameters
cancellableA Cancellable, or nullptr.
slotA SlotAsyncReady.
user_dataUser data for the callback.

◆ accept_async() [2/2]

void Gio::SocketListener::accept_async ( const SlotAsyncReady &  slot)

This is the asynchronous version of g_socket_listener_accept().

When the operation is finished slot will be called. You can then call g_socket_listener_accept_socket() to get the result of the operation.

Since glibmm 2.22:
Parameters
cancellableA Cancellable, or nullptr.
slotA SlotAsyncReady.
user_dataUser data for the callback.

◆ accept_finish() [1/2]

Glib::RefPtr< SocketConnection > Gio::SocketListener::accept_finish ( const Glib::RefPtr< AsyncResult > &  result)

Finishes an async accept operation.

See g_socket_listener_accept_async()

Since glibmm 2.22:
Parameters
resultA AsyncResult.
source_objectOptional Object identifying this source.
Returns
A SocketConnection on success, nullptr on error.

◆ accept_finish() [2/2]

Glib::RefPtr< SocketConnection > Gio::SocketListener::accept_finish ( const Glib::RefPtr< AsyncResult > &  result,
Glib::RefPtr< Glib::Object > &  source_object 
)

Finishes an async accept operation.

See g_socket_listener_accept_async()

Since glibmm 2.22:
Parameters
resultA AsyncResult.
source_objectOptional Object identifying this source.
Returns
A SocketConnection on success, nullptr on error.

◆ accept_socket() [1/4]

Glib::RefPtr< Socket > Gio::SocketListener::accept_socket ( )

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 g_socket_listener_accept() instead.

If source_object is not nullptr 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 nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IO_ERROR_CANCELLED will be returned.

Since glibmm 2.22:
Parameters
source_objectLocation where Object pointer will be stored, or nullptr.
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A Socket on success, nullptr on error.

◆ accept_socket() [2/4]

Glib::RefPtr< Socket > Gio::SocketListener::accept_socket ( const Glib::RefPtr< Cancellable > &  cancellable)

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 g_socket_listener_accept() instead.

If source_object is not nullptr 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 nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IO_ERROR_CANCELLED will be returned.

Since glibmm 2.22:
Parameters
source_objectLocation where Object pointer will be stored, or nullptr.
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A Socket on success, nullptr on error.

◆ accept_socket() [3/4]

Glib::RefPtr< Socket > Gio::SocketListener::accept_socket ( Glib::RefPtr< Glib::Object > &  source_object)

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 g_socket_listener_accept() instead.

If source_object is not nullptr 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 nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IO_ERROR_CANCELLED will be returned.

Since glibmm 2.22:
Parameters
source_objectLocation where Object pointer will be stored, or nullptr.
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A Socket on success, nullptr on error.

◆ accept_socket() [4/4]

Glib::RefPtr< Socket > Gio::SocketListener::accept_socket ( Glib::RefPtr< Glib::Object > &  source_object,
const Glib::RefPtr< Cancellable > &  cancellable 
)

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 g_socket_listener_accept() instead.

If source_object is not nullptr 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 nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IO_ERROR_CANCELLED will be returned.

Since glibmm 2.22:
Parameters
source_objectLocation where Object pointer will be stored, or nullptr.
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A Socket on success, nullptr on error.

◆ accept_socket_async() [1/2]

void Gio::SocketListener::accept_socket_async ( const Glib::RefPtr< Cancellable > &  cancellable,
const SlotAsyncReady &  slot 
)

This is the asynchronous version of g_socket_listener_accept_socket().

When the operation is finished slot will be called. You can then call g_socket_listener_accept_socket_finish() to get the result of the operation.

Since glibmm 2.22:
Parameters
cancellableA Cancellable, or nullptr.
slotA SlotAsyncReady.
user_dataUser data for the callback.

◆ accept_socket_async() [2/2]

void Gio::SocketListener::accept_socket_async ( const SlotAsyncReady &  slot)

This is the asynchronous version of g_socket_listener_accept_socket().

When the operation is finished slot will be called. You can then call g_socket_listener_accept_socket_finish() to get the result of the operation.

Since glibmm 2.22:
Parameters
cancellableA Cancellable, or nullptr.
slotA SlotAsyncReady.
user_dataUser data for the callback.

◆ accept_socket_finish() [1/2]

Glib::RefPtr< Socket > Gio::SocketListener::accept_socket_finish ( const Glib::RefPtr< AsyncResult > &  result)

Finishes an async accept operation.

See g_socket_listener_accept_socket_async()

Since glibmm 2.22:
Parameters
resultA AsyncResult.
source_objectOptional Object identifying this source.
Returns
A Socket on success, nullptr on error.

◆ accept_socket_finish() [2/2]

Glib::RefPtr< Socket > Gio::SocketListener::accept_socket_finish ( const Glib::RefPtr< AsyncResult > &  result,
Glib::RefPtr< Glib::Object > &  source_object 
)

Finishes an async accept operation.

See g_socket_listener_accept_socket_async()

Since glibmm 2.22:
Parameters
resultA AsyncResult.
source_objectOptional Object identifying this source.
Returns
A Socket on success, nullptr on error.

◆ add_address() [1/2]

bool Gio::SocketListener::add_address ( const Glib::RefPtr< SocketAddress > &  address,
SocketType  type,
SocketProtocol  protocol,
const Glib::RefPtr< Glib::Object > &  source_object,
Glib::RefPtr< SocketAddress > &  effective_address 
)

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 g_socket_listener_add_inet_port().

source_object 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 effective_address is non-nullptr 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 g_socket_listener_close() 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 glibmm 2.22:
Parameters
addressA SocketAddress.
typeA SocketType.
protocolA SocketProtocol.
source_objectOptional Object identifying this source.
effective_addressLocation to store the address that was bound to, or nullptr.
Returns
true on success, false on error.

◆ add_address() [2/2]

bool Gio::SocketListener::add_address ( const Glib::RefPtr< SocketAddress > &  address,
SocketType  type,
SocketProtocol  protocol,
Glib::RefPtr< SocketAddress > &  effective_address 
)

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 g_socket_listener_add_inet_port().

source_object 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 effective_address is non-nullptr 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 g_socket_listener_close() 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 glibmm 2.22:
Parameters
addressA SocketAddress.
typeA SocketType.
protocolA SocketProtocol.
source_objectOptional Object identifying this source.
effective_addressLocation to store the address that was bound to, or nullptr.
Returns
true on success, false on error.

◆ add_any_inet_port() [1/2]

guint16 Gio::SocketListener::add_any_inet_port ( )

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.

source_object 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 glibmm 2.24:
Parameters
source_objectOptional Object identifying this source.
Returns
The port number, or 0 in case of failure.

◆ add_any_inet_port() [2/2]

guint16 Gio::SocketListener::add_any_inet_port ( const Glib::RefPtr< Glib::Object > &  source_object)

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.

source_object 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 glibmm 2.24:
Parameters
source_objectOptional Object identifying this source.
Returns
The port number, or 0 in case of failure.
Exceptions
Glib::Error

◆ add_inet_port() [1/2]

bool Gio::SocketListener::add_inet_port ( guint16  port)

Helper function for g_socket_listener_add_address() that creates a TCP/IP socket listening on IPv4 and IPv6 (if supported) on the specified port on all interfaces.

source_object 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 g_socket_listener_close() 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 glibmm 2.22:
Parameters
portAn IP port number (non-zero).
source_objectOptional Object identifying this source.
Returns
true on success, false on error.

◆ add_inet_port() [2/2]

bool Gio::SocketListener::add_inet_port ( guint16  port,
const Glib::RefPtr< Glib::Object > &  source_object 
)

Helper function for g_socket_listener_add_address() that creates a TCP/IP socket listening on IPv4 and IPv6 (if supported) on the specified port on all interfaces.

source_object 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 g_socket_listener_close() 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 glibmm 2.22:
Parameters
portAn IP port number (non-zero).
source_objectOptional Object identifying this source.
Returns
true on success, false on error.
Exceptions
Glib::Error

◆ add_socket() [1/2]

bool Gio::SocketListener::add_socket ( const Glib::RefPtr< Socket > &  socket)

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.

source_object 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 glibmm 2.22:
Parameters
socketA listening Socket.
source_objectOptional Object identifying this source.
Returns
true on success, false on error.

◆ add_socket() [2/2]

bool Gio::SocketListener::add_socket ( const Glib::RefPtr< Socket > &  socket,
const Glib::RefPtr< Glib::Object > &  source_object 
)

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.

source_object 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 glibmm 2.22:
Parameters
socketA listening Socket.
source_objectOptional Object identifying this source.
Returns
true on success, false on error.
Exceptions
Glib::Error

◆ close()

void Gio::SocketListener::close ( )

Closes all the sockets in the listener.

Since glibmm 2.22:

◆ create()

static Glib::RefPtr< SocketListener > Gio::SocketListener::create ( )
static

◆ get_type()

static GType Gio::SocketListener::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ gobj() [1/2]

GSocketListener * Gio::SocketListener::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GSocketListener * Gio::SocketListener::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GSocketListener * Gio::SocketListener::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ operator=()

SocketListener & Gio::SocketListener::operator= ( SocketListener &&  src)
noexcept

◆ property_listen_backlog() [1/2]

Glib::PropertyProxy< int > Gio::SocketListener::property_listen_backlog ( )

outstanding connections in the listen queue.

Default value: 10

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_listen_backlog() [2/2]

Glib::PropertyProxy_ReadOnly< int > Gio::SocketListener::property_listen_backlog ( ) const

outstanding connections in the listen queue.

Default value: 10

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ set_backlog()

void Gio::SocketListener::set_backlog ( int  listen_backlog)

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 g_socket_listener_add_inet_port()) to be effective.

See g_socket_set_listen_backlog() for details

Since glibmm 2.22:
Parameters
listen_backlogAn integer.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gio::SocketListener > wrap ( GSocketListener *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.