System.Net.Sockets.SocketAsyncEventArgs.DoOperationAccept C# (CSharp) Method

DoOperationAccept() private method

private DoOperationAccept ( Socket socket, SafeCloseSocket handle, SafeCloseSocket acceptHandle, int &bytesTransferred ) : SocketError
socket Socket
handle SafeCloseSocket
acceptHandle SafeCloseSocket
bytesTransferred int
return SocketError
        internal unsafe SocketError DoOperationAccept(Socket socket, SafeCloseSocket handle, SafeCloseSocket acceptHandle, out int bytesTransferred)
        {
            PrepareIOCPOperation();

            SocketError socketError = SocketError.Success;

            if (!socket.AcceptEx(
                handle,
                acceptHandle,
                (_ptrSingleBuffer != IntPtr.Zero) ? _ptrSingleBuffer : _ptrAcceptBuffer,
                (_ptrSingleBuffer != IntPtr.Zero) ? Count - _acceptAddressBufferCount : 0,
                _acceptAddressBufferCount / 2,
                _acceptAddressBufferCount / 2,
                out bytesTransferred,
                _ptrNativeOverlapped))
            {
                socketError = SocketPal.GetLastSocketError();
            }

            return socketError;
        }

Usage Example

Example #1
0
        public bool AcceptAsync(SocketAsyncEventArgs e)
        {
            bool retval;

            if (s_loggingEnabled)
            {
                Logging.Enter(Logging.Sockets, this, "AcceptAsync", "");
            }

            if (CleanedUp)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            if (e._bufferList != null)
            {
                throw new ArgumentException(SR.net_multibuffernotsupported, "BufferList");
            }
            if (_rightEndPoint == null)
            {
                throw new InvalidOperationException(SR.net_sockets_mustbind);
            }
            if (!_isListening)
            {
                throw new InvalidOperationException(SR.net_sockets_mustlisten);
            }

            // Handle AcceptSocket property.
            SafeCloseSocket acceptHandle;
            e.AcceptSocket = GetOrCreateAcceptSocket(e.AcceptSocket, true, "AcceptSocket", out acceptHandle);

            // Prepare for the native call.
            e.StartOperationCommon(this);
            e.StartOperationAccept();

            // Local variables for sync completion.
            int bytesTransferred;
            SocketError socketError = SocketError.Success;

            // Make the native call.
            try
            {
                socketError = e.DoOperationAccept(this, _handle, acceptHandle, out bytesTransferred);
            }
            catch (Exception ex)
            {
                // Clear in-use flag on event args object.
                e.Complete();
                throw ex;
            }

            // Handle completion when completion port is not posted.
            if (socketError != SocketError.Success && socketError != SocketError.IOPending)
            {
                e.FinishOperationSyncFailure(socketError, bytesTransferred, SocketFlags.None);
                retval = false;
            }
            else
            {
                retval = true;
            }

            if (s_loggingEnabled)
            {
                Logging.Exit(Logging.Sockets, this, "AcceptAsync", retval);
            }
            return retval;
        }
SocketAsyncEventArgs