glibmm  2.31.22
Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions
Gio::SocketService Class Reference

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

#include <giomm/socketservice.h>

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

List of all members.

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

Static Public Member Functions

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

Related Functions

(Note that these are not member functions.)

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

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]

Member Function Documentation

Reimplemented from Gio::SocketListener.

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.

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 
) [protected, virtual]

This is a default handler for the signal 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:
connectionA new SocketConnection object.
source_objectThe source_object passed to g_socket_listener_add_address().
Returns:
true to stop other handlers from being called.

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:

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