Receive data (up to buffer.length
bytes) from a socket.
This is mainly used by connection-oriented sockets; it is identical to
receive_from with address
set to null.
For g_socket_type_datagram and g_socket_type_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 buffer.length
bytes will be discarded, without any
explicit indication that this has occurred.
For g_socket_type_stream sockets, receive can return any number
of bytes, up to buffer.length
. If more than buffer.length
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 g_io_error_would_block error will be returned. To be notified when data is available, wait for the g_io_in condition.
On error -1 is returned and throws is set accordingly.
this |
a Socket |
buffer |
a buffer to read data into (which should be at least |
cancellable |
a gcancellable or null |
size |
the number of bytes you want to read from the socket |
Number of bytes read, or 0 if the connection was closed by the peer, or -1 on error |