Gio.Socket.prototype.receive
function receive(buffer: ByteArray, cancellable: Gio.Cancellable): Number(gssize) {
// Gjs wrapper for g_socket_receive()
}
Receive data (up to size bytes) from a socket. This is mainly used by connection-oriented sockets; it is identical to Gio.Socket.prototype.receive_from with @address set to null.
For Gio.SocketType.datagram and Gio.SocketType.seqpacket sockets, Gio.Socket.prototype.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, Gio.Socket.prototype.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 Gio.Socket.prototype.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 GLib.IOCondition.in condition.
On error -1 is returned and @error is set accordingly.
Since 2.22
- buffer
a buffer to read data into (which should be at least size bytes long).
- cancellable
a %GCancellable or null
- Returns
Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error