예제 #1
0
        public override AsyncSocket GetAcceptedSocket()
        {
            m_inSocketAsyncEventArgs.AcceptSocket = null;
            var temp = m_acceptedSocket;

            m_acceptedSocket = null;
            return(temp);
        }
예제 #2
0
        public override void Accept(AsyncSocket socket)
        {
            NativeSocket nativeSocket = (NativeSocket)socket;

            m_inSocketAsyncEventArgs.AcceptSocket = nativeSocket.m_socket;

            if (!m_socket.AcceptAsync(m_inSocketAsyncEventArgs))
            {
                CompletionStatus completionStatus = new CompletionStatus(this, m_state, OperationType.Accept, SocketError.Success, 0);

                m_completionPort.Queue(ref completionStatus);
            }
        }
예제 #3
0
        public override void Accept()
        {
            m_inSocketAsyncEventArgs.AcceptSocket = null;

            if (!m_socket.AcceptAsync(m_inSocketAsyncEventArgs))
            {
                if (m_inSocketAsyncEventArgs.SocketError == SocketError.Success)
                {
                    m_acceptedSocket = new NativeSocket(m_inSocketAsyncEventArgs.AcceptSocket);
                }

                CompletionStatus completionStatus = new CompletionStatus(this, m_state, OperationType.Accept, SocketError.Success, 0);

                m_completionPort.Queue(ref completionStatus);
            }
        }
예제 #4
0
        private void OnAsyncCompleted(object sender, SocketAsyncEventArgs e)
        {
            OperationType operationType;

            switch (e.LastOperation)
            {
            case SocketAsyncOperation.Accept:
                operationType = OperationType.Accept;
                if (e.SocketError == SocketError.Success)
                {
                    m_acceptedSocket = new NativeSocket(e.AcceptSocket);
                }
                break;

            case SocketAsyncOperation.Connect:
                operationType = OperationType.Connect;
                break;

            case SocketAsyncOperation.Receive:
                operationType = OperationType.Receive;
                break;

            case SocketAsyncOperation.Send:
                operationType = OperationType.Send;
                break;

            case SocketAsyncOperation.Disconnect:
                operationType = OperationType.Disconnect;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            CompletionStatus completionStatus = new CompletionStatus(this, m_state, operationType, e.SocketError,
                                                                     e.BytesTransferred);

            m_completionPort.Queue(ref completionStatus);
        }