Method

GioSocketcreate_source

since: 2.22

Declaration

GSource*
g_socket_create_source (
  GSocket* socket,
  GIOCondition condition,
  GCancellable* cancellable
)

Description

Creates a GSource that can be attached to a %GMainContext to monitor for the availability of the specified condition on the socket. The GSource keeps a reference to the socket.

The callback on the source is of the GSocketSourceFunc type.

It is meaningless to specify G_IO_ERR or G_IO_HUP in condition; these conditions will always be reported output if they are true.

cancellable if not NULL can be used to cancel the source, which will cause the source to trigger, reporting the current condition (which is likely 0 unless cancellation happened at the same time as a condition change). You can check for this in the callback using g_cancellable_is_cancelled().

If socket has a timeout set, and it is reached before condition occurs, the source will then trigger anyway, reporting G_IO_IN or G_IO_OUT depending on condition. However, socket will have been marked as having had a timeout, and so the next GSocket I/O method you call will then fail with a G_IO_ERROR_TIMED_OUT.

Available since: 2.22

This method is not directly available to language bindings.

Parameters

condition

Type: GIOCondition

A GIOCondition mask to monitor.

cancellable

Type: GCancellable

A %GCancellable or NULL.

The argument can be NULL.
The data is owned by the caller of the function.

Return value

Type: GSource

A newly allocated %GSource, free with g_source_unref().

The caller of the method takes ownership of the data, and is responsible for freeing it.