1.81 <GSocketConnection>

Class: <GSocketConnection>

It derives from <GIOStream>.

<GSocketConnection> is a <GIOStream> for a connected socket. They can be created either by <GSocketClient> when connecting to a host, or by <GSocketListener> when accepting a new client.

The type of the <GSocketConnection> object returned from these calls depends on the type of the underlying socket that is in use. For instance, for a TCP/IP connection it will be a <GTcpConnection>.

Choosing what type of object to construct is done with the socket connection factory, and it is possible for third parties to register custom socket connection types for specific combination of socket family/type/protocol using socket-connection:factory-register-type.

To close a <GSocketConnection>, use iostream:close?. Closing both substreams of the <GIOStream> separately will not close the underlying <GSocket>.

Fields

parent-instance
priv

Properties

Property: socket-connection:socket self

The underlying <GSocket>.

Its value is a <GSocket>, or #f.

It can only be set when the object is made, with #:socket.

Procedures

Method: socket-connection:connect-async self address [cancellable] [callback]
Method: connect-async self address [cancellable] [callback]

Asynchronously connect self to the specified remote address.

This clears the socket:blocking flag on self’s underlying socket if it is currently set.

If socket:timeout is set, the operation will time out and return timed-out after that period. Otherwise, it will continue indefinitely until operating system timeouts (if any) are hit.

Use socket-connection:connect-finish? to retrieve the result.

self

Passed: a <GSocketConnection>.

a <GSocketConnection>

address

Passed: a <GSocketAddress>.

a <GSocketAddress> specifying the remote address.

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable> or #f

callback

Passed, or left out: a procedure, or #f.

a GAsyncReadyCallback

See GAsyncReadyCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

user data for the callback

Method: socket-connection:connect-finish? self result ⇒ %return
Method: connect-finish? self result ⇒ %return

Gets the result of a socket-connection:connect-async call.

self

Passed: a <GSocketConnection>.

a <GSocketConnection>

result

Passed: a <GAsyncResult>.

the <GAsyncResult>

%return

Returned: a boolean.

#t if the connection succeeded, #f on error

Method: socket-connection:connect? self address [cancellable] ⇒ %return
Method: connect? self address [cancellable] ⇒ %return

Connect self to the specified remote address.

self

Passed: a <GSocketConnection>.

a <GSocketConnection>

address

Passed: a <GSocketAddress>.

a <GSocketAddress> specifying the remote address.

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable> or #f

%return

Returned: a boolean.

#t if the connection succeeded, #f on error

Procedure: socket-connection:factory-lookup-type family type protocol-id ⇒ %return

Looks up the GType to be used when creating socket connections on sockets with the specified family, type and protocol-id.

If no type is registered, the <GSocketConnection> base type is returned.

family

Passed: a <GSocketFamily>, or one of its symbols.

a <GSocketFamily>

type

Passed: a <GSocketType>, or one of its symbols.

a <GSocketType>

protocol-id

Passed: a 32-bit integer.

a protocol id

%return

Returned: a class, or a GType number.

a GType

Procedure: socket-connection:factory-register-type g-type family type protocol

Looks up the GType to be used when creating socket connections on sockets with the specified family, type and protocol.

If no type is registered, the <GSocketConnection> base type is returned.

g-type

Passed: a class, or a GType number.

a GType, inheriting from G_TYPE_SOCKET_CONNECTION

family

Passed: a <GSocketFamily>, or one of its symbols.

a <GSocketFamily>

type

Passed: a <GSocketType>, or one of its symbols.

a <GSocketType>

protocol

Passed: a 32-bit integer.

a protocol id

Method: socket-connection:get-local-address self ⇒ %return
Method: get-local-address self ⇒ %return

Try to get the local address of a socket connection.

self

Passed: a <GSocketConnection>.

a <GSocketConnection>

%return

Returned: a <GSocketAddress>.

a <GSocketAddress> or #f on error. Free the returned object with object:unref.

Method: socket-connection:get-remote-address self ⇒ %return
Method: get-remote-address self ⇒ %return

Try to get the remote address of a socket connection.

Since GLib 2.40, when used with socket-client:connect or socket-client:connect-async, during emission of connecting, this function will return the remote address that will be used for the connection. This allows applications to print e.g. "Connecting to example.com (10.42.77.3)...".

self

Passed: a <GSocketConnection>.

a <GSocketConnection>

%return

Returned: a <GSocketAddress>.

a <GSocketAddress> or #f on error. Free the returned object with object:unref.

Method: socket-connection:get-socket self ⇒ %return
Method: get-socket self ⇒ %return

Gets the underlying <GSocket> object of the connection. This can be useful if you want to do something unusual on it not supported by the <GSocketConnection> APIs.

self

Passed: a <GSocketConnection>.

a <GSocketConnection>

%return

Returned: a <GSocket>.

a <GSocket> or #f on error.

Method: socket-connection:is-connected? self ⇒ %return
Method: is-connected? self ⇒ %return

Checks if self is connected. This is equivalent to calling socket:is-connected? on self’s underlying <GSocket>.

self

Passed: a <GSocketConnection>.

a <GSocketConnection>

%return

Returned: a boolean.

whether self is connected