Exemple #1
0
        private void Receive_Process(SocketAsyncEventArgs e)
        {
            int byteCount = e.BytesTransferred;

            if (e.SocketError != SocketError.Success || byteCount <= 0)
            {
                Dispose(false);
                return;
            }

            m_NextCheckActivity = DateTime.Now + TimeSpan.FromMinutes(1.2);

            byte[] buffer = m_RecvBuffer;

            if (m_Encoder != null)
            {
                m_Encoder.DecodeIncomingPacket(this, ref buffer, ref byteCount);
            }

            lock (m_Buffer)
                m_Buffer.Enqueue(buffer, 0, byteCount);

            m_MessagePump.OnReceive(this);

            lock ( m_AsyncLock ) {
                m_AsyncState &= ~AsyncState.Pending;
            }
        }
Exemple #2
0
        private void Receive_Start()
        {
            try {
                bool result = false;

                do
                {
                    lock ( m_AsyncLock ) {
                        if ((m_AsyncState & (AsyncState.Pending | AsyncState.Paused)) == 0)
                        {
                            m_AsyncState |= AsyncState.Pending;
                            result        = !m_Socket.ReceiveAsync(m_ReceiveEventArgs);

                            if (result)
                            {
                                Receive_Process(m_ReceiveEventArgs);
                            }
                        }
                    }
                } while (result);
            } catch (Exception ex) {
                TraceException(ex);
                Dispose(false);
            }
        }
Exemple #3
0
        private void Receive_Process(SocketAsyncEventArgs e)
        {
            int byteCount = e.BytesTransferred;

            if (e.SocketError != SocketError.Success || byteCount <= 0)
            {
                Dispose(false);
                return;
            }

            m_NextCheckActivity = DateTime.UtcNow + TimeSpan.FromMinutes(1.2);

            byte[] buffer = m_RecvBuffer;

            if (m_Encoder != null)
            {
                m_Encoder.DecodeIncomingPacket(this, ref buffer, ref byteCount);
            }

            //If we support encryption, then it is possible that the client was DISPOSED at this point.
            if (!m_Disposing)
            {
                lock (m_Buffer)
                    m_Buffer.Enqueue(buffer, 0, byteCount);

                m_MessagePump.OnReceive(this);

                lock (m_AsyncLock)
                    m_AsyncState &= ~AsyncState.Pending;
            }
        }
Exemple #4
0
        private void OnReceive(IAsyncResult asyncResult)
        {
            try
            {
                Socket s = (Socket)asyncResult.AsyncState;

                int byteCount = s.EndReceive(asyncResult);

                if (byteCount > 0)
                {
                    m_NextCheckActivity = Core.TickCount + 90000;

                    byte[] buffer;

                    lock (m_AsyncLock)
                        buffer = m_RecvBuffer;

                    if (PacketEncryptor != null)
                    {
                        PacketEncryptor.DecryptIncomingPacket(this, ref buffer, ref byteCount);
                    }

                    if (PacketEncoder != null)
                    {
                        PacketEncoder.DecodeIncomingPacket(this, ref buffer, ref byteCount);
                    }

                    lock (m_Buffer)
                        m_Buffer.Enqueue(buffer, 0, byteCount);

                    m_MessagePump.OnReceive(this);

                    lock (m_AsyncLock)
                    {
                        m_AsyncState &= ~AsyncState.Pending;

                        if ((m_AsyncState & AsyncState.Paused) == 0)
                        {
                            try
                            {
                                InternalBeginReceive();
                            }
                            catch (Exception ex)
                            {
                                TraceException(ex);
                                Dispose(false);
                            }
                        }
                    }
                }
                else
                {
                    Dispose(false);
                }
            }
            catch
            {
                Dispose(false);
            }
        }
Exemple #5
0
        private void OnReceive(IAsyncResult asyncResult)
        {
            Socket s = (Socket)asyncResult.AsyncState;

            try
            {
                int byteCount = s.EndReceive(asyncResult);

                if (byteCount > 0)
                {
                    m_NextCheckActivity = DateTime.Now + TimeSpan.FromMinutes(1.2);

                    byte[] buffer = m_RecvBuffer;

                    if (m_Encoder != null)
                    {
                        m_Encoder.DecodeIncomingPacket(this, ref buffer, ref byteCount);
                    }

                    lock (m_Buffer)
                        m_Buffer.Enqueue(buffer, 0, byteCount);

                    m_MessagePump.OnReceive(this);

                    lock (m_AsyncLock)
                    {
                        m_AsyncState &= ~AsyncState.Pending;

                        if ((m_AsyncState & AsyncState.Paused) == 0)
                        {
                            try
                            {
                                InternalBeginReceive();
                            }
                            catch (Exception ex)
                            {
                                TraceException(ex);
                                Dispose(false);
                            }
                        }
                    }
                }
                else
                {
                    Dispose(false);
                }
            }
            catch
            {
                Dispose(false);
            }
        }
Exemple #6
0
        public void ReceiveSimulatedPacket(PacketSimulation packetSimulation)
        {
            try
            {
                byte[] buffer = packetSimulation.ProcessedBytes;
                if (buffer.Length > 0)
                {
                    m_NextCheckActivity = DateTime.UtcNow + TimeSpan.FromMinutes(1.2);

                    if (!m_Disposing)
                    {
                        lock (m_Buffer)
                            m_Buffer.Enqueue(buffer, 0, buffer.Length);

                        m_MessagePump.OnReceive(this);

                        lock (m_AsyncLock)
                        {
                            m_AsyncState &= ~AsyncState.Pending;

                            if ((m_AsyncState & AsyncState.Paused) == 0)
                            {
                                try
                                {
                                    InternalBeginReceive();
                                }
                                catch (Exception ex)
                                {
                                    TraceException(ex);
                                    Dispose(false);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Dispose(false);
                }
            }
            catch
            {
                Dispose(false);
            }
        }
Exemple #7
0
        private void InternalBeginReceive()
        {
            m_AsyncState |= AsyncState.Pending;

            m_Socket.BeginReceive(m_RecvBuffer, 0, m_RecvBuffer.Length, SocketFlags.None, m_OnReceive, m_Socket);
        }
Exemple #8
0
		private void Receive_Process( SocketAsyncEventArgs e )
		{
			//Plume : Net 4
            /*int byteCount = e.BytesTransferred;

			if ( e.SocketError != SocketError.Success || byteCount <= 0 ) {
				Dispose( false );
				return;
			}

			m_NextCheckActivity = DateTime.Now + TimeSpan.FromMinutes( 1.2 );

			byte[] buffer = m_RecvBuffer;

			if ( m_Encoder != null )
				m_Encoder.DecodeIncomingPacket( this, ref buffer, ref byteCount );

			lock ( m_Buffer )
				m_Buffer.Enqueue( buffer, 0, byteCount );

			m_MessagePump.OnReceive( this );

			lock ( m_AsyncLock ) {
				m_AsyncState &= ~AsyncState.Pending;*/

            try
			{
				if (!m_Disposing)
				{
                    int byteCount = e.BytesTransferred;
                    if ( e.SocketError != SocketError.Success || byteCount <= 0 )
                    {
						Dispose( false );
						return;
					}
                    else
                    {
                        m_NextCheckActivity = DateTime.Now + TimeSpan.FromMinutes( 1.2 );
                        byte[] buffer = m_RecvBuffer;
                        if ( m_Encoder != null )
							m_Encoder.DecodeIncomingPacket( this, ref buffer, ref byteCount );
                if (m_Buffer != null)
                        {
                        	lock ( m_Buffer )
								m_Buffer.Enqueue( buffer, 0, byteCount );
                if (!m_Disposing)
                            {
								m_MessagePump.OnReceive( this );
                                lock ( m_AsyncLock ) 
                                {
									m_AsyncState &= ~AsyncState.Pending;
								}
                            }
                        }
                    }
				}
 			}
			catch (Exception ex)
			{
				Console.WriteLine("Exception on Netstate in Receive_Process");
				Console.WriteLine(ex.Message);
				Console.WriteLine(ex.StackTrace);
			}
			}