glibmm: Gio::ThreadedSocketService Class Reference

glibmm 2.86.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Gio::ThreadedSocketService Class Reference
Portable Network I/O Functionality

A threaded GSocketService. More...

`#include <giomm/threadedsocketservice.h>`

Inheritance diagram for Gio::ThreadedSocketService:
[legend]

## Public Member Functions
| ThreadedSocketService (ThreadedSocketService && src) noexcept
ThreadedSocketService & | operator= (ThreadedSocketService && src) noexcept
| ~ThreadedSocketService () noexcept override
GThreadedSocketService * | gobj ()
| Provides access to the underlying C GObject.
const GThreadedSocketService * | gobj () const
| Provides access to the underlying C GObject.
GThreadedSocketService * | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
Glib::SignalProxy< bool(const Glib::RefPtr< SocketConnection > &, const Glib::RefPtr< Glib::Object > &)> | signal_run ()
Glib::PropertyProxy_ReadOnly< int > | property_max_threads () const
| The maximum number of threads handling clients for this service.
Public Member Functions inherited from Gio::SocketService
| SocketService (SocketService && src) noexcept
SocketService & | operator= (SocketService && src) noexcept
| ~SocketService () noexcept override
GSocketService * | gobj ()
| Provides access to the underlying C GObject.
const GSocketService * | gobj () const
| Provides access to the underlying C GObject.
GSocketService * | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
void | start ()
| Restarts the service, i.e. start accepting connections from the added sockets when the mainloop runs.
void | stop ()
| Stops the service, i.e. stops accepting connections from the added sockets when the mainloop runs.
bool | is_active ()
| Check whether the service is active or not.
Glib::SignalProxy< bool(const Glib::RefPtr< SocketConnection > &, const Glib::RefPtr< Glib::Object > &)> | signal_incoming ()
Glib::PropertyProxy< bool > | property_active ()
| Whether the service is currently accepting connections.
Glib::PropertyProxy_ReadOnly< bool > | property_active () const
| Whether the service is currently accepting connections.
Public Member Functions inherited from Gio::SocketListener
| SocketListener (SocketListener && src) noexcept
SocketListener & | operator= (SocketListener && src) noexcept
| ~SocketListener () noexcept override
GSocketListener * | gobj ()
| Provides access to the underlying C GObject.
const GSocketListener * | gobj () const
| Provides access to the underlying C GObject.
GSocketListener * | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
void | set_backlog (int listen_backlog)
| Sets the listen backlog on the sockets in the listener.
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.
bool | add_socket (const Glib::RefPtr< Socket > & socket)
| Adds socket to the set of sockets that we try to accept new clients from.
bool | add_address (const Glib::RefPtr< SocketAddress > & address, Socket::Type type, Socket::Protocol 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.
bool | add_address (const Glib::RefPtr< SocketAddress > & address, Socket::Type type, Socket::Protocol 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.
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.
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.
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).
guint16 | add_any_inet_port ()
| Listens for TCP connections on any available port number for both IPv6 and IPv4 (if each is available).
Glib::RefPtr< Socket > | 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.
Glib::RefPtr< Socket > | accept_socket (Glib::RefPtr< Glib::Object > & source_object)
| Blocks waiting for a client to connect to any of the sockets added to the listener.
Glib::RefPtr< Socket > | accept_socket (const Glib::RefPtr< Cancellable > & cancellable)
| Blocks waiting for a client to connect to any of the sockets added to the listener.
Glib::RefPtr< Socket > | accept_socket ()
| Blocks waiting for a client to connect to any of the sockets added to the listener.
void | accept_socket_async (const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot)
| This is the asynchronous version of g_socket_listener_accept_socket().
void | accept_socket_async (const SlotAsyncReady & slot)
| This is the asynchronous version of g_socket_listener_accept_socket().
Glib::RefPtr< Socket > | accept_socket_finish (const Glib::RefPtr< AsyncResult > & result, Glib::RefPtr< Glib::Object > & source_object)
| Finishes an async accept operation.
Glib::RefPtr< Socket > | accept_socket_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes an async accept operation.
Glib::RefPtr< SocketConnection > | 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.
Glib::RefPtr< SocketConnection > | accept (Glib::RefPtr< Object > & source_object)
| Blocks waiting for a client to connect to any of the sockets added to the listener.
Glib::RefPtr< SocketConnection > | accept (const Glib::RefPtr< Cancellable > & cancellable)
| Blocks waiting for a client to connect to any of the sockets added to the listener.
Glib::RefPtr< SocketConnection > | accept ()
| Blocks waiting for a client to connect to any of the sockets added to the listener.
void | accept_async (const SlotAsyncReady & slot)
| This is the asynchronous version of g_socket_listener_accept().
void | accept_async (const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot)
| This is the asynchronous version of g_socket_listener_accept().
Glib::RefPtr< SocketConnection > | accept_finish (const Glib::RefPtr< AsyncResult > & result, Glib::RefPtr< Glib::Object > & source_object)
| Finishes an async accept operation.
Glib::RefPtr< SocketConnection > | accept_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes an async accept operation.
void | close ()
| Closes all the sockets in the listener.
Glib::SignalProxy< void(Event, const Glib::RefPtr< Socket > &)> | signal_event ()
Glib::PropertyProxy< int > | property_listen_backlog ()
| The number of outstanding connections in the listen queue.
Glib::PropertyProxy_ReadOnly< int > | property_listen_backlog () const
| The number of outstanding connections in the listen queue.
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object && src) noexcept
Object & | operator= (Object && src) noexcept
void * | get_data (const QueryQuark & key)
void | set_data (const Quark & key, void *data)
void | set_data_with_c_callback (const Quark & key, void *data, GDestroyNotify notify)
void | set_data (const Quark & key, void *data, DestroyNotify notify)
| Prefer set_data_with_c_callback() with a callback with C linkage.
void | remove_data (const QueryQuark & quark)
void * | steal_data (const QueryQuark & quark)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (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.
void | get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const
| You probably want to use a specific property_*() accessor method instead.
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.
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.
template<class PropertyType>
PropertyType | get_property (const Glib::ustring & property_name) const
| You probably want to use a specific property_*() accessor method instead.
sigc::connection | 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.
sigc::connection | connect_property_changed (const Glib::ustring & property_name, sigc::slot< void()> && slot)
| You can use the signal_changed() signal of the property proxy instead.
void | freeze_notify ()
| Increases the freeze count on object.
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify().
virtual void | reference () const
| Increment the reference count for this object.
virtual void | unreference () const
| Decrement the reference count for this object.
GObject * | gobj ()
| Provides access to the underlying C GObject.
const GObject * | gobj () const
| Provides access to the underlying C GObject.
GObject * | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access.

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.
static Glib::RefPtr< ThreadedSocketService > | create (int max_threads)
Static Public Member Functions inherited from Gio::SocketService
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.
static Glib::RefPtr< SocketService > | create ()
Static Public Member Functions inherited from Gio::SocketListener
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.
static Glib::RefPtr< SocketListener > | create ()

## Protected Member Functions
| ThreadedSocketService (int max_threads)
virtual bool | on_run (const Glib::RefPtr< SocketConnection > & connection, const Glib::RefPtr< Glib::Object > & source_object)
| This is a default handler for the signal signal_run().
Protected Member Functions inherited from Gio::SocketService
| SocketService ()
virtual bool | on_incoming (const Glib::RefPtr< SocketConnection > & connection, const Glib::RefPtr< Glib::Object > & source_object)
| This is a default handler for the signal signal_incoming().
Protected Member Functions inherited from Gio::SocketListener
| 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.
| ObjectBase (const char * custom_type_name)
| A derived constructor always overrides this choice.
| 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.
| ObjectBase (ObjectBase && src) noexcept
ObjectBase & | operator= (ObjectBase && src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject * castitem)
void | initialize_move (GObject * castitem, Glib::ObjectBase * previous_wrapper)

## Related Symbols
(Note that these are not member symbols.)
Glib::RefPtr< Gio::ThreadedSocketService > | wrap (GThreadedSocketService * object, bool take_copy=false)
| A Glib::wrap() method for this object.
Related Symbols inherited from Gio::SocketService
Glib::RefPtr< Gio::SocketService > | wrap (GSocketService * object, bool take_copy=false)
| A Glib::wrap() method for this object.
Related Symbols inherited from Gio::SocketListener
Glib::RefPtr< Gio::SocketListener > | wrap (GSocketListener * object, bool take_copy=false)
| A Glib::wrap() method for this object.
Related Symbols inherited from Glib::Object
Glib::RefPtr< Glib::Object > | wrap (GObject * object, bool take_copy=false)

## Additional Inherited Members
Public Types inherited from Gio::SocketListener
enum class | Event { Event::BINDING , Event::BOUND , Event::LISTENING , Event::LISTENED }
| Describes an event occurring on a SocketListener. More...
Public Types inherited from Glib::Object
using | DestroyNotify = void (*)(gpointer data)

## Detailed Description

A threaded GSocketService.

A ThreadedSocketService is a simple subclass of SocketService that handles incoming connections by creating a worker thread and dispatching the connection to it by emitting the run signal in the new thread.

The signal handler may perform blocking IO and need not return until the connection is closed.

The service is implemented using a thread pool, so there is a limited amount of threads availible to serve incomming requests. The service automatically stops the SocketService from accepting new connections when all threads are busy.

As with SocketService, you may connect to ThreadedSocketService::signal_run(), or subclass and override the default handler.

Since glibmm 2.24

## Constructor & Destructor Documentation

## ◆ ThreadedSocketService() [1/2]

Gio::ThreadedSocketService::ThreadedSocketService | ( | ThreadedSocketService && | src | ) |
| noexcept

## ◆ ~ThreadedSocketService()

Gio::ThreadedSocketService::~ThreadedSocketService | ( |  | ) |
| overridenoexcept

## ◆ ThreadedSocketService() [2/2]

Gio::ThreadedSocketService::ThreadedSocketService | ( | int | max_threads | ) |
| explicitprotected

## Member Function Documentation

## ◆ create()

Glib::RefPtr< ThreadedSocketService > Gio::ThreadedSocketService::create | ( | int | max_threads | ) |
| static

## ◆ get_type()

GType Gio::ThreadedSocketService::get_type | ( |  | ) |
| static

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

## ◆ gobj() [1/2]

GThreadedSocketService * Gio::ThreadedSocketService::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GThreadedSocketService * Gio::ThreadedSocketService::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ gobj_copy()

GThreadedSocketService * Gio::ThreadedSocketService::gobj_copy | ( |  | ) |

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

## ◆ on_run()

virtual bool Gio::ThreadedSocketService::on_run | ( | const Glib::RefPtr< SocketConnection > & | connection,
|  | const Glib::RefPtr< Glib::Object > & | source_object )
| protectedvirtual

This is a default handler for the signal signal_run().

## ◆ operator=()

ThreadedSocketService & Gio::ThreadedSocketService::operator= | ( | ThreadedSocketService && | src | ) |
| noexcept

## ◆ property_max_threads()

Glib::PropertyProxy_ReadOnly< int > Gio::ThreadedSocketService::property_max_threads | ( |  | ) | const

The maximum number of threads handling clients for this service.

Since glibmm 2.22

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.

## ◆ signal_run()

Glib::SignalProxy< bool(const Glib::RefPtr< SocketConnection > &, const Glib::RefPtr< Glib::Object > &)> Gio::ThreadedSocketService::signal_run | ( |  | ) |

Slot Prototype:
  bool on_my_run(const Glib::RefPtr<SocketConnection>& connection, const Glib::RefPtr<Glib::Object>& source_object)

Flags: Run Last

The signal_run() signal is emitted in a worker thread in response to an incoming connection. This thread is dedicated to handling connection and may perform blocking IO. The signal handler need not return until the connection is closed.

Parameters

  connection | A new SocketConnection object.
  source_object | The source_object passed to g_socket_listener_add_address().

Returns
  true to stop further signal handlers from being called.

## Friends And Related Symbol Documentation

## ◆ wrap()

Glib::RefPtr< Gio::ThreadedSocketService > wrap | ( | GThreadedSocketService * | object,
|  | bool | take_copy = false )
| related

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

Parameters

  object | The C instance.
  take_copy | False 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.