Optionalproperties: Partial<Gio.Socket.ConstructorProps>Internal$signalsCompile-time signal type information.
This instance property is generated only for TypeScript type checking. It is not defined at runtime and should not be accessed in JS code.
Static$gtypeSince 2.22blockingSince 2.32broadcastConstruct OnlySince 2.22familyConstruct OnlySince 2.22fdSince 2.22keepaliveSince 2.22listen_Since 2.22listenRead-OnlySince 2.22local_Read-OnlySince 2.22localSince 2.32multicast_Since 2.32multicast_Since 2.32multicastSince 2.32multicastConstruct OnlySince 2.22protocolRead-OnlySince 2.22remote_Read-OnlySince 2.22remoteSince 2.26timeoutSince 2.32ttlConstruct OnlySince 2.22typeAccept incoming connections on a connection-based socket. This removes the first outstanding connection request from the listening socket and creates a Gio.Socket object for it.
The socket must be bound to a local address with g_socket_bind() and
must be listening for incoming connections (g_socket_listen()).
If there are no outstanding connections then the operation will block or return Gio.IOErrorEnum.WOULD_BLOCK if non-blocking I/O is enabled. To be notified of an incoming connection, wait for the GObject.IOCondition.IN condition.
Optionalcancellable: Gio.Cancellablea %GCancellable or null
a new Gio.Socket, or null on error. Free the returned object with g_object_unref().
When a socket is created it is attached to an address family, but it
doesn't have an address in this family. g_socket_bind() assigns the
address (sometimes called name) of the socket.
It is generally required to bind to a local address before you can
receive connections. (See g_socket_listen() and g_socket_accept() ).
In certain situations, you may also want to bind a socket that will be
used to initiate connections, though this is not normally required.
If socket is a TCP socket, then allow_reuse controls the setting
of the SO_REUSEADDR socket option; normally it should be true for
server sockets (sockets that you will eventually call
g_socket_accept() on), and false for client sockets. (Failing to
set this flag on a server socket may cause g_socket_bind() to return
Gio.IOErrorEnum.ADDRESS_IN_USE if the server program is stopped and then
immediately restarted.)
If socket is a UDP socket, then allow_reuse determines whether or
not other UDP sockets can be bound to the same address at the same
time. In particular, you can have several UDP sockets bound to the
same address, and they will all receive all of the multicast and
broadcast packets sent to that address. (The behavior of unicast
UDP packets to an address with multiple listeners is not defined.)
a Gio.SocketAddress specifying the local address.
whether to allow reusing this address
true on success, false on error.
Creates a binding between source_property on source and target_property
on target.
Whenever the source_property is changed the target_property is
updated using the same value. For instance:
g_object_bind_property (action, "active", widget, "sensitive", 0);
Will result in the "sensitive" property of the widget GObject.Object instance to be updated with the same value of the "active" property of the action GObject.Object instance.
If flags contains GObject.BindingFlags.BIDIRECTIONAL then the binding will be mutual:
if target_property on target changes then the source_property on source
will be updated as well.
The binding will automatically be removed when either the source or the
target instances are finalized. To remove the binding without affecting the
source and the target you can just call g_object_unref() on the returned
GObject.Binding instance.
Removing the binding by calling g_object_unref() on it must only be done if
the binding, source and target are only used from a single thread and it
is clear that both source and target outlive the binding. Especially it
is not safe to rely on this if the binding, source or target can be
finalized from different threads. Keep another reference to the binding and
use g_binding_unbind() instead to be on the safe side.
A GObject.Object can have multiple bindings.
the property on source to bind
the target GObject.Object
the property on target to bind
flags to pass to GObject.Binding
the GObject.Binding instance representing the binding between the two GObject.Object instances. The binding is released whenever the GObject.Binding reference count reaches zero.
Complete version of g_object_bind_property().
Creates a binding between source_property on source and target_property
on target, allowing you to set the transformation functions to be used by
the binding.
If flags contains GObject.BindingFlags.BIDIRECTIONAL then the binding will be mutual:
if target_property on target changes then the source_property on source
will be updated as well. The transform_from function is only used in case
of bidirectional bindings, otherwise it will be ignored
The binding will automatically be removed when either the source or the
target instances are finalized. This will release the reference that is
being held on the GObject.Binding instance; if you want to hold on to the
GObject.Binding instance, you will need to hold a reference to it.
To remove the binding, call g_binding_unbind().
A GObject.Object can have multiple bindings.
The same user_data parameter will be used for both transform_to
and transform_from transformation functions; the notify function will
be called once, when the binding is removed. If you need different data
for each transformation function, please use
g_object_bind_property_with_closures() instead.
the property on source to bind
the target GObject.Object
the property on target to bind
flags to pass to GObject.Binding
Optionaltransform_to: BindingTransformFuncthe transformation function from the source to the target, or null to use the default
Optionaltransform_from: BindingTransformFuncthe transformation function from the target to the source, or null to use the default
Optionalnotify: DestroyNotifya function to call when disposing the binding, to free resources used by the transformation functions, or null if not required
the GObject.Binding instance representing the binding between the two GObject.Object instances. The binding is released whenever the GObject.Binding reference count reaches zero.
Creates a binding between source_property on source and target_property
on target, allowing you to set the transformation functions to be used by
the binding.
This function is the language bindings friendly version of
g_object_bind_property_full(), using GClosures instead of
function pointers.
the property on source to bind
the GObject.Binding instance representing the binding between the two GObject.Object instances. The binding is released whenever the GObject.Binding reference count reaches zero.
Blocks a handler of an instance so it will not be called during any signal emissions
Handler ID of the handler to be blocked
Checks and resets the pending connect error for the socket.
This is used to check for errors when g_socket_connect() is
used in non-blocking mode.
true if no error, false otherwise, setting error to the error
Closes the socket, shutting down any active connection.
Closing a socket does not wait for all outstanding I/O operations to finish, so the caller should not rely on them to be guaranteed to complete even if the close returns with no error.
Once the socket is closed, all other operations will return Gio.IOErrorEnum.CLOSED. Closing a socket multiple times will not return an error.
Sockets will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible.
Beware that due to the way that TCP works, it is possible for
recently-sent data to be lost if either you close a socket while the
GObject.IOCondition.IN condition is set, or else if the remote connection tries to
send something to you after you close the socket but before it has
finished reading all of the data you sent. There is no easy generic
way to avoid this problem; the easiest fix is to design the network
protocol such that the client will never send data "out of turn".
Another solution is for the server to half-close the connection by
calling g_socket_shutdown() with only the shutdown_write flag set,
and then wait for the client to notice this and close its side of the
connection, after which the server can safely call g_socket_close().
(This is what Gio.TcpConnection does if you call
g_tcp_connection_set_graceful_disconnect(). But of course, this
only works if the client will close its connection after the server
does.)
true on success, false on error
Checks on the readiness of socket to perform operations.
The operations specified in condition are checked for and masked
against the currently-satisfied conditions on socket. The result
is returned.
Note that on Windows, it is possible for an operation to return
Gio.IOErrorEnum.WOULD_BLOCK even immediately after
g_socket_condition_check() has claimed that the socket is ready for
writing. Rather than calling g_socket_condition_check() and then
writing to the socket if it succeeds, it is generally better to
simply try writing to the socket right away, and try again later if
the initial attempt returns Gio.IOErrorEnum.WOULD_BLOCK.
It is meaningless to specify GObject.IOCondition.ERR or GObject.IOCondition.HUP in condition; these conditions will always be set in the output if they are true.
This call never blocks.
a GObject.IOCondition mask to check
the GIOCondition mask of the current state
Waits for up to timeout_us microseconds for condition to become true
on socket. If the condition is met, true is returned.
If cancellable is cancelled before the condition is met, or if
timeout_us (or the socket's Gio.Socket.timeout) is reached before the
condition is met, then false is returned and error, if non-null,
is set to the appropriate value (Gio.IOErrorEnum.CANCELLED or
Gio.IOErrorEnum.TIMED_OUT).
If you don't want a timeout, use g_socket_condition_wait().
(Alternatively, you can pass -1 for timeout_us.)
Note that although timeout_us is in microseconds for consistency with
other GLib APIs, this function actually only has millisecond
resolution, and the behavior is undefined if timeout_us is not an
exact number of milliseconds.
a GObject.IOCondition mask to wait for
the maximum time (in microseconds) to wait, or -1
Optionalcancellable: Gio.Cancellablea Gio.Cancellable, or null
true if the condition was met, false otherwise
Waits for condition to become true on socket. When the condition
is met, true is returned.
If cancellable is cancelled before the condition is met, or if the
socket has a timeout set and it is reached before the condition is
met, then false is returned and error, if non-null, is set to
the appropriate value (Gio.IOErrorEnum.CANCELLED or
Gio.IOErrorEnum.TIMED_OUT).
See also g_socket_condition_timed_wait().
a GObject.IOCondition mask to wait for
Optionalcancellable: Gio.Cancellablea Gio.Cancellable, or null
true if the condition was met, false otherwise
SignalconnectConnect the socket to the specified remote address.
For connection oriented socket this generally means we attempt to make
a connection to the address. For a connection-less socket it sets
the default address for g_socket_send() and discards all incoming datagrams
from other sources.
Generally connection oriented sockets can only connect once, but connection-less sockets can connect multiple times to change the default address.
If the connect call needs to do network I/O it will block, unless
non-blocking I/O is enabled. Then Gio.IOErrorEnum.PENDING is returned
and the user can be notified of the connection finishing by waiting
for the G_IO_OUT condition. The result of the connection must then be
checked with g_socket_check_connect_result().
a Gio.SocketAddress specifying the remote address.
Optionalcancellable: Gio.Cancellablea %GCancellable or null
true if connected, false on error.
Signalconnect_Creates a Gio.SocketConnection subclass of the right type for
socket.
Creates a GLib.Source that can be attached to a GLib.MainContext to monitor for
the availability of the specified condition on the Gio.DatagramBased. The
GLib.Source keeps a reference to the datagram_based.
The callback on the source is of the Gio.DatagramBasedSourceFunc type.
It is meaningless to specify GObject.IOCondition.ERR or GObject.IOCondition.HUP in condition; these
conditions will always be reported in the callback if they are true.
If non-null, cancellable 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().
a GObject.IOCondition mask to monitor
Optionalcancellable: Gio.Cancellablea newly allocated GLib.Source
Disconnects a handler from an instance so it will not be called during any future or currently ongoing emissions of the signal it has been connected to.
Handler ID of the handler to be disconnected
SignalemitThis function is intended for GObject.Object implementations to re-enforce
a [floating][floating-ref] object reference. Doing this is seldom
required: all GInitiallyUnowneds are created with a floating reference
which usually just needs to be sunken by calling g_object_ref_sink().
Increases the freeze count on object. If the freeze count is
non-zero, the emission of "notify" signals on object is
stopped. The signals are queued until the freeze count is decreased
to zero. Duplicate notifications are squashed so that at most one
GObject.Object::notify signal is emitted for each property modified while the
object is frozen.
This is necessary for accessors that modify multiple properties to prevent premature notification while the object is still being modified.
Get the amount of data pending in the OS input buffer, without blocking.
If socket is a UDP or SCTP socket, this will return the size of
just the next packet, even if additional packets are buffered after
that one.
Note that on Windows, this function is rather inefficient in the
UDP case, and so if you know any plausible upper bound on the size
of the incoming packet, it is better to just do a
g_socket_receive() with a buffer of that size, rather than calling
g_socket_get_available_bytes() first and then doing a receive of
exactly the right size.
the number of bytes that can be read from the socket without blocking or truncating, or -1 on error.
Gets the blocking mode of the socket. For details on blocking I/O,
see g_socket_set_blocking().
true if blocking I/O is used, false otherwise.
Gets the broadcast setting on socket; if true,
it is possible to send packets to broadcast
addresses.
the broadcast setting on socket
Returns the credentials of the foreign process connected to this socket, if any (e.g. it is only supported for Gio.SocketFamily.UNIX sockets).
If this operation isn't supported on the OS, the method fails with
the Gio.IOErrorEnum.NOT_SUPPORTED error. On Linux this is implemented
by reading the SO_PEERCRED option on the underlying socket.
This method can be expected to be available on the following platforms:
Other ways to obtain credentials from a foreign peer includes the
Gio.UnixCredentialsMessage type and
g_unix_connection_send_credentials() /
g_unix_connection_receive_credentials() functions.
null if error is set, otherwise a Gio.Credentials object that must be freed with g_object_unref().
Gets a named field from the objects table of associations (see g_object_set_data()).
name of the key for that association
the data if found, or null if no such data exists.
Returns the underlying OS socket object. On unix this is a socket file descriptor, and on Windows this is a Winsock2 SOCKET handle. This may be useful for doing platform specific or otherwise unusual operations on the socket.
the file descriptor of the socket.
Gets the keepalive mode of the socket. For details on this,
see g_socket_set_keepalive().
true if keepalive is active, false otherwise.
Gets the listen backlog setting of the socket. For details on this,
see g_socket_set_listen_backlog().
the maximum number of pending connections.
Try to get the local address of a bound socket. This is only useful if the socket has been bound to a local address, either explicitly or implicitly when connecting.
a Gio.SocketAddress or null on error. Free the returned object with g_object_unref().
Gets the multicast loopback setting on socket; if true (the
default), outgoing multicast packets will be looped back to
multicast listeners on the same host.
the multicast loopback setting on socket
Gets the multicast time-to-live setting on socket; see
g_socket_set_multicast_ttl() for more details.
the multicast time-to-live setting on socket
Gets the value of an integer-valued option on socket, as with
getsockopt(). (If you need to fetch a non-integer-valued option,
you will need to call getsockopt() directly.)
The <gio/gnetworking.h>
header pulls in system headers that will define most of the
standard/portable socket options. For unusual socket protocols or
platform-dependent options, you may need to include additional
headers.
Note that even for socket options that are a single byte in size,
value is still a pointer to a gint variable, not a guchar;
g_socket_get_option() will handle the conversion internally.
the "API level" of the option (eg, SOL_SOCKET)
the "name" of the option (eg, SO_BROADCAST)
success or failure. On failure, error will be set, and the system error value (errno or WSAGetLastError()) will still be set to the result of the getsockopt() call.
Gets a property of an object.
The value can be:
In general, a copy is made of the property contents and the caller is responsible for freeing the memory by calling GObject.Value.unset.
Note that GObject.Object.get_property is really intended for language bindings, GObject.Object.get is much more convenient for C programming.
The name of the property to get
Return location for the property value. Can be an empty GObject.Value initialized by G_VALUE_INIT (auto-initialized with expected type since GLib 2.60), a GObject.Value initialized with the expected property type, or a GObject.Value initialized with a transformable type
Gets the socket protocol id the socket was created with. In case the protocol is unknown, -1 is returned.
a protocol id, or -1 if unknown
This function gets back user data pointers stored via
g_object_set_qdata().
A GLib.Quark, naming the user data pointer
The user data pointer set, or null
Try to get the remote address of a connected socket. This is only useful for connection oriented sockets that have been connected.
a Gio.SocketAddress or null on error. Free the returned object with g_object_unref().
Gets the timeout setting of the socket. For details on this, see
g_socket_set_timeout().
the timeout in seconds
Gets the unicast time-to-live setting on socket; see
g_socket_set_ttl() for more details.
the time-to-live setting on socket
Gets n_properties properties for an object.
Obtained properties will be set to values. All properties must be valid.
Warnings will be emitted and undefined behaviour may result if invalid
properties are passed in.
the names of each property to get
the values of each property to get
Initializes the object implementing the interface.
This method is intended for language bindings. If writing in C,
g_initable_new() should typically be used instead.
The object must be initialized before any real use after initial
construction, either with this function or g_async_initable_init_async().
Implementations may also support cancellation. If cancellable is not null,
then initialization can be cancelled by triggering the cancellable object
from another thread. If the operation was cancelled, the error
Gio.IOErrorEnum.CANCELLED will be returned. If cancellable is not null and
the object doesn't support cancellable initialization the error
Gio.IOErrorEnum.NOT_SUPPORTED will be returned.
If the object is not initialized, or initialization returns with an
error, then all operations on the object except g_object_ref() and
g_object_unref() are considered to be invalid, and have undefined
behaviour. See the [description][iface@Gio.Initable#description] for more details.
Callers should not assume that a class which implements Gio.Initable can be
initialized multiple times, unless the class explicitly documents itself as
supporting this. Generally, a class’ implementation of init() can assume
(and assert) that it will only be called once. Previously, this documentation
recommended all Gio.Initable implementations should be idempotent; that
recommendation was relaxed in GLib 2.54.
If a class explicitly supports being initialized multiple times, it is recommended that the method is idempotent: multiple calls with the same arguments should return the same results. Only the first call initializes the object; further calls return the result of the first call.
One reason why a class might need to support idempotent initialization is if
it is designed to be used via the singleton pattern, with a
GObject.ObjectClass.constructor that sometimes returns an existing instance.
In this pattern, a caller would expect to be able to call g_initable_init()
on the result of g_object_new(), regardless of whether it is in fact a new
instance.
Optionalcancellable: Gio.Cancellableoptional Gio.Cancellable object, null to ignore.
true if successful. If an error has occurred, this function will return false and set error appropriately if present.
Checks whether a socket is closed.
true if socket is closed, false otherwise
Check whether the socket is connected. This is only useful for connection-oriented sockets.
If using g_socket_shutdown(), this function will return true until the
socket has been shut down for reading and writing. If you do a non-blocking
connect, this function will not return true until after you call
g_socket_check_connect_result().
true if socket is connected, false otherwise.
Checks whether object has a [floating][floating-ref] reference.
true if object has a floating reference
Registers socket to receive multicast messages sent to group.
socket must be a Gio.SocketType.DATAGRAM socket, and must have
been bound to an appropriate interface and port with
g_socket_bind().
If iface is null, the system will automatically pick an interface
to bind to based on group.
If source_specific is true, source-specific multicast as defined
in RFC 4604 is used. Note that on older platforms this may fail
with a Gio.IOErrorEnum.NOT_SUPPORTED error.
To bind to a given source-specific multicast address, use
g_socket_join_multicast_group_ssm() instead.
a Gio.InetAddress specifying the group address to join.
true if source-specific multicast should be used
Optionaliface: stringName of the interface to use, or null
true on success, false on error.
Registers socket to receive multicast messages sent to group.
socket must be a Gio.SocketType.DATAGRAM socket, and must have
been bound to an appropriate interface and port with
g_socket_bind().
If iface is null, the system will automatically pick an interface
to bind to based on group.
If source_specific is not null, use source-specific multicast as
defined in RFC 4604. Note that on older platforms this may fail
with a Gio.IOErrorEnum.NOT_SUPPORTED error.
Note that this function can be called multiple times for the same
group with different source_specific in order to receive multicast
packets from more than one source.
a Gio.InetAddress specifying the group address to join.
Optionalsource_specific: Gio.InetAddressa Gio.InetAddress specifying the source-specific multicast address or null to ignore.
Optionaliface: stringName of the interface to use, or null
true on success, false on error.
Removes socket from the multicast group defined by group, iface,
and source_specific (which must all have the same values they had
when you joined the group).
socket remains bound to its address and port, and can still receive
unicast messages after calling this.
To unbind to a given source-specific multicast address, use
g_socket_leave_multicast_group_ssm() instead.
a Gio.InetAddress specifying the group address to leave.
true if source-specific multicast was used
Optionaliface: stringInterface used
true on success, false on error.
Removes socket from the multicast group defined by group, iface,
and source_specific (which must all have the same values they had
when you joined the group).
socket remains bound to its address and port, and can still receive
unicast messages after calling this.
a Gio.InetAddress specifying the group address to leave.
Optionalsource_specific: Gio.InetAddressa Gio.InetAddress specifying the source-specific multicast address or null to ignore.
Optionaliface: stringName of the interface to use, or null
true on success, false on error.
Marks the socket as a server socket, i.e. a socket that is used
to accept incoming requests using g_socket_accept().
Before calling this the socket must be bound to a local address using
g_socket_bind().
To set the maximum amount of outstanding clients, use
g_socket_set_listen_backlog().
true on success, false on error.
Emits a "notify" signal for the property property_name on object.
When possible, eg. when signaling a property change from within the class
that registered the property, you should use g_object_notify_by_pspec()
instead.
Note that emission of the notify signal may be blocked with
g_object_freeze_notify(). In this case, the signal emissions are queued
and will be emitted (in reverse order) when g_object_thaw_notify() is
called.
the name of a property installed on the class of object.
Emits a "notify" signal for the property specified by pspec on object.
This function omits the property name lookup, hence it is faster than
g_object_notify().
One way to avoid using g_object_notify() from within the
class that registered the properties, and using g_object_notify_by_pspec()
instead, is to store the GParamSpec used with
g_object_class_install_property() inside a static array, e.g.:
typedef enum
{
PROP_FOO = 1,
PROP_LAST
} MyObjectProperty;
static GParamSpec *properties[PROP_LAST];
static void
my_object_class_init (MyObjectClass *klass)
{
properties[PROP_FOO] = g_param_spec_int ("foo", NULL, NULL,
0, 100,
50,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class,
PROP_FOO,
properties[PROP_FOO]);
}
and then notify a change on the "foo" property with:
g_object_notify_by_pspec (self, properties[PROP_FOO]);
the GObject.ParamSpec of a property installed on the class of object.
Receive data (up to size bytes) from a socket. This is mainly used by
connection-oriented sockets; it is identical to g_socket_receive_from()
with address set to null.
For Gio.SocketType.DATAGRAM and Gio.SocketType.SEQPACKET sockets,
g_socket_receive() will always read either 0 or 1 complete messages from
the socket. If the received message is too large to fit in buffer, then
the data beyond size bytes will be discarded, without any explicit
indication that this has occurred.
For Gio.SocketType.STREAM sockets, g_socket_receive() can return any
number of bytes, up to size. If more than size bytes have been
received, the additional data will be returned in future calls to
g_socket_receive().
If the socket is in blocking mode the call will block until there is some data to receive, the connection is closed, or there is an error. If there is no data available and the socket is in non-blocking mode, a Gio.IOErrorEnum.WOULD_BLOCK error will be returned. To be notified when data is available, wait for the GObject.IOCondition.IN condition.
On error -1 is returned and error is set accordingly.
Optionalcancellable: Gio.Cancellablea %GCancellable or null
Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error
Receives data (up to size bytes) from a socket.
This function is a variant of Gio.Socket.receive which returns a GLib.Bytes rather than a plain buffer.
Pass -1 to timeout_us to block indefinitely until data is received (or
the connection is closed, or there is an error). Pass 0 to use the default
timeout from Gio.Socket.timeout, or pass a positive number to wait
for that many microseconds for data before returning G_IO_ERROR_TIMED_OUT.
the number of bytes you want to read from the socket
the timeout to wait for, in microseconds, or -1 to block indefinitely
Optionalcancellable: Gio.Cancellablea %GCancellable, or NULL
a bytes buffer containing the received bytes, or NULL on error
Receive data (up to size bytes) from a socket.
This function is a variant of Gio.Socket.receive_from which returns a GLib.Bytes rather than a plain buffer.
If address is non-null then address will be set equal to the
source address of the received packet.
The address is owned by the caller.
Pass -1 to timeout_us to block indefinitely until data is received (or
the connection is closed, or there is an error). Pass 0 to use the default
timeout from Gio.Socket.timeout, or pass a positive number to wait
for that many microseconds for data before returning G_IO_ERROR_TIMED_OUT.
the number of bytes you want to read from the socket
the timeout to wait for, in microseconds, or -1 to block indefinitely
Optionalcancellable: Gio.Cancellablea Gio.Cancellable, or NULL
a bytes buffer containing the received bytes, or NULL on error
Receive data (up to size bytes) from a socket.
If address is non-null then address will be set equal to the
source address of the received packet.
address is owned by the caller.
See g_socket_receive() for additional information.
Optionalcancellable: Gio.Cancellablea %GCancellable or null
Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error
Receive data from a socket. For receiving multiple messages, see
g_socket_receive_messages(); for easier use, see
g_socket_receive() and g_socket_receive_from().
If address is non-null then address will be set equal to the
source address of the received packet.
address is owned by the caller.
vector must point to an array of Gio.InputVector structs and
num_vectors must be the length of this array. These structs
describe the buffers that received data will be scattered into.
If num_vectors is -1, then vectors is assumed to be terminated
by a Gio.InputVector with a null buffer pointer.
As a special case, if num_vectors is 0 (in which case, vectors
may of course be null), then a single byte is received and
discarded. This is to facilitate the common practice of sending a
single '\0' byte for the purposes of transferring ancillary data.
messages, if non-null, will be set to point to a newly-allocated
array of Gio.SocketControlMessage instances or null if no such
messages was received. These correspond to the control messages
received from the kernel, one Gio.SocketControlMessage per message
from the kernel. This array is null-terminated and must be freed
by the caller using g_free() after calling g_object_unref() on each
element. If messages is null, any control messages received will
be discarded.
num_messages, if non-null, will be set to the number of control
messages received.
If both messages and num_messages are non-null, then
num_messages gives the number of Gio.SocketControlMessage instances
in messages (ie: not including the null terminator).
flags is an in/out parameter. The commonly available arguments
for this are available in the Gio.SocketMsgFlags enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too
(and g_socket_receive_message() may pass system-specific flags out).
Flags passed in to the parameter affect the receive operation; flags returned
out of it are relevant to the specific returned message.
As with g_socket_receive(), data may be discarded if socket is
Gio.SocketType.DATAGRAM or Gio.SocketType.SEQPACKET and you do not
provide enough buffer space to read a complete message. You can pass
Gio.SocketMsgFlags.PEEK in flags to peek at the current message without
removing it from the receive queue, but there is no portable way to find
out the length of the message other than by reading it into a
sufficiently-large buffer.
If the socket is in blocking mode the call will block until there is some data to receive, the connection is closed, or there is an error. If there is no data available and the socket is in non-blocking mode, a Gio.IOErrorEnum.WOULD_BLOCK error will be returned. To be notified when data is available, wait for the GObject.IOCondition.IN condition.
On error -1 is returned and error is set accordingly.
an array of Gio.InputVector structs
a pointer to an int containing Gio.SocketMsgFlags flags, which may additionally contain other platform specific flags
Optionalcancellable: Gio.Cancellablea %GCancellable or null
Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error
Receive multiple data messages from socket in one go. This is the most
complicated and fully-featured version of this call. For easier use, see
g_socket_receive(), g_socket_receive_from(), and g_socket_receive_message().
messages must point to an array of Gio.InputMessage structs and
num_messages must be the length of this array. Each Gio.InputMessage
contains a pointer to an array of Gio.InputVector structs describing the
buffers that the data received in each message will be written to. Using
multiple GInputVectors is more memory-efficient than manually copying data
out of a single buffer to multiple sources, and more system-call-efficient
than making multiple calls to g_socket_receive(), such as in scenarios where
a lot of data packets need to be received (e.g. high-bandwidth video
streaming over RTP/UDP).
flags modify how all messages are received. The commonly available
arguments for this are available in the Gio.SocketMsgFlags enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too. These
flags affect the overall receive operation. Flags affecting individual
messages are returned in Gio.InputMessage.flags.
The other members of Gio.InputMessage are treated as described in its documentation.
If Gio.Socket.blocking is true the call will block until num_messages have
been received, or the end of the stream is reached.
If Gio.Socket.blocking is false the call will return up to num_messages
without blocking, or Gio.IOErrorEnum.WOULD_BLOCK if no messages are queued in the
operating system to be received.
In blocking mode, if Gio.Socket.timeout is positive and is reached before any
messages are received, Gio.IOErrorEnum.TIMED_OUT is returned, otherwise up to
num_messages are returned. (Note: This is effectively the
behaviour of MSG_WAITFORONE with recvmmsg().)
To be notified when messages are available, wait for the
GObject.IOCondition.IN condition. Note though that you may still receive
Gio.IOErrorEnum.WOULD_BLOCK from g_socket_receive_messages() even if you were
previously notified of a GObject.IOCondition.IN condition.
If the remote peer closes the connection, any messages queued in the
operating system will be returned, and subsequent calls to
g_socket_receive_messages() will return 0 (with no error set).
On error -1 is returned and error is set accordingly. An error will only
be returned if zero messages could be received; otherwise the number of
messages successfully received before the error will be returned.
an array of Gio.InputMessage structs
an int containing Gio.SocketMsgFlags flags for the overall operation, which may additionally contain other platform specific flags
Optionalcancellable: Gio.Cancellablea %GCancellable or null
number of messages received, or -1 on error. Note that the number of messages received may be smaller than num_messages if in non-blocking mode, if the peer closed the connection, or if num_messages was larger than UIO_MAXIOV (1024), in which case the caller may re-try to receive the remaining messages.
This behaves exactly the same as g_socket_receive(), except that
the choice of blocking or non-blocking behavior is determined by
the blocking argument rather than by socket's properties.
whether to do blocking or non-blocking I/O
Optionalcancellable: Gio.Cancellablea %GCancellable or null
Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error
Increases the reference count of object.
Since GLib 2.56, if GLIB_VERSION_MAX_ALLOWED is 2.56 or greater, the type
of object will be propagated to the return type (using the GCC typeof()
extension), so any casting the caller needs to do on the return type must be
explicit.
the same object
Increase the reference count of object, and possibly remove the
[floating][floating-ref] reference, if object has a floating reference.
In other words, if the object is floating, then this call "assumes ownership" of the floating reference, converting it to a normal reference by clearing the floating flag while leaving the reference count unchanged. If the object is not floating, then this call adds a new normal reference increasing the reference count by one.
Since GLib 2.56, the type of object will be propagated to the return type
under the same conditions as for g_object_ref().
object
Releases all references to other objects. This can be used to break reference cycles.
This function should only be called from object system implementations.
Tries to send size bytes from buffer on the socket. This is
mainly used by connection-oriented sockets; it is identical to
g_socket_send_to() with address set to null.
If the socket is in blocking mode the call will block until there is
space for the data in the socket queue. If there is no space available
and the socket is in non-blocking mode a Gio.IOErrorEnum.WOULD_BLOCK error
will be returned. To be notified when space is available, wait for the
GObject.IOCondition.OUT condition. Note though that you may still receive
Gio.IOErrorEnum.WOULD_BLOCK from g_socket_send() even if you were previously
notified of a GObject.IOCondition.OUT condition. (On Windows in particular, this is
very common due to the way the underlying APIs work.)
On error -1 is returned and error is set accordingly.
the buffer containing the data to send.
Optionalcancellable: Gio.Cancellablea %GCancellable or null
Number of bytes written (which may be less than size), or -1 on error
Send data to address on socket. For sending multiple messages see
g_socket_send_messages(); for easier use, see
g_socket_send() and g_socket_send_to().
If address is null then the message is sent to the default receiver
(set by g_socket_connect()).
vectors must point to an array of Gio.OutputVector structs and
num_vectors must be the length of this array. (If num_vectors is -1,
then vectors is assumed to be terminated by a Gio.OutputVector with a
null buffer pointer.) The Gio.OutputVector structs describe the buffers
that the sent data will be gathered from. Using multiple
GOutputVectors is more memory-efficient than manually copying
data from multiple sources into a single buffer, and more
network-efficient than making multiple calls to g_socket_send().
messages, if non-null, is taken to point to an array of num_messages
Gio.SocketControlMessage instances. These correspond to the control
messages to be sent on the socket.
If num_messages is -1 then messages is treated as a null-terminated
array.
flags modify how the message is sent. The commonly available arguments
for this are available in the Gio.SocketMsgFlags enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too.
If the socket is in blocking mode the call will block until there is
space for the data in the socket queue. If there is no space available
and the socket is in non-blocking mode a Gio.IOErrorEnum.WOULD_BLOCK error
will be returned. To be notified when space is available, wait for the
GObject.IOCondition.OUT condition. Note though that you may still receive
Gio.IOErrorEnum.WOULD_BLOCK from g_socket_send() even if you were previously
notified of a GObject.IOCondition.OUT condition. (On Windows in particular, this is
very common due to the way the underlying APIs work.)
The sum of the sizes of each Gio.OutputVector in vectors must not be
greater than G_MAXSSIZE. If the message can be larger than this,
then it is mandatory to use the g_socket_send_message_with_timeout()
function.
On error -1 is returned and error is set accordingly.
a Gio.SocketAddress, or null
an array of Gio.OutputVector structs
a pointer to an array of GSocketControlMessages, or null.
an int containing Gio.SocketMsgFlags flags, which may additionally contain other platform specific flags
Optionalcancellable: Gio.Cancellablea %GCancellable or null
Number of bytes written (which may be less than size), or -1 on error
This behaves exactly the same as g_socket_send_message(), except that
the choice of timeout behavior is determined by the timeout_us argument
rather than by socket's properties.
On error Gio.PollableReturn.FAILED is returned and error is set accordingly, or
if the socket is currently not writable Gio.PollableReturn.WOULD_BLOCK is
returned. bytes_written will contain 0 in both cases.
a Gio.SocketAddress, or null
an array of Gio.OutputVector structs
a pointer to an array of GSocketControlMessages, or null.
an int containing Gio.SocketMsgFlags flags, which may additionally contain other platform specific flags
the maximum time (in microseconds) to wait, or -1
Optionalcancellable: Gio.Cancellablea %GCancellable or null
Gio.PollableReturn.OK if all data was successfully written, Gio.PollableReturn.WOULD_BLOCK if the socket is currently not writable, or Gio.PollableReturn.FAILED if an error happened and error is set.
Send multiple data messages from socket in one go. This is the most
complicated and fully-featured version of this call. For easier use, see
g_socket_send(), g_socket_send_to(), and g_socket_send_message().
messages must point to an array of Gio.OutputMessage structs and
num_messages must be the length of this array. Each Gio.OutputMessage
contains an address to send the data to, and a pointer to an array of
Gio.OutputVector structs to describe the buffers that the data to be sent
for each message will be gathered from. Using multiple GOutputVectors is
more memory-efficient than manually copying data from multiple sources
into a single buffer, and more network-efficient than making multiple
calls to g_socket_send(). Sending multiple messages in one go avoids the
overhead of making a lot of syscalls in scenarios where a lot of data
packets need to be sent (e.g. high-bandwidth video streaming over RTP/UDP),
or where the same data needs to be sent to multiple recipients.
flags modify how the message is sent. The commonly available arguments
for this are available in the Gio.SocketMsgFlags enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too.
If the socket is in blocking mode the call will block until there is
space for all the data in the socket queue. If there is no space available
and the socket is in non-blocking mode a Gio.IOErrorEnum.WOULD_BLOCK error
will be returned if no data was written at all, otherwise the number of
messages sent will be returned. To be notified when space is available,
wait for the GObject.IOCondition.OUT condition. Note though that you may still receive
Gio.IOErrorEnum.WOULD_BLOCK from g_socket_send() even if you were previously
notified of a GObject.IOCondition.OUT condition. (On Windows in particular, this is
very common due to the way the underlying APIs work.)
On error -1 is returned and error is set accordingly. An error will only
be returned if zero messages could be sent; otherwise the number of messages
successfully sent before the error will be returned.
an array of Gio.OutputMessage structs
an int containing Gio.SocketMsgFlags flags, which may additionally contain other platform specific flags
Optionalcancellable: Gio.Cancellablea %GCancellable or null
number of messages sent, or -1 on error. Note that the number of messages sent may be smaller than num_messages if the socket is non-blocking or if num_messages was larger than UIO_MAXIOV (1024), in which case the caller may re-try to send the remaining messages.
Tries to send size bytes from buffer to address. If address is
null then the message is sent to the default receiver (set by
g_socket_connect()).
See g_socket_send() for additional information.
a Gio.SocketAddress, or null
the buffer containing the data to send.
Optionalcancellable: Gio.Cancellablea %GCancellable or null
Number of bytes written (which may be less than size), or -1 on error
This behaves exactly the same as g_socket_send(), except that
the choice of blocking or non-blocking behavior is determined by
the blocking argument rather than by socket's properties.
the buffer containing the data to send.
whether to do blocking or non-blocking I/O
Optionalcancellable: Gio.Cancellablea %GCancellable or null
Number of bytes written (which may be less than size), or -1 on error
Sets multiple properties of an object at once. The properties argument should be a dictionary mapping property names to values.
Object containing the properties to set
Sets the blocking mode of the socket. In blocking mode all operations (which don’t take an explicit blocking parameter) block until they succeed or there is an error. In non-blocking mode all functions return results immediately or with a Gio.IOErrorEnum.WOULD_BLOCK error.
All sockets are created in blocking mode. However, note that the platform level socket is always non-blocking, and blocking mode is a GSocket level feature.
Whether to use blocking I/O or not.
Sets whether socket should allow sending to broadcast addresses.
This is false by default.
whether socket should allow sending to broadcast addresses
Each object carries around a table of associations from strings to pointers. This function lets you set an association.
If the object already had an association with that name, the old association will be destroyed.
Internally, the key is converted to a GLib.Quark using g_quark_from_string().
This means a copy of key is kept permanently (even after object has been
finalized) — so it is recommended to only use a small, bounded set of values
for key in your program, to avoid the GLib.Quark storage growing unbounded.
name of the key
Optionaldata: anydata to associate with that key
Sets or unsets the SO_KEEPALIVE flag on the underlying socket. When
this flag is set on a socket, the system will attempt to verify that the
remote socket endpoint is still present if a sufficiently long period of
time passes with no data being exchanged. If the system is unable to
verify the presence of the remote endpoint, it will automatically close
the connection.
This option is only functional on certain kinds of sockets. (Notably, Gio.SocketProtocol.TCP sockets.)
The exact time between pings is system- and protocol-dependent, but will normally be at least two hours. Most commonly, you would set this flag on a server socket if you want to allow clients to remain idle for long periods of time, but also want to ensure that connections are eventually garbage-collected if clients crash or become unreachable.
Value for the keepalive flag
Sets the maximum number of outstanding connections allowed when listening on this socket. If more clients than this are connecting to the socket and the application is not handling them on time then the new connections will be refused.
Note that this must be called before g_socket_listen() and has no
effect if called after that.
the maximum number of pending connections.
Sets whether outgoing multicast packets will be received by sockets
listening on that multicast address on the same host. This is true
by default.
whether socket should receive messages sent to its multicast groups from the local host
Sets the time-to-live for outgoing multicast datagrams on socket.
By default, this is 1, meaning that multicast packets will not leave
the local network.
the time-to-live value for all multicast datagrams on socket
Sets the value of an integer-valued option on socket, as with
setsockopt(). (If you need to set a non-integer-valued option,
you will need to call setsockopt() directly.)
The <gio/gnetworking.h>
header pulls in system headers that will define most of the
standard/portable socket options. For unusual socket protocols or
platform-dependent options, you may need to include additional
headers.
the "API level" of the option (eg, SOL_SOCKET)
the "name" of the option (eg, SO_BROADCAST)
the value to set the option to
success or failure. On failure, error will be set, and the system error value (errno or WSAGetLastError()) will still be set to the result of the setsockopt() call.
Sets a property on an object.
The name of the property to set
The value to set the property to
Sets the time in seconds after which I/O operations on socket will
time out if they have not yet completed.
On a blocking socket, this means that any blocking Gio.Socket
operation will time out after timeout seconds of inactivity,
returning Gio.IOErrorEnum.TIMED_OUT.
On a non-blocking socket, calls to g_socket_condition_wait() will
also fail with Gio.IOErrorEnum.TIMED_OUT after the given time. Sources
created with g_socket_create_source() will trigger after
timeout seconds of inactivity, with the requested condition
set, at which point calling g_socket_receive(), g_socket_send(),
g_socket_check_connect_result(), etc, will fail with
Gio.IOErrorEnum.TIMED_OUT.
If timeout is 0 (the default), operations will never time out
on their own.
Note that if an I/O operation is interrupted by a signal, this may cause the timeout to be reset.
the timeout for socket, in seconds, or 0 for none
Sets the time-to-live for outgoing unicast packets on socket.
By default the platform-specific default value is used.
the time-to-live value for all unicast packets on socket
Shut down part or all of a full-duplex connection.
If shutdown_read is true then the receiving side of the connection
is shut down, and further reading is disallowed.
If shutdown_write is true then the sending side of the connection
is shut down, and further writing is disallowed.
It is allowed for both shutdown_read and shutdown_write to be true.
One example where it is useful to shut down only one side of a connection is graceful disconnect for TCP connections where you close the sending side, then wait for the other side to close the connection, thus ensuring that the other side saw all sent data.
whether to shut down the read side
whether to shut down the write side
true on success, false on error
Checks if a socket is capable of speaking IPv4.
IPv4 sockets are capable of speaking IPv4. On some operating systems and under some combinations of circumstances IPv6 sockets are also capable of speaking IPv4. See RFC 3493 section 3.7 for more information.
No other types of sockets are currently considered as being capable of speaking IPv4.
true if this socket can be used with IPv4.
Remove a specified datum from the object's data associations, without invoking the association's destroy handler.
name of the key
the data if found, or null if no such data exists.
This function gets back user data pointers stored via
g_object_set_qdata() and removes the data from object
without invoking its destroy() function (if any was
set).
Usually, calling this function is only required to update
user data pointers with a destroy notifier, for example:
void
object_add_to_user_list (GObject *object,
const gchar *new_string)
{
// the quark, naming the object data
GQuark quark_string_list = g_quark_from_static_string ("my-string-list");
// retrieve the old string list
GList *list = g_object_steal_qdata (object, quark_string_list);
// prepend new string
list = g_list_prepend (list, g_strdup (new_string));
// this changed 'list', so we need to set it again
g_object_set_qdata_full (object, quark_string_list, list, free_string_list);
}
static void
free_string_list (gpointer data)
{
GList *node, *list = data;
for (node = list; node; node = node->next)
g_free (node->data);
g_list_free (list);
}
Using g_object_get_qdata() in the above example, instead of
g_object_steal_qdata() would have left the destroy function set,
and thus the partial string list would have been freed upon
g_object_set_qdata_full().
A GLib.Quark, naming the user data pointer
The user data pointer set, or null
Stops a signal's emission by the given signal name. This will prevent the default handler and any subsequent signal handlers from being invoked.
Name of the signal to stop emission of
Reverts the effect of a previous call to
g_object_freeze_notify(). The freeze count is decreased on object
and when it reaches zero, queued "notify" signals are emitted.
Duplicate notifications for each property are squashed so that at most one GObject.Object::notify signal is emitted for each property, in the reverse order in which they have been queued.
It is an error to call this function when the freeze count is zero.
Unblocks a handler so it will be called again during any signal emissions
Handler ID of the handler to be unblocked
Decreases the reference count of object. When its reference count
drops to 0, the object is finalized (i.e. its memory is freed).
If the pointer to the GObject.Object may be reused in future (for example, if it is
an instance variable of another object), it is recommended to clear the
pointer to null rather than retain a dangling pointer to a potentially
invalid GObject.Object instance. Use g_clear_object() for this.
Virtualvfunc_Checks on the readiness of datagram_based to perform operations. The
operations specified in condition are checked for and masked against the
currently-satisfied conditions on datagram_based. The result is returned.
GObject.IOCondition.IN will be set in the return value if data is available to read with
g_datagram_based_receive_messages(), or if the connection is closed remotely
(EOS); and if the datagram_based has not been closed locally using some
implementation-specific method (such as g_socket_close() or
g_socket_shutdown() with shutdown_read set, if it’s a Gio.Socket).
If the connection is shut down or closed (by calling g_socket_close() or
g_socket_shutdown() with shutdown_read set, if it’s a Gio.Socket, for
example), all calls to this function will return Gio.IOErrorEnum.CLOSED.
GObject.IOCondition.OUT will be set if it is expected that at least one byte can be sent
using g_datagram_based_send_messages() without blocking. It will not be set
if the datagram_based has been closed locally.
GObject.IOCondition.HUP will be set if the connection has been closed locally.
GObject.IOCondition.ERR will be set if there was an asynchronous error in transmitting data
previously enqueued using g_datagram_based_send_messages().
Note that on Windows, it is possible for an operation to return
Gio.IOErrorEnum.WOULD_BLOCK even immediately after
g_datagram_based_condition_check() has claimed that the Gio.DatagramBased is
ready for writing. Rather than calling g_datagram_based_condition_check() and
then writing to the Gio.DatagramBased if it succeeds, it is generally better to
simply try writing right away, and try again later if the initial attempt
returns Gio.IOErrorEnum.WOULD_BLOCK.
It is meaningless to specify GObject.IOCondition.ERR or GObject.IOCondition.HUP in condition; these
conditions will always be set in the output if they are true. Apart from
these flags, the output is guaranteed to be masked by condition.
This call never blocks.
a GObject.IOCondition mask to check
Virtualvfunc_Waits for up to timeout microseconds for condition to become true on
datagram_based. If the condition is met, true is returned.
If cancellable is cancelled before the condition is met, or if timeout is
reached before the condition is met, then false is returned and error is
set appropriately (Gio.IOErrorEnum.CANCELLED or Gio.IOErrorEnum.TIMED_OUT).
a GObject.IOCondition mask to wait for
the maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely
Optionalcancellable: Gio.CancellableVirtualvfunc_the constructed function is called by g_object_new() as the
final step of the object creation process. At the point of the call, all
construction properties have been set on the object. The purpose of this
call is to allow for object initialisation steps that can only be performed
after construction properties have been set. constructed implementors
should chain up to the constructed call of their parent class to allow it
to complete its initialisation.
Virtualvfunc_Creates a GLib.Source that can be attached to a GLib.MainContext to monitor for
the availability of the specified condition on the Gio.DatagramBased. The
GLib.Source keeps a reference to the datagram_based.
The callback on the source is of the Gio.DatagramBasedSourceFunc type.
It is meaningless to specify GObject.IOCondition.ERR or GObject.IOCondition.HUP in condition; these
conditions will always be reported in the callback if they are true.
If non-null, cancellable 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().
a GObject.IOCondition mask to monitor
Optionalcancellable: Gio.CancellableVirtualvfunc_Virtualvfunc_the dispose function is supposed to drop all references to other
objects, but keep the instance otherwise intact, so that client method
invocations still work. It may be run multiple times (due to reference
loops). Before returning, dispose should chain up to the dispose method
of the parent class.
Virtualvfunc_instance finalization function, should finish the finalization of
the instance begun in dispose and chain up to the finalize method of the
parent class.
Virtualvfunc_Virtualvfunc_Initializes the object implementing the interface.
This method is intended for language bindings. If writing in C,
g_initable_new() should typically be used instead.
The object must be initialized before any real use after initial
construction, either with this function or g_async_initable_init_async().
Implementations may also support cancellation. If cancellable is not null,
then initialization can be cancelled by triggering the cancellable object
from another thread. If the operation was cancelled, the error
Gio.IOErrorEnum.CANCELLED will be returned. If cancellable is not null and
the object doesn't support cancellable initialization the error
Gio.IOErrorEnum.NOT_SUPPORTED will be returned.
If the object is not initialized, or initialization returns with an
error, then all operations on the object except g_object_ref() and
g_object_unref() are considered to be invalid, and have undefined
behaviour. See the [description][iface@Gio.Initable#description] for more details.
Callers should not assume that a class which implements Gio.Initable can be
initialized multiple times, unless the class explicitly documents itself as
supporting this. Generally, a class’ implementation of init() can assume
(and assert) that it will only be called once. Previously, this documentation
recommended all Gio.Initable implementations should be idempotent; that
recommendation was relaxed in GLib 2.54.
If a class explicitly supports being initialized multiple times, it is recommended that the method is idempotent: multiple calls with the same arguments should return the same results. Only the first call initializes the object; further calls return the result of the first call.
One reason why a class might need to support idempotent initialization is if
it is designed to be used via the singleton pattern, with a
GObject.ObjectClass.constructor that sometimes returns an existing instance.
In this pattern, a caller would expect to be able to call g_initable_init()
on the result of g_object_new(), regardless of whether it is in fact a new
instance.
Optionalcancellable: Gio.Cancellableoptional Gio.Cancellable object, null to ignore.
Virtualvfunc_Emits a "notify" signal for the property property_name on object.
When possible, eg. when signaling a property change from within the class
that registered the property, you should use g_object_notify_by_pspec()
instead.
Note that emission of the notify signal may be blocked with
g_object_freeze_notify(). In this case, the signal emissions are queued
and will be emitted (in reverse order) when g_object_thaw_notify() is
called.
Virtualvfunc_Receive one or more data messages from datagram_based in one go.
messages must point to an array of Gio.InputMessage structs and
num_messages must be the length of this array. Each Gio.InputMessage
contains a pointer to an array of Gio.InputVector structs describing the
buffers that the data received in each message will be written to.
flags modify how all messages are received. The commonly available
arguments for this are available in the Gio.SocketMsgFlags enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too. These
flags affect the overall receive operation. Flags affecting individual
messages are returned in Gio.InputMessage.flags.
The other members of Gio.InputMessage are treated as described in its documentation.
If timeout is negative the call will block until num_messages have been
received, the connection is closed remotely (EOS), cancellable is cancelled,
or an error occurs.
If timeout is 0 the call will return up to num_messages without blocking,
or Gio.IOErrorEnum.WOULD_BLOCK if no messages are queued in the operating system
to be received.
If timeout is positive the call will block on the same conditions as if
timeout were negative. If the timeout is reached
before any messages are received, Gio.IOErrorEnum.TIMED_OUT is returned,
otherwise it will return the number of messages received before timing out.
(Note: This is effectively the behaviour of MSG_WAITFORONE with
recvmmsg().)
To be notified when messages are available, wait for the GObject.IOCondition.IN condition.
Note though that you may still receive Gio.IOErrorEnum.WOULD_BLOCK from
g_datagram_based_receive_messages() even if you were previously notified of a
GObject.IOCondition.IN condition.
If the remote peer closes the connection, any messages queued in the
underlying receive buffer will be returned, and subsequent calls to
g_datagram_based_receive_messages() will return 0 (with no error set).
If the connection is shut down or closed (by calling g_socket_close() or
g_socket_shutdown() with shutdown_read set, if it’s a Gio.Socket, for
example), all calls to this function will return Gio.IOErrorEnum.CLOSED.
On error -1 is returned and error is set accordingly. An error will only
be returned if zero messages could be received; otherwise the number of
messages successfully received before the error will be returned. If
cancellable is cancelled, Gio.IOErrorEnum.CANCELLED is returned as with any
other error.
an array of Gio.InputMessage structs
an int containing Gio.SocketMsgFlags flags for the overall operation
the maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely
Optionalcancellable: Gio.Cancellablea %GCancellable
Virtualvfunc_Send one or more data messages from datagram_based in one go.
messages must point to an array of Gio.OutputMessage structs and
num_messages must be the length of this array. Each Gio.OutputMessage
contains an address to send the data to, and a pointer to an array of
Gio.OutputVector structs to describe the buffers that the data to be sent
for each message will be gathered from.
flags modify how the message is sent. The commonly available arguments
for this are available in the Gio.SocketMsgFlags enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too.
The other members of Gio.OutputMessage are treated as described in its documentation.
If timeout is negative the call will block until num_messages have been
sent, cancellable is cancelled, or an error occurs.
If timeout is 0 the call will send up to num_messages without blocking,
or will return Gio.IOErrorEnum.WOULD_BLOCK if there is no space to send messages.
If timeout is positive the call will block on the same conditions as if
timeout were negative. If the timeout is reached before any messages are
sent, Gio.IOErrorEnum.TIMED_OUT is returned, otherwise it will return the number
of messages sent before timing out.
To be notified when messages can be sent, wait for the GObject.IOCondition.OUT condition.
Note though that you may still receive Gio.IOErrorEnum.WOULD_BLOCK from
g_datagram_based_send_messages() even if you were previously notified of a
GObject.IOCondition.OUT condition. (On Windows in particular, this is very common due to
the way the underlying APIs work.)
If the connection is shut down or closed (by calling g_socket_close() or
g_socket_shutdown() with shutdown_write set, if it’s a Gio.Socket, for
example), all calls to this function will return Gio.IOErrorEnum.CLOSED.
On error -1 is returned and error is set accordingly. An error will only
be returned if zero messages could be sent; otherwise the number of messages
successfully sent before the error will be returned. If cancellable is
cancelled, Gio.IOErrorEnum.CANCELLED is returned as with any other error.
an array of Gio.OutputMessage structs
an int containing Gio.SocketMsgFlags flags
the maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely
Optionalcancellable: Gio.Cancellablea %GCancellable
Virtualvfunc_the generic setter for all properties of this type. Should be
overridden for every type with properties. If implementations of
set_property don't emit property change notification explicitly, this will
be done implicitly by the type system. However, if the notify signal is
emitted explicitly, the type system will not emit it a second time.
This function essentially limits the life time of the closure to
the life time of the object. That is, when the object is finalized,
the closure is invalidated by calling g_closure_invalidate() on
it, in order to prevent invocations of the closure with a finalized
(nonexisting) object. Also, g_object_ref() and g_object_unref() are
added as marshal guards to the closure, to ensure that an extra
reference count is held on object during invocation of the
closure. Usually, this function will be called on closures that
use this object as closure data.
GObject.Closure to watch
StaticnewStaticnew_Static_Staticcompat_Optionaldata: anyStaticfind_Staticinstall_Staticinstall_the id for the new property
the GObject.ParamSpec for the new property
Staticinterface_Find the GObject.ParamSpec with the given name for an
interface. Generally, the interface vtable passed in as g_iface
will be the default vtable from g_type_default_interface_ref(), or,
if you know the interface has already been loaded,
g_type_default_interface_peek().
any interface vtable for the interface, or the default vtable for the interface
name of a property to look up.
Staticinterface_Add a property to an interface; this is only useful for interfaces
that are added to GObject-derived types. Adding a property to an
interface forces all objects classes with that interface to have a
compatible property. The compatible property could be a newly
created GObject.ParamSpec, but normally
g_object_class_override_property() will be used so that the object
class only needs to provide an implementation and inherits the
property description, default value, bounds, and so forth from the
interface property.
This function is meant to be called from the interface's default
vtable initialization function (the class_init member of
GObject.TypeInfo.) It must not be called after after class_init has
been called for any object types implementing this interface.
If pspec is a floating reference, it will be consumed.
any interface vtable for the interface, or the default vtable for the interface.
the GObject.ParamSpec for the new property
Staticinterface_Lists the properties of an interface.Generally, the interface
vtable passed in as g_iface will be the default vtable from
g_type_default_interface_ref(), or, if you know the interface has
already been loaded, g_type_default_interface_peek().
any interface vtable for the interface, or the default vtable for the interface
Staticlist_StaticnewvStaticoverride_the new property ID
the name of a property registered in a parent class or in an interface of this class.
A Gio.Socket is a low-level networking primitive. It is a more or less direct mapping of the BSD socket API in a portable GObject based API. It supports both the UNIX socket implementations and winsock2 on Windows.
Gio.Socket is the platform independent base upon which the higher level network primitives are based. Applications are not typically meant to use it directly, but rather through classes like Gio.SocketClient, Gio.SocketService and Gio.SocketConnection. However there may be cases where direct use of Gio.Socket is useful.
Gio.Socket implements the Gio.Initable interface, so if it is manually constructed by e.g. GObject.Object.new you must call Gio.Initable.init and check the results before using the object. This is done automatically in Gio.Socket.new and Gio.Socket.new_from_fd, so these functions can return
NULL.Sockets operate in two general modes, blocking or non-blocking. When in blocking mode all operations (which don’t take an explicit blocking parameter) block until the requested operation is finished or there is an error. In non-blocking mode all calls that would block return immediately with a
G_IO_ERROR_WOULD_BLOCKerror. To know when a call would successfully run you can call Gio.Socket.condition_check, or Gio.Socket.condition_wait. You can also use Gio.Socket.create_source and attach it to a GLib.MainContext to get callbacks when I/O is possible. Note that all sockets are always set to non blocking mode in the system, and blocking mode is emulated in Gio.Socket.When working in non-blocking mode applications should always be able to handle getting a
G_IO_ERROR_WOULD_BLOCKerror even when some other function said that I/O was possible. This can easily happen in case of a race condition in the application, but it can also happen for other reasons. For instance, on Windows a socket is always seen as writable until a write returnsG_IO_ERROR_WOULD_BLOCK.Gio.Sockets can be either connection oriented or datagram based. For connection oriented types you must first establish a connection by either connecting to an address or accepting a connection from another address. For connectionless socket types the target/source address is specified or received in each I/O operation.
All socket file descriptors are set to be close-on-exec.
Note that creating a Gio.Socket causes the signal
SIGPIPEto be ignored for the remainder of the program. If you are writing a command-line utility that uses Gio.Socket, you may need to take into account the fact that your program will not automatically be killed if it tries to write tostdoutafter it has been closed.Like most other APIs in GLib, Gio.Socket is not inherently thread safe. To use a Gio.Socket concurrently from multiple threads, you must implement your own locking.
Nagle’s algorithm
Since GLib 2.80, Gio.Socket will automatically set the
TCP_NODELAYoption on allG_SOCKET_TYPE_STREAMsockets. This disables Nagle’s algorithm as it typically does more harm than good on modern networks.If your application needs Nagle’s algorithm enabled, call Gio.Socket.set_option after constructing a Gio.Socket to enable it:
Since
2.22