Class: Gio::SocketListener

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Overview

Class structure for GSocket::Listener.

Instance Method Summary collapse

Instance Method Details

#accept(source_object, cancellable) ⇒ Gio::SocketConnection

Blocks waiting for a client to connect to any of the sockets added to the listener. Returns a GSocket::Connection for the socket that was accepted.

If source_object is not nil it will be filled out with the source object specified when the corresponding socket or address was added to the listener.

If cancellable is not nil, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.

Parameters:

  • source_object (GObject::Object)

    location where #GObject pointer will be stored, or nil

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore.

Returns:

#accept_async(cancellable, callback, user_data) ⇒ nil

This is the asynchronous version of g_socket_listener_accept().

When the operation is finished callback will be called. You can then call g_socket_listener_accept_socket() to get the result of the operation.

Parameters:

  • cancellable (Gio::Cancellable)

    a #GCancellable, or nil

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback

  • user_data (GObject)

    user data for the callback

Returns:

  • (nil)

#accept_finish(result, source_object) ⇒ Gio::SocketConnection

Finishes an async accept operation. See g_socket_listener_accept_async()

Parameters:

  • result (Gio::AsyncResult)

    a GAsync::Result.

  • source_object (GObject::Object)

    Optional #GObject identifying this source

Returns:

#accept_socket(source_object, cancellable) ⇒ Gio::Socket

Blocks waiting for a client to connect to any of the sockets added to the listener. Returns the #GSocket that was accepted.

If you want to accept the high-level GSocket::Connection, not a #GSocket, which is often the case, then you should use g_socket_listener_accept() instead.

If source_object is not nil it will be filled out with the source object specified when the corresponding socket or address was added to the listener.

If cancellable is not nil, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.

Parameters:

  • source_object (GObject::Object)

    location where #GObject pointer will be stored, or nil.

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore.

Returns:

  • (Gio::Socket)

    a #GSocket on success, nil on error.

#accept_socket_async(cancellable, callback, user_data) ⇒ nil

This is the asynchronous version of g_socket_listener_accept_socket().

When the operation is finished callback will be called. You can then call g_socket_listener_accept_socket_finish() to get the result of the operation.

Parameters:

  • cancellable (Gio::Cancellable)

    a #GCancellable, or nil

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback

  • user_data (GObject)

    user data for the callback

Returns:

  • (nil)

#accept_socket_finish(result, source_object) ⇒ Gio::Socket

Finishes an async accept operation. See g_socket_listener_accept_socket_async()

Parameters:

  • result (Gio::AsyncResult)

    a GAsync::Result.

  • source_object (GObject::Object)

    Optional #GObject identifying this source

Returns:

  • (Gio::Socket)

    a #GSocket on success, nil on error.

#add_address(address, type, protocol, source_object, effective_address) ⇒ TrueClass

Creates a socket of type type and protocol protocol, binds it to address and adds it to the set of sockets we’re accepting sockets from.

Note that adding an IPv6 address, depending on the platform, may or may not result in a listener that also accepts IPv4 connections. For more deterministic behavior, see g_socket_listener_add_inet_port().

source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to.

If successful and effective_address is non-nil then it will be set to the address that the binding actually occurred at. This is helpful for determining the port number that was used for when requesting a binding to port 0 (ie: “any port”). This address, if requested, belongs to the caller and must be freed.

Call g_socket_listener_close() to stop listening on address; this will not be done automatically when you drop your final reference to listener, as references may be held internally.

Parameters:

Returns:

  • (TrueClass)

    true on success, false on error.

#add_any_inet_port(source_object) ⇒ Integer

Listens for TCP connections on any available port number for both IPv6 and IPv4 (if each is available).

This is useful if you need to have a socket for incoming connections but don’t care about the specific port number.

source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to.

Parameters:

  • source_object (GObject::Object)

    Optional #GObject identifying this source

Returns:

  • (Integer)

    the port number, or 0 in case of failure.

#add_inet_port(port, source_object) ⇒ TrueClass

Helper function for g_socket_listener_add_address() that creates a TCP/IP socket listening on IPv4 and IPv6 (if supported) on the specified port on all interfaces.

source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to.

Call g_socket_listener_close() to stop listening on port; this will not be done automatically when you drop your final reference to listener, as references may be held internally.

Parameters:

  • port (Integer)

    an IP port number (non-zero)

  • source_object (GObject::Object)

    Optional #GObject identifying this source

Returns:

  • (TrueClass)

    true on success, false on error.

#add_socket(socket, source_object) ⇒ TrueClass

Adds socket to the set of sockets that we try to accept new clients from. The socket must be bound to a local address and listened to.

source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to.

The socket will not be automatically closed when the listener is finalized unless the listener held the final reference to the socket. Before GLib 2.42, the socket was automatically closed on finalization of the listener, even if references to it were held elsewhere.

Parameters:

  • socket (Gio::Socket)

    a listening #GSocket

  • source_object (GObject::Object)

    Optional #GObject identifying this source

Returns:

  • (TrueClass)

    true on success, false on error.

#backlog=(listen_backlog) ⇒ nil

Sets the listen backlog on the sockets in the listener. This must be called before adding any sockets, addresses or ports to the GSocket::Listener (for example, by calling g_socket_listener_add_inet_port()) to be effective.

See g_socket_set_listen_backlog() for details

Parameters:

  • listen_backlog (Integer)

    an integer

Returns:

  • (nil)

#closenil

Closes all the sockets in the listener.

Returns:

  • (nil)

#listen_backlogInteger

Returns listen-backlog.

Returns:

  • (Integer)

    listen-backlog

#listen_backlog=(listen_backlog) ⇒ Integer

Parameters:

  • listen_backlog (Integer)

Returns:

  • (Integer)

    listen-backlog

  • (Integer)

    listen-backlog

#newGio::SocketListener

Creates a new GSocket::Listener 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().

Returns: