BytesRoad.Net.Sockets.SocketEx.EndSend C# (CSharp) Method

EndSend() public method

Ends a pending asynchronous send.
EndSend is a blocking method that completes the asynchronous send operation started in the BytesRoad.Net.Sockets.SocketEx.BeginSend method.

EndSend will block until the requested number of bytes are sent. 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 EndSend method means that the underlying system has had room to buffer your data for a network send.

/// The object was disposed. /// /// asyncResult is a null reference /// (Nothing in Visual Basic). /// /// asyncResult was not returned by a call to the /// /// method. /// /// EndSend was previously called for the /// asynchronous receiving. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public EndSend ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult /// An /// IAsyncResult /// that stores state information for this asynchronous operation. ///
return int
        public int EndSend(IAsyncResult asyncResult)
        {
            return (int)EndTimeoutOp(new Send_Op(_baseSocket), asyncResult);
        }

Usage Example

Example #1
0
        void Send_End(IAsyncResult ar)
        {
            Write_SO stateObj = (Write_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                int sent = _socket.EndSend(ar);

                stateObj.Sent += sent;
                if (stateObj.Sent < stateObj.Size)
                {
                    _socket.BeginSend(
                        stateObj.Buffer,
                        stateObj.Offset + stateObj.Sent,
                        stateObj.Size - stateObj.Sent,
                        new AsyncCallback(Send_End),
                        stateObj);
                }
                else
                {
                    stateObj.SetCompleted();
                }
            }
            catch (Exception e)
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else
                {
                    stateObj.Exception = e;
                }
                stateObj.SetCompleted();
            }

            /*
             * catch
             * {
             *  if(_disposed)
             *      stateObj.Exception = GetDisposedException();
             *  else
             *      stateObj.Exception = new SocketException(SockErrors.WSAECONNRESET);
             *  stateObj.SetCompleted();
             * }
             */
        }