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

◆ end_send() [1/2]

size_t xtd::net::sockets::socket::end_send ( xtd::sptr< xtd::iasync_result async_result)

Ends a pending asynchronous send.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
Returns
If successful, the number of bytes sent to the xtd::net::sockets::socket::socket; otherwise, an invalid xtd::net::sockets::socket::socket error.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_send method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::end_send completes the asynchronous send operation started in xtd::net::sockets::socket::begin_send.
Before calling xtd::net::sockets::socket::begin_send, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread and is called by the system after xtd::net::sockets::socket::begin_send returns. The callback method must accept the xtd::iasync_result returned by the xtd::net::sockets::socket::begin_send method as a parameter.
Within the callback method, call the xtd::iasync_result::async_state method of the xtd::iasync_result parameter to obtain the sending xtd::net::sockets::socket::socket. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_send method to successfully complete the send operation and return the number of bytes sent.
If you are using a connectionless protocol, xtd::net::sockets::socket::end_send will block until the datagram is sent. If you are using a connection-oriented protocol, xtd::net::sockets::socket::end_send will block until some of the buffer was sent. If the return value from xtd::net::sockets::socket::end_send indicates that the buffer was not completely sent, call the xtd::net::sockets::socket::begin_send method again, modifying the buffer to hold the unsent data.
There is no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the xtd::net::sockets::socket::begin_send method means that the underlying system has had room to buffer your data for a network send.
Note
If you receive a xtd::net::sockets::socket_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.
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.