Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Login

GLib::SocketService

class GLib::SocketService

A GLib::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 “incoming” signal is emitted.

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

There are two options for implementing a network service based on GLib::SocketService. The first is to create the service using GLib::SocketService.new and to connect to the “incoming” signal. The second is to subclass GLib::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 GLib::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.

Class Methods

GLib::SocketService.new
Creates a new GLib::SocketService with no sockets to listen for. New listeners can be added with, for example, GLib::SocketListener#add_address or GLib::SocketListener#add_inet_port.

Instance Methods

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 2.22

  • Returns: true if the service is active
start

Starts the service, that is, 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 2.22

  • Returns: self
stop

Stops the service, that is, 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 2.22

  • Returns: self

Signals

incoming: self, connection, source_object
The ::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.
Last modified:2010/12/27 21:59:23
Keyword(s):
References:[GLib::ThreadedSocketService] [Ruby/GIO] [index-ruby-glib2] [index-ruby-gio2] [GLib::SocketService] [GLib::SocketListener]