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

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)

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

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

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

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

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

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

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

This call is threadsafe, so it may be called from a thread handling an incomming 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 threadsafe, so it may be called from a thread handling an incomming 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.