EndReceive() public method

Ends a pending asynchronous receive.
EndReceive is a blocking method that completes the asynchronous receive operation started in the BytesRoad.Net.Sockets.SocketEx.BeginReceive method. The EndReceive method will read as much data as is available up to the number of bytes you specified in the size parameter of the BytesRoad.Net.Sockets.SocketEx.BeginReceive method. If the remote host shuts down the BytesRoad.Net.Sockets.SocketEx connection with the BytesRoad.Net.Sockets.SocketEx.Shutdown method, and all available data has been received, the EndReceive method will complete immediately and return zero bytes.
/// The object was disposed. /// /// asyncResult is a null reference /// (Nothing in Visual Basic). /// /// asyncResult was not returned by a call to the /// /// method. /// /// EndReceive 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 EndReceive ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult /// An /// IAsyncResult /// that stores state information for this asynchronous operation. ///
return int
Ejemplo n.º 1
0
        void Read_End(IAsyncResult ar)
        {
            Read_SO stateObj = (Read_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                int read = _socket.EndReceive(ar);

                stateObj.Read += read;
                if ((read > 0) && (stateObj.Read < stateObj.Size))
                {
                    _socket.BeginReceive(
                        stateObj.Buffer,
                        stateObj.Offset + stateObj.Read,
                        stateObj.Size - stateObj.Read,
                        new AsyncCallback(Read_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();
             * }
             */
        }