예제 #1
0
        private void OnAsyncSendTo(SocketAsyncEventArgs args)
        {
            Debug.Assert(m_SendEventArgs == args);
            Debug.Assert(args.UserToken is UdpSession);

            if (SocketError.Success == args.SocketError)
            {
                UdpSession sess = args.UserToken as UdpSession;

                //if (null != sess && null != sess.m_Socket)
                //{
                //DebugUdpSendLog(sess.m_Socket, args);

                if (sess.ProcessSend(args))
                {
                    if (!sess.m_Socket.SendToAsync(args))
                    {
                        sess.OnAsyncSendTo(args);
                    }
                }
                else if (!sess.m_Socket.ReceiveFromAsync(m_RecvEventArgs))
                {
                    sess.OnAsyncReceiveFrom(m_RecvEventArgs);
                }
                //}
            }
            else
            {
                ProcessError(args);
            }
        }
예제 #2
0
        public void Initialize()
        {
            Session sess = null;

            for (int i = 0; i < USER_TCP_SESSION_MAX_NUM; ++i)
            {
                sess = new TcpSession(i + 1);
                m_FreeTcpUserSessionQueue.Enqueue(sess);
            }

            for (int i = 0; i < USER_UDP_SESSION_MAX_NUM; ++i)
            {
                sess = new UdpSession(i + 1);
                m_FreeUdpUserSessionQueue.Enqueue(sess);
            }

            ValidInitializeOnce();
        }
예제 #3
0
        private void OnAsyncReceiveFrom(SocketAsyncEventArgs args)
        {
            Debug.Assert(m_RecvEventArgs == args);
            Debug.Assert(args.UserToken is UdpSession);

            if (args.BytesTransferred > 0)
            {
                if (SocketError.Success == args.SocketError)
                {
                    UdpSession sess = args.UserToken as UdpSession;

                    //DebugUdpRecvLog(sess.m_Socket, args);

                    sess.ProcessReceive(args);

                    if (sess.ProcessSend(m_SendEventArgs))
                    {
                        if (!sess.m_Socket.SendToAsync(m_SendEventArgs))
                        {
                            sess.OnAsyncSendTo(m_SendEventArgs);
                        }
                    }
                    else if (!sess.m_Socket.ReceiveFromAsync(args))
                    {
                        sess.OnAsyncReceiveFrom(args);
                    }
                }
                else
                {
                    ProcessError(args);
                }
            }
            else
            {
                CloseSession(args);
            }
        }