glibmm: Gio::SocketService Class Reference

glibmm 2.36.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

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

Make it easy to implement a network service. More...

`#include <giomm/socketservice.h>`

Inheritance diagram for Gio::SocketService:
[legend]

## Public Member Functions
virtual | ~SocketService ()
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 ()
| Starts 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::SignalProxy2< bool, const Glib::RefPtr < SocketConnection >&, const Glib::RefPtr< Glib::Object >& > | signal_incoming ()
Public Member Functions inherited from Gio::SocketListener
virtual | ~SocketListener ()
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, 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.
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.
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::PropertyProxy< int > | property_listen_backlog ()
| outstanding connections in the listen queue.
Glib::PropertyProxy_ReadOnly< int > | property_listen_backlog () const
| outstanding connections in the listen queue.
Public Member Functions inherited from Glib::Object
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
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.
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, but this is necessary when using the reduced API.
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, but this is necessary when using the reduced API.
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_copy () const
| Give a ref-ed copy to someone. Use for direct struct access.
Public Member Functions inherited from sigc::trackable
| trackable ()
| trackable (const trackable &src)
| ~trackable ()
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
void | remove_destroy_notify_callback (void *data) const

## 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 < SocketService > | create ()

## Protected Member Functions
| 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)
virtual | ~Object ()
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.
virtual | ~ObjectBase ()=0
void | initialize (GObject* castitem)

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

## Additional Inherited Members
Public Types inherited from Glib::Object
typedef void(* | DestroyNotify )(gpointer data)

## Detailed Description

Make it easy to implement a network service.

See Also
  ThreadedSocketService, SocketListener.

A SocketService is an object that represents a service that is provided to the network or over local sockets. When a new connection is made to the service the SocketService:incoming signal is emitted.

A SocketService is a subclass of SocketListener and you need to add the addresses you want to accept connections on to the with the SocketListener APIs.

There are two options for implementing a network service based on SocketService. The first is to create the service using g_socket_service_new() and to connect to the SocketService:incoming signal. The second is to subclass SocketService and override the default signal handler implementation.

In either case, the handler must immediately return, or else it will block additional incoming connections from being serviced. If you are interested in writing connection handlers that contain blocking code then see ThreadedSocketService.

The socket service runs on the main loop in the main thread, and is not threadsafe in general. However, the calls to start and stop the service are threadsafe so these can be used from threads that handle incoming clients.

Since glibmm 2.24:

## Constructor & Destructor Documentation

virtual Gio::SocketService::~SocketService | ( |  | ) |
| virtual

Gio::SocketService::SocketService | ( |  | ) |
| protected

## Member Function Documentation

static Glib::RefPtr<SocketService> Gio::SocketService::create | ( |  | ) |
| static

Reimplemented from Gio::SocketListener.

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

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

Reimplemented from Gio::SocketListener.

Reimplemented in Gio::ThreadedSocketService.

GSocketService* Gio::SocketService::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

Reimplemented from Gio::SocketListener.

Reimplemented in Gio::ThreadedSocketService.

const GSocketService* Gio::SocketService::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

Reimplemented from Gio::SocketListener.

Reimplemented in Gio::ThreadedSocketService.

GSocketService* Gio::SocketService::gobj_copy | ( |  | ) |

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

Reimplemented from Gio::SocketListener.

Reimplemented in Gio::ThreadedSocketService.

bool Gio::SocketService::is_active | ( |  | ) |

Check whether the service is active or not.

An active service will accept new clients that connect, while a non-active service will let connecting clients queue up until the service is started.

Since glibmm 2.22:

Returns
  `true` if the service is active, `false` otherwise.

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

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

Glib::SignalProxy2< bool,const Glib::RefPtr<SocketConnection>&,const Glib::RefPtr<Glib::Object>& > Gio::SocketService::signal_incoming | ( |  | ) |

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

The signal_incoming() signal is emitted when a new incoming connection to service needs to be handled. The handler must initiate the handling of connection, but may not block; in essence, asynchronous operations must be used.

connection will be unreffed once the signal handler returns, so you need to ref it yourself if you are planning to use it.

Since glibmm 2.22:

Parameters

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

Returns
  `true` to stop other handlers from being called.

void Gio::SocketService::start | ( |  | ) |

Starts the service, i.e. start accepting connections from the added sockets when the mainloop runs.

This call is thread-safe, so it may be called from a thread handling an incoming client request.

Since glibmm 2.22:

void Gio::SocketService::stop | ( |  | ) |

Stops the service, i.e. stops accepting connections from the added sockets when the mainloop runs.

This call is thread-safe, so it may be called from a thread handling an incoming client request.

Since glibmm 2.22:

## Friends And Related Function Documentation

Glib::RefPtr< Gio::SocketService > wrap | ( | GSocketService * | 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.