Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: SocketService

[30:7] extends: object

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 [signal@Gio.SocketService::incoming] signal is emitted. A GSocketService is a subclass of [class@Gio.SocketListener] and you need to add the addresses you want to accept connections on with the [class@Gio.SocketListener] APIs. There are two options for implementing a network service based on GSocketService. The first is to create the service using [ctor@Gio.SocketService.new] and to connect to the [signal@Gio.SocketService::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 [class@Gio.ThreadedSocketService]. The socket service runs on the main loop of the thread-default context (see [method@GLib.MainContext.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.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

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

  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asSocketListener ()

    Wraps this handle as SocketListener.

    • @r A SocketListener object.
  • connectSignal (string Name, CallbackObj)

    Connects one generated callback wrapper to a named signal.

    • @p Name is the signal name.
    • @p CallbackObj is the generated callback wrapper to connect.
    • @r The connected handler id.
  • disconnectSignalHandler (int HandlerId)

    Disconnects one retained signal handler id.

    • @p HandlerId is the signal handler id to disconnect.
    • @r None.
  • setOnIncoming (callback Fn, UserData = null)

    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.
    • @p Fn is the Aussom callback.
    • @p Fn is called with (SocketService Self, SocketConnection Connection, Object Source_object).
    • @p UserData is retained and passed through to the generated callback wrapper when provided.
    • @r The connected handler id.
  • getProperty (string Name)

    Reads one generated property by name.

  • setProperty (string Name, Value)

    Writes one generated property by name.

  • setActive (bool Value)

    Whether the service is currently accepting connections.

    • @p Value is the new property value.
    • @r None.
  • 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.

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

    • @r None.
  • 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.

    • @r None.

class: SocketServiceIncomingCallback

[243:7] extends: object

Generated low-level callback wrapper for GIR callback incoming.

Members

  • callbackObj
  • userFn
  • userData
  • hasUserData

Methods

  • SocketServiceIncomingCallback (callback Fn, UserData = null)

    Creates one native callback wrapper. The wrapper owns a trampoline that converts native pointers into generated wrapper objects before invoking Fn.

    • @p Fn is the Aussom callback implementation.
    • @p UserData is retained and passed through to Fn on each invocation when provided.
  • trampoline (nativeSelf, connection, source_object, nativeUserData)

    Internal trampoline. Converts native pointer arguments into generated wrapper instances, then invokes the user's callback.

  • callback ()

    Returns the wrapped NativeCallback.

  • handle ()

    Returns the callback as a NativeHandle.

  • close ()

    Closes the underlying NativeCallback.

  • isClosed ()

    Returns true when the callback has been closed.

class: SocketServiceMeta

[315:14] static extends: object

Generated metadata helpers for SocketService class surfaces.

Methods

  • properties ()

    Returns property metadata for SocketService.

    • @r A list.
  • signals ()

    Returns signal metadata for SocketService.

    • @r A list.