It derives from <GSocketListener>.
A <GSocketService> 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
socket-service:incoming
signal is emitted.
A <GSocketService> is a subclass of
<GSocketListener> and you need to add the
addresses you want to accept connections on with the
<GSocketListener> APIs.
There are two options for implementing a network service based on
<GSocketService>. The first is to create
the service using socket-service:new and
to connect to the socket-service:incoming signal. The second is to subclass
<GSocketService> 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 <GThreadedSocketService>.
The socket service runs on the main loop of the thread-default context
(see main-context:push-thread-default) of the
thread it is created in, and is not threadsafe in general. However, the
calls to start and stop the service are thread-safe so these can be used
from threads that handle incoming clients.
parent-instanceprivWhether the service is currently accepting connections.
Its value is a boolean.
Set it with (set! (socket-service:active self) value).
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.
Passed: a <GSocketService>.
Returned: a boolean.
#t if the service is active, #f otherwise
Creates a new <GSocketService> with no
sockets to listen for. New listeners can be added with e.g.
socket-listener:add-address or
socket-listener:add-inet-port?.
New services are created active, there is no need to call
socket-service:start, unless
socket-service:stop has been called
before.
Returned: a <GSocketService>.
a new <GSocketService>.
Restarts the service, i.e. start accepting connections from the added
sockets when the mainloop runs. This only needs to be called after the
service has been stopped from socket-service:stop.
This call is thread-safe, so it may be called from a thread handling an incoming client request.
Passed: a <GSocketService>.
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.
Note that this only stops accepting new connections; it does not close
the listening sockets, and you can call socket-service:start again later to begin listening again. To
close the listening sockets, call socket-listener:close. (This will happen automatically when
the <GSocketService> is finalized.)
This must be called before calling socket-listener:close as the socket service will start
accepting connections immediately when a new socket is added.
Passed: a <GSocketService>.
Connect a handler with (connect object socket-service:incoming
handler). It is called as (handler self connection
source-object) ⇒ %return.
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.
connection will be unreffed once the signal handler returns, so you need to ref it yourself if you are planning to use it.
Passed: a <GSocketService>.
Passed: a <GSocketConnection>.
a new <GSocketConnection> object
Passed: a <GObject>, or #f.
the source_object passed to socket-listener:add-address
Returned: a boolean.
#t to stop other handlers from being called
signal emitted when new connections are accepted
To override it in a new class, give register-type #:vfuncs
`((incoming . ,procedure)). The procedure is called as
(procedure self connection source-object) ⇒ %return.
Passed: the class whose implementation to call:
<GSocketService>, or a class that derives
from it, or its GType number.
Passed: a <GSocketService>.
Passed: a <GSocketConnection>.
Passed: a <GObject>.
Returned: a boolean.