xtd 0.2.0
Loading...
Searching...
No Matches

◆ begin_receive() [1/2]

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_receive ( std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::async_callback  callback,
const std::any &  state 
)

Begins to asynchronously receive data from a connected xtd::net::sockets::socket::socket.

Parameters
bufferAn array of type xtd::byte that is the storage location for the received data.
offsetThe zero-based position in the buffer parameter at which to store the received data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The asynchronous xtd::net::sockets::socket::begin_receive operation must be completed by calling the xtd::net::sockets::socket::end_receive method. Typically, the method is invoked by the callback delegate.
This method does not block until the operation is complete. To block until the operation is complete, use one of the xtd::net::sockets::socket::receive method overloads.
To cancel a pending xtd::net::sockets::socket::begin_receive, call the xtd::net::sockets::socket::socket::close method.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.
state is an instantiation of a user-defined class.