W Wrapl, The Programming Language

Libraries:Gtk:Gio:GSocket

Types

T

Inherits from:

A T 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.

T 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 Gtk.Gio.GSocketClient.T, Gtk.Gio.GSocketService.T and Gtk.Gio.GSocketConnection.T. However there may be cases where direct use of T is useful.

T implements the Gtk.Gio.GInitable.T interface, so if it is manually constructed by e.g. g_object_new() you must call Gtk.Gio.GInitable.Init and check the results before using the object. This is done automatically in g_socket_new() and g_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 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 Gtk.Gio.GIOErrorEnum.WouldBlock error. To know when a call would successfully run you can call ConditionCheck, or ConditionWait. You can also use CreateSource and attach it to a Gtk.Glib.GMainContext.T 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 GSocket.

When working in non-blocking mode applications should always be able to handle getting a Gtk.Gio.GIOErrorEnum.WouldBlock error 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 returns Gtk.Gio.GIOErrorEnum.WouldBlock.

Ts 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 T causes the signal SIGPIPE to be ignored for the remainder of the program. If you are writing a command-line utility that uses T, you may need to take into account the fact that your program will not automatically be killed if it tries to write to stdout after it has been closed.



Constants

Nil : T

Functions

GetType() : Gtk.GObject.Type.T



New(family @ Gtk.Gio.GSocketFamily.T, type @ Gtk.Gio.GSocketType.T, protocol @ Gtk.Gio.GSocketProtocol.T, error @ Std.Object.T) : Gtk.Gio.GSocket.T

Creates a new T with the defined family, type and protocol. If protocol is 0 (Gtk.Gio.GSocketProtocol.Default) the default protocol type for the family and type is used.

The protocol is a family and type specific int that specifies what kind of protocol to use. Gtk.Gio.GSocketProtocol.T lists several common ones. Many families only support one protocol, and use 0 for this, others support several and using 0 means to use the default protocol for the family and type.

The protocol id is passed directly to the operating system, so you can use protocols not listed in Gtk.Gio.GSocketProtocol.T if you know the protocol number used for it.

family the socket family to use, e.g. Gtk.Gio.GSocketFamily.Ipv4.
type the socket type to use.
protocol the id of the protocol to use, or 0 for default.
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns a T or NULL on error. Free the returned object with g_object_unref().


NewFromFd(fd @ Std.Integer.SmallT, error @ Std.Object.T) : Gtk.Gio.GSocket.T

Creates a new T from a native file descriptor or winsock SOCKET handle.

This reads all the settings from the file descriptor so that all properties should work. Note that the file descriptor will be set to non-blocking mode, independent on the blocking mode of the T.

fd a native socket file descriptor.
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns a T or NULL on error. Free the returned object with g_object_unref().


Methods

:Accept(self @ T, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Gtk.Gio.GSocket.T

Accept incoming connections on a connection-based socket. This removes the first outstanding connection request from the listening socket and creates a T object for it.

The socket must be bound to a local address with Bind and must be listening for incoming connections (Listen).

If there are no outstanding connections then the operation will block or return Gtk.Gio.GIOErrorEnum.WouldBlock if non-blocking I/O is enabled. To be notified of an incoming connection, wait for the Gtk.Glib.GIOCondition.In condition.

socket a T.
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns a new T, or NULL on error. Free the returned object with g_object_unref(). [transfer full]


:Bind(self @ T, address @ Gtk.Gio.GSocketAddress.T, allow_reuse @ Std.Symbol.T, error @ Std.Object.T) : Std.Symbol.T

When a socket is created it is attached to an address family, but it doesn't have an address in this family. 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 Listen and 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.

allow_reuse should be TRUE for server sockets (sockets that you will eventually call Accept on), and FALSE for client sockets. (Specifically, if it is TRUE, then Bind will set the SO_REUSEADDR flag on the socket, allowing it to bind address even if that address was previously used by another socket that has not yet been fully cleaned-up by the kernel. Failing to set this flag on a server socket may cause the bind call to return Gtk.Gio.GIOErrorEnum.AddressInUse if the server program is stopped and then immediately restarted.)

socket a T.
address a Gtk.Gio.GSocketAddress.T specifying the local address.
allow_reuse whether to allow reusing this address
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns TRUE on success, FALSE on error.


:CheckConnectResult(self @ T, error @ Std.Object.T) : Std.Symbol.T

Checks and resets the pending connect error for the socket. This is used to check for errors when Connect is used in non-blocking mode.

socket a T
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns TRUE if no error, FALSE otherwise, setting error to the error


:Close(self @ T, error @ Std.Object.T) : Std.Symbol.T

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 Gtk.Gio.GIOErrorEnum.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 Gtk.Glib.GIOCondition.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 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 Close. (This is what Gtk.Gio.GTcpConnection.T does if you call Gtk.Gio.GTcpConnection.SetGracefulDisconnect. But of course, this only works if the client will close its connection after the server does.)

socket a T
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns TRUE on success, FALSE on error


:ConditionCheck(self @ T, condition @ Gtk.Glib.GIOCondition.T) : Gtk.Glib.GIOCondition.T

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 Gtk.Gio.GIOErrorEnum.WouldBlock even immediately after ConditionCheck has claimed that the socket is ready for writing. Rather than calling ConditionCheck 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 Gtk.Gio.GIOErrorEnum.WouldBlock.

It is meaningless to specify Gtk.Glib.GIOCondition.Err or Gtk.Glib.GIOCondition.Hup in condition; these conditions will always be set in the output if they are true.

This call never blocks.

socket a T
condition a Gtk.Glib.GIOCondition.T mask to check
Returns the GIOCondition mask of the current state


:ConditionWait(self @ T, condition @ Gtk.Glib.GIOCondition.T, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Symbol.T

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 (Gtk.Gio.GIOErrorEnum.Cancelled or Gtk.Gio.GIOErrorEnum.TimedOut).

socket a T
condition a Gtk.Glib.GIOCondition.T mask to wait for
cancellable a Gtk.Gio.GCancellable.T, or NULL. [allow-none]
error a Gtk.Glib.GError.T pointer, or NULL
Returns TRUE if the condition was met, FALSE otherwise


:Connect(self @ T, address @ Gtk.Gio.GSocketAddress.T, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Symbol.T

Connect 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 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 Gtk.Gio.GIOErrorEnum.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 CheckConnectResult.

socket a T.
address a Gtk.Gio.GSocketAddress.T specifying the remote address.
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns TRUE if connected, FALSE on error.


:CreateSource(self @ T, condition @ Gtk.Glib.GIOCondition.T, cancellable @ Gtk.Gio.GCancellable.T) : Gtk.Glib.GSource.T

Creates a Gtk.Glib.GSource.T that can be attached to a Gtk.Glib.GMainContext.T to monitor for the availibility of the specified condition on the socket.

The callback on the source is of the Gtk.Gio.GSocketSourceFunc type.

It is meaningless to specify Gtk.Glib.GIOCondition.Err or Gtk.Glib.GIOCondition.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 Gtk.Gio.GCancellable.IsCancelled.

If socket has a timeout set, and it is reached before condition occurs, the source will then trigger anyway, reporting Gtk.Glib.GIOCondition.In or Gtk.Glib.GIOCondition.Out depending on condition. However, socket will have been marked as having had a timeout, and so the next T I/O method you call will then fail with a Gtk.Gio.GIOErrorEnum.TimedOut.

socket a T
condition a Gtk.Glib.GIOCondition.T mask to monitor
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
Returns a newly allocated Gtk.Glib.GSource.T, free with Gtk.Glib.GMain.SourceUnref. [transfer full]


:GetBlocking(self @ T) : Std.Symbol.T

Gets the blocking mode of the socket. For details on blocking I/O, see SetBlocking.

socket a T.
Returns TRUE if blocking I/O is used, FALSE otherwise.


:GetCredentials(self @ T, error @ Std.Object.T) : Gtk.Gio.GCredentials.T

Returns the credentials of the foreign process connected to this socket, if any (e.g. it is only supported for Gtk.Gio.GSocketFamily.Unix sockets).

If this operation isn't supported on the OS, the method fails with the Gtk.Gio.GIOErrorEnum.NotSupported error. On Linux this is implemented by reading the SO_PEERCRED option on the underlying socket.

Other ways to obtain credentials from a foreign peer includes the Gtk.Gio.GUnixCredentialsMessage.T type and g_unix_connection_send_credentials() / g_unix_connection_receive_credentials() functions.

socket a T.
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns NULL if error is set, otherwise a Gtk.Gio.GCredentials.T object that must be freed with g_object_unref(). [transfer full]


:GetFamily(self @ T) : Gtk.Gio.GSocketFamily.T

Gets the socket family of the socket.

socket a T.
Returns a Gtk.Gio.GSocketFamily.T


:GetFd(self @ T) : Std.Integer.SmallT

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.

socket a T.
Returns the file descriptor of the socket.


:GetKeepalive(self @ T) : Std.Symbol.T

Gets the keepalive mode of the socket. For details on this, see SetKeepalive.

socket a T.
Returns TRUE if keepalive is active, FALSE otherwise.


:GetListenBacklog(self @ T) : Std.Integer.SmallT

Gets the listen backlog setting of the socket. For details on this, see SetListenBacklog.

socket a T.
Returns the maximum number of pending connections.


:GetLocalAddress(self @ T, error @ Std.Object.T) : Gtk.Gio.GSocketAddress.T

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.

socket a T.
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns a Gtk.Gio.GSocketAddress.T or NULL on error. Free the returned object with g_object_unref(). [transfer full]


:GetProtocol(self @ T) : Gtk.Gio.GSocketProtocol.T

Gets the socket protocol id the socket was created with. In case the protocol is unknown, -1 is returned.

socket a T.
Returns a protocol id, or -1 if unknown


:GetRemoteAddress(self @ T, error @ Std.Object.T) : Gtk.Gio.GSocketAddress.T

Try to get the remove address of a connected socket. This is only useful for connection oriented sockets that have been connected.

socket a T.
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns a Gtk.Gio.GSocketAddress.T or NULL on error. Free the returned object with g_object_unref(). [transfer full]


:GetSocketType(self @ T) : Gtk.Gio.GSocketType.T

Gets the socket type of the socket.

socket a T.
Returns a Gtk.Gio.GSocketType.T


:GetTimeout(self @ T) : Std.Integer.SmallT

Gets the timeout setting of the socket. For details on this, see SetTimeout.

socket a T.
Returns the timeout in seconds


:IsClosed(self @ T) : Std.Symbol.T

Checks whether a socket is closed.

socket a T
Returns TRUE if socket is closed, FALSE otherwise


:IsConnected(self @ T) : Std.Symbol.T

Check whether the socket is connected. This is only useful for connection-oriented sockets.

socket a T.
Returns TRUE if socket is connected, FALSE otherwise.


:Listen(self @ T, error @ Std.Object.T) : Std.Symbol.T

Marks the socket as a server socket, i.e. a socket that is used to accept incoming requests using Accept.

Before calling this the socket must be bound to a local address using Bind.

To set the maximum amount of outstanding clients, use SetListenBacklog.

socket a T.
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns TRUE on success, FALSE on error.


:Priv(self @ T) : Std.Object.T

:Receive(self @ T, buffer @ Std.String.T, size @ Std.Integer.SmallT, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Integer.SmallT

Receive data (up to size bytes) from a socket. This is mainly used by connection-oriented sockets; it is identical to ReceiveFrom with address set to NULL.

For Gtk.Gio.GSocketType.Datagram and Gtk.Gio.GSocketType.Seqpacket sockets, 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 Gtk.Gio.GSocketType.Stream sockets, 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 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 Gtk.Gio.GIOErrorEnum.WouldBlock error will be returned. To be notified when data is available, wait for the Gtk.Glib.GIOCondition.In condition.

On error -1 is returned and error is set accordingly.

socket a T
buffer a buffer to read data into (which should be at least size bytes long).
size the number of bytes you want to read from the socket
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error


:ReceiveFrom(self @ T, address @ Std.Object.T, buffer @ Std.String.T, size @ Std.Integer.SmallT, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Integer.SmallT

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 Receive for additional information.

socket a T
address a pointer to a Gtk.Gio.GSocketAddress.T pointer, or NULL
buffer a buffer to read data into (which should be at least size bytes long).
size the number of bytes you want to read from the socket
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error


:ReceiveMessage(self @ T, address @ Std.Object.T, vectors @ Gtk.Gio.GInputVector.T, num_vectors @ Std.Integer.SmallT, messages @ Std.Object.T, num_messages @ Std.Object.T, flags @ Std.Object.T, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Integer.SmallT

Receive data from a socket. This is the most complicated and fully-featured version of this call. For easier use, see Receive and ReceiveFrom.

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 Gtk.Gio.GInputVector.T 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 Gtk.Gio.GInputVector.T 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 Gtk.Gio.GSocketControlMessage.T instances or NULL if no such messages was received. These correspond to the control messages received from the kernel, one Gtk.Gio.GSocketControlMessage.T 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 Gtk.Gio.GSocketControlMessage.T 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 Gtk.Gio.GSocketMsgFlags.T 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 ReceiveMessage may pass system-specific flags out).

As with Receive, data may be discarded if socket is Gtk.Gio.GSocketType.Datagram or Gtk.Gio.GSocketType.Seqpacket and you do not provide enough buffer space to read a complete message. You can pass Gtk.Gio.GSocketMsgFlags.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 Gtk.Gio.GIOErrorEnum.WouldBlock error will be returned. To be notified when data is available, wait for the Gtk.Glib.GIOCondition.In condition.

On error -1 is returned and error is set accordingly.

socket a T
address a pointer to a Gtk.Gio.GSocketAddress.T pointer, or NULL
vectors an array of Gtk.Gio.GInputVector.T structs. [array length=num_vectors]
num_vectors the number of elements in vectors, or -1
messages a pointer which may be filled with an array of GSocketControlMessages, or NULL. [array length=num_messages][allow-none]
num_messages a pointer which will be filled with the number of elements in messages, or NULL
flags a pointer to an int containing Gtk.Gio.GSocketMsgFlags.T flags
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error a Gtk.Glib.GError.T pointer, or NULL
Returns Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error


:ReceiveWithBlocking(self @ T, buffer @ Std.String.T, size @ Std.Integer.SmallT, blocking @ Std.Symbol.T, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Integer.SmallT

This behaves exactly the same as Receive, except that the choice of blocking or non-blocking behavior is determined by the blocking argument rather than by socket's properties.

socket a T
buffer a buffer to read data into (which should be at least size bytes long).
size the number of bytes you want to read from the socket
blocking whether to do blocking or non-blocking I/O
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error


:Send(self @ T, buffer @ Std.String.T, size @ Std.Integer.SmallT, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Integer.SmallT

Tries to send size bytes from buffer on the socket. This is mainly used by connection-oriented sockets; it is identical to SendTo 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 Gtk.Gio.GIOErrorEnum.WouldBlock error will be returned. To be notified when space is available, wait for the Gtk.Glib.GIOCondition.Out condition. Note though that you may still receive Gtk.Gio.GIOErrorEnum.WouldBlock from Send even if you were previously notified of a Gtk.Glib.GIOCondition.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.

socket a T
buffer the buffer containing the data to send. [array length=size]
size the number of bytes to send
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns Number of bytes written (which may be less than size), or -1 on error


:SendMessage(self @ T, address @ Gtk.Gio.GSocketAddress.T, vectors @ Gtk.Gio.GOutputVector.T, num_vectors @ Std.Integer.SmallT, messages @ Std.Object.T, num_messages @ Std.Integer.SmallT, flags @ Std.Integer.SmallT, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Integer.SmallT

Send data to address on socket. This is the most complicated and fully-featured version of this call. For easier use, see Send and SendTo.

If address is NULL then the message is sent to the default receiver (set by Connect).

vectors must point to an array of Gtk.Gio.GOutputVector.T 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 Gtk.Gio.GOutputVector.T with a NULL buffer pointer.) The Gtk.Gio.GOutputVector.T structs describe the buffers that the sent data will be gathered from. Using multiple Gtk.Gio.GOutputVector.Ts is more memory-efficient than manually copying data from multiple sources into a single buffer, and more network-efficient than making multiple calls to Send.

messages, if non-NULL, is taken to point to an array of num_messages Gtk.Gio.GSocketControlMessage.T 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 Gtk.Gio.GSocketMsgFlags.T 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 Gtk.Gio.GIOErrorEnum.WouldBlock error will be returned. To be notified when space is available, wait for the Gtk.Glib.GIOCondition.Out condition. Note though that you may still receive Gtk.Gio.GIOErrorEnum.WouldBlock from Send even if you were previously notified of a Gtk.Glib.GIOCondition.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.

socket a T
address a Gtk.Gio.GSocketAddress.T, or NULL
vectors an array of Gtk.Gio.GOutputVector.T structs. [array length=num_vectors]
num_vectors the number of elements in vectors, or -1
messages a pointer to an array of GSocketControlMessages, or NULL. [array length=num_messages][allow-none]
num_messages number of elements in messages, or -1.
flags an int containing Gtk.Gio.GSocketMsgFlags.T flags
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns Number of bytes written (which may be less than size), or -1 on error


:SendTo(self @ T, address @ Gtk.Gio.GSocketAddress.T, buffer @ Std.String.T, size @ Std.Integer.SmallT, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Integer.SmallT

Tries to send size bytes from buffer to address. If address is NULL then the message is sent to the default receiver (set by Connect).

See Send for additional information.

socket a T
address a Gtk.Gio.GSocketAddress.T, or NULL
buffer the buffer containing the data to send. [array length=size]
size the number of bytes to send
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns Number of bytes written (which may be less than size), or -1 on error


:SendWithBlocking(self @ T, buffer @ Std.String.T, size @ Std.Integer.SmallT, blocking @ Std.Symbol.T, cancellable @ Gtk.Gio.GCancellable.T, error @ Std.Object.T) : Std.Integer.SmallT

This behaves exactly the same as Send, except that the choice of blocking or non-blocking behavior is determined by the blocking argument rather than by socket's properties.

socket a T
buffer the buffer containing the data to send. [array length=size]
size the number of bytes to send
blocking whether to do blocking or non-blocking I/O
cancellable a Gtk.Gio.GCancellable.T or NULL. [allow-none]
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns Number of bytes written (which may be less than size), or -1 on error


:SetBlocking(self @ T, blocking @ Std.Symbol.T) : Std.Object.T

Sets the blocking mode of the socket. In blocking mode all operations block until they succeed or there is an error. In non-blocking mode all functions return results immediately or with a Gtk.Gio.GIOErrorEnum.WouldBlock 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.

socket a T.
blocking Whether to use blocking I/O or not.


:SetKeepalive(self @ T, keepalive @ Std.Symbol.T) : Std.Object.T

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, Gtk.Gio.GSocketProtocol.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.

socket a T.
keepalive Value for the keepalive flag


:SetListenBacklog(self @ T, backlog @ Std.Integer.SmallT) : Std.Object.T

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 Listen and has no effect if called after that.

socket a T.
backlog the maximum number of pending connections.


:SetTimeout(self @ T, timeout @ Std.Integer.SmallT) : Std.Object.T

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 T operation will time out after timeout seconds of inactivity, returning Gtk.Gio.GIOErrorEnum.TimedOut.

On a non-blocking socket, calls to ConditionWait will also fail with Gtk.Gio.GIOErrorEnum.TimedOut after the given time. Sources created with CreateSource will trigger after timeout seconds of inactivity, with the requested condition set, at which point calling Receive, Send, CheckConnectResult, etc, will fail with Gtk.Gio.GIOErrorEnum.TimedOut.

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.

socket a T.
timeout the timeout for socket, in seconds, or 0 for none


:Shutdown(self @ T, shutdown_read @ Std.Symbol.T, shutdown_write @ Std.Symbol.T, error @ Std.Object.T) : Std.Symbol.T

Shut down part 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 this is used 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.

socket a T
shutdown_read whether to shut down the read side
shutdown_write whether to shut down the write side
error Gtk.Glib.GError.T for error reporting, or NULL to ignore.
Returns TRUE on success, FALSE on error


:SpeaksIpv4(self @ T) : Std.Symbol.T

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.

socket a T
Returns TRUE if this socket can be used with IPv4.


:setPriv(self @ T, value @ Std.Object.T) : Std.Object.T