System.Net.Sockets.Socket.DoBeginReceive C# (CSharp) Method

DoBeginReceive() private method

private DoBeginReceive ( byte buffer, int offset, int size, SocketFlags socketFlags, OverlappedAsyncResult asyncResult ) : SocketError
buffer byte
offset int
size int
socketFlags SocketFlags
asyncResult OverlappedAsyncResult
return SocketError
        private SocketError DoBeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"size:{size}");

#if DEBUG
            IntPtr lastHandle = _handle.DangerousGetHandle();
#endif
            // Guarantee to call CheckAsyncCallOverlappedResult if we call SetUnamangedStructures with a cache in order to
            // avoid a Socket leak in case of error.
            SocketError errorCode = SocketError.SocketError;
            try
            {
                errorCode = SocketPal.ReceiveAsync(_handle, buffer, offset, size, socketFlags, asyncResult);

                if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Interop.Winsock.WSARecv returns:{errorCode} returning AsyncResult:{asyncResult}");
            }
            finally
            {
                errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
            }

            // Throw an appropriate SocketException if the native call fails synchronously.
            if (errorCode != SocketError.Success)
            {
                // TODO: https://github.com/dotnet/corefx/issues/5426
                // NetEventSource.Fail(this, "GetLastWin32Error() returned zero.");

                // Update the internal state of this socket according to the error before throwing.
                UpdateStatusAfterSocketError(errorCode);
                var socketException = new SocketException((int)errorCode);
                if (NetEventSource.IsEnabled) NetEventSource.Error(this, socketException);
                asyncResult.InvokeCallback(new SocketException((int)errorCode));
            }
#if DEBUG
            else
            {
                _lastReceiveHandle = lastHandle;
                _lastReceiveThread = Environment.CurrentManagedThreadId;
                _lastReceiveTick = Environment.TickCount;
            }
#endif

            return errorCode;
        }

Same methods

Socket::DoBeginReceive ( IList buffers, SocketFlags socketFlags, OverlappedAsyncResult asyncResult ) : SocketError