Exemplo n.º 1
0
        public void ProcessMessage()
        {
            m_AsyncEvent.Swap();

            AsyncEvent.RecvBufferData Data  = null;
            AsyncEvent.EventData      Event = null;

            while (m_AsyncEvent.PeekData(ref Data, ref Event))
            {
                if (Data != null)
                {
                    ReceiveData(Data.m_abyRecvBuffer, Data.m_iRecvSize);
                }
                else
                {
                    switch (Event.m_eEvent)
                    {
                    case AsyncEvent.e_SocketEvent.E_SOCKETEVENT_CONNECTED:
                        m_Callee.OnSockConnected(this, Event.m_strIP, Event.m_iPort);
                        break;

                    case AsyncEvent.e_SocketEvent.E_SOCKETEVENT_CONNECTFAILED:
                        m_Callee.OnSockConnectFail(this, Event.m_strIP, Event.m_iPort);
                        break;

                    case AsyncEvent.e_SocketEvent.E_SOCKETEVENT_CLOSED:
                        m_Callee.OnSockClose(this);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 开始接收数据
 /// </summary>
 /// <returns></returns>
 private bool StartReceive()
 {
     try
     {
         m_RecvBufferData = m_AsyncEvent.GetBufferData();
         m_Socket.BeginReceive(m_RecvBufferData.m_abyRecvBuffer, 0, AsyncEvent.ASYNCRECVBUF_LENGTH,
                               SocketFlags.None, new AsyncCallback(SockAsync.Receive), this);
     }
     catch (SocketException e)
     {
         SetSockError(e.ErrorCode, e.Message);
         SetSockState(SockState.Failed);
         return(false);
     }
     return(true);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 接受数据
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        private bool StopReceive(AsyncEvent.RecvBufferData recvBuff, int size)
        {
            recvBuff.m_iRecvSize = size;
            if (size > 0)
            {
                m_AsyncEvent.PushRecvData(recvBuff);
            }
            else
            {
                m_AsyncEvent.PushFreeData(recvBuff);
                ///接收不到数据了,可以断开完了,通知逻辑层
                if (size < 0)
                {
                    return(Close());
                }
            }

            return(StartReceive());
        }
Exemplo n.º 4
0
        public void ProcessMessage()
        {
            AsyncEvent.RecvBufferData Data  = null;
            AsyncEvent.EventData      Event = null;

            while (m_AsyncEvent.PeekData(ref Data, ref Event))
            {
                ///处理内部网络事件
                if (Event != null)
                {
                    switch (Event.m_eEvent)
                    {
                    case AsyncEvent.e_SocketEvent.E_SOCKETEVENT_CONNECTED:
                        m_Callee.OnSockConnected(this, Event.m_strIP, Event.m_iPort);
                        break;

                    case AsyncEvent.e_SocketEvent.E_SOCKETEVENT_CONNECTFAILED:
                        m_Callee.OnSockConnectFail(this, Event.m_strIP, Event.m_iPort);
                        break;

                    case AsyncEvent.e_SocketEvent.E_SOCKETEVENT_CLOSED:
                        m_Callee.OnSockClose(this);
                        break;

                    default:
                        break;
                    }
                    return;
                }

                ///处理数据接收
                if (Data != null)
                {
                    ReceiveData(Data.m_abyRecvBuffer, Data.m_iRecvSize);
                    m_AsyncEvent.PushFreeData(Data);
                    Data = null;
                }
            }
        }
Exemplo n.º 5
0
        public RecvContext GetRecvContext(UserSock uSock, AsyncEvent.RecvBufferData recvBuff)
        {
            RecvContext recvContext = null;

            lock (moRecvQueue)
            {
                if (m_queueRecvContext.Count > 0)
                {
                    recvContext = m_queueRecvContext.Dequeue();
                }
            }
            if (recvContext == null)
            {
                recvContext = new RecvContext(uSock, recvBuff);
            }
            else
            {
                recvContext.uUserSock = uSock;
                recvContext.RecvBuff  = recvBuff;
            }
            return(recvContext);
        }
Exemplo n.º 6
0
 public RecvContext(UserSock uSock, AsyncEvent.RecvBufferData RecvBuff)
 {
     this.uUserSock = uSock;
     this.RecvBuff  = RecvBuff;
 }