Package ch.bailu.gtk.gio
Class SocketService
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gio.SocketListener
ch.bailu.gtk.gio.SocketService
- All Implemented Interfaces:
PointerInterface
- Direct Known Subclasses:
ThreadedSocketService
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 #GSocketService::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
g_socket_service_new() and to connect to the #GSocketService::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][g-main-context-push-thread-default-context]
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.
is provided to the network or over local sockets. When a new
connection is made to the service the #GSocketService::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
g_socket_service_new() and to connect to the #GSocketService::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][g-main-context-push-thread-default-context]
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gio.SocketListener
SocketListener.OnAsyncReadyCallback, SocketListener.OnEvent
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gio.SocketListener
SIGNAL_ON_EVENT
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionCreates a new #GSocketService with no sockets to listen for.SocketService
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionstatic ClassHandler
static int
static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
boolean
isActive()
Check whether the service is active or not.onIncoming
(SocketService.OnIncoming signal) Connect to signal "incoming".void
start()
Restarts 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.Methods inherited from class ch.bailu.gtk.gio.SocketListener
acceptAsync, acceptSocketAsync, addAnyInetPort, addInetPort, addSocket, close, onEvent, setBacklog
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_INCOMING
- See Also:
-
-
Constructor Details
-
SocketService
-
SocketService
public SocketService()Creates a new #GSocketService with no sockets to listen for.
New listeners can be added with e.g. g_socket_listener_add_address()
or g_socket_listener_add_inet_port().
New services are created active, there is no need to call
g_socket_service_start(), unless g_socket_service_stop() has been
called before.
-
-
Method Details
-
getClassHandler
-
isActive
public boolean isActive()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.- Returns:
- %TRUE if the service is active, %FALSE otherwise
-
start
public void start()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
g_socket_service_stop().
This call is thread-safe, so it may be called from a thread
handling an incoming client request. -
stop
public void 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.
Note that this only stops accepting new connections; it does not
close the listening sockets, and you can call
g_socket_service_start() again later to begin listening again. To
close the listening sockets, call g_socket_listener_close(). (This
will happen automatically when the #GSocketService is finalized.)
This must be called before calling g_socket_listener_close() as
the socket service will start accepting connections immediately
when a new socket is added. -
onIncoming
Connect to signal "incoming".
SeeSocketService.OnIncoming.onIncoming(ch.bailu.gtk.gio.SocketConnection, ch.bailu.gtk.gobject.Object)
for signal description.
FieldSIGNAL_ON_INCOMING
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-