Example #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);
            }
        }
Example #2
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);
            }
        }