Socket.receive

ptrdiff_t receive(ref ubyte[] buffer, gio.cancellable.Cancellable cancellable = null)

Receive data (up to size bytes) from a socket. This is mainly used by connection-oriented sockets; it is identical to [gio.socket.Socket.receiveFrom] with address set to null.

For [gio.types.SocketType.Datagram] and [gio.types.SocketType.Seqpacket] sockets, [gio.socket.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.types.SocketType.Stream] sockets, [gio.socket.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 [gio.socket.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.types.IOErrorEnum.WouldBlock] error will be returned. To be notified when data is available, wait for the [glib.types.IOCondition.In] condition.

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

Parameters

buffera buffer to read data into (which should be at least size bytes long).
cancellablea [gio.cancellable.Cancellable] or null

Returns

Number of bytes read, or 0 if the connection was closed by

the peer, or -1 on error

Throws

[ErrorWrap]