Esempio n. 1
0
        private NetworkIncommingMessage ReadMessage()
        {
            NetworkIncommingMessage msg = null;

            if (m_Messages.TryDequeue(out msg) == false)
            {
                return(null);
            }

            return(msg);
        }
Esempio n. 2
0
        public NetworkIncommingMessage WaitMessage(TimeSpan _Timeout)
        {
            NetworkIncommingMessage msg = ReadMessage();

            if (msg != null)
            {
                return(msg);
            }

            m_NewMessageEvent.WaitOne(_Timeout);
            return(ReadMessage());
        }
Esempio n. 3
0
 internal void _AddReceivedMessage(NetworkIncommingMessage _Message)
 {
     if (_Message.MessageType == NetworkMessageType.RawData)
     {
         m_Messages.Enqueue(_Message);
         m_NewMessageEvent.Set();
     }
     else
     {
         m_InternalMessages.Enqueue(_Message);
     }
 }
Esempio n. 4
0
        private void ReceiveCallback(IAsyncResult _AsyncResult)
        {
            try
            {
                int bytesRead = m_Socket.EndReceive(_AsyncResult);
                if (bytesRead > 0)
                {
                    int bytesHandled = 0;
                    while (bytesHandled != bytesRead)
                    {
                        if (m_CurrentIncommingMessage == null)
                        {
                            m_CurrentIncommingMessage = m_Server._CreateMessage(this);
                        }

                        int bytesAdded = m_CurrentIncommingMessage._AddData(m_RecvBuffer, bytesHandled, bytesRead - bytesHandled);
                        if (m_CurrentIncommingMessage.IsComplete() == true)
                        {
                            //Paketet är färdigt
                            m_Server._AddReceivedMessage(m_CurrentIncommingMessage);
                            m_CurrentIncommingMessage = null;
                        }
                        bytesHandled += bytesAdded;
                    }

                    //Fortsätt receive
                    m_Socket.BeginReceive(m_RecvBuffer, 0, m_RecvBufferSize, 0, new AsyncCallback(ReceiveCallback), this);
                }
                else
                {
                    m_CurrentReceiving = false;
                }
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                m_CurrentReceiving = false;
                if (ex.NativeErrorCode.Equals(10054)) //WSAECONNRESET "An existing connection was forcibly closed by the remote host"
                {
                    //Do nothing. just shutdown connection
                }
                else
                {
                    m_Exceptions.Enqueue(ex);
                }
            }
            catch (Exception ex)
            {
                m_Exceptions.Enqueue(ex);
                m_CurrentReceiving = false;
            }
        }
Esempio n. 5
0
        private void ReceiveCallback(IAsyncResult _AsyncResult)
        {
            try
            {
                int bytesRead = m_Socket.EndReceive(_AsyncResult);
                if (bytesRead > 0)
                {
                    int bytesHandled = 0;
                    while (bytesHandled != bytesRead)
                    {
                        if (m_CurrentIncommingMessage == null)
                        {
                            m_CurrentIncommingMessage = _CreateMessage();
                        }

                        int bytesAdded = m_CurrentIncommingMessage._AddData(m_RecvBuffer, bytesHandled, bytesRead - bytesHandled);
                        if (m_CurrentIncommingMessage.IsComplete() == true)
                        {
                            //Paketet är färdigt
                            _AddReceivedMessage(m_CurrentIncommingMessage);
                            m_CurrentIncommingMessage = null;
                        }
                        bytesHandled += bytesAdded;
                    }

                    //Fortsätt receive
                    m_Socket.BeginReceive(m_RecvBuffer, 0, m_RecvBufferSize, 0, new AsyncCallback(ReceiveCallback), this);
                }
                else
                {
                    m_CurrentReceiving = false;
                }
            }
            catch (Exception ex)
            {
                m_Connected.Reset();
                m_Exceptions.Enqueue(ex);
                if (m_Socket != null)
                {
                    Logger.LogException(ex);
                }
                m_CurrentReceiving = false;
            }
        }
Esempio n. 6
0
        internal NetworkIncommingMessage _CreateMessage(NetworkServerClient _Client)
        {
            NetworkIncommingMessage newMessage = new NetworkIncommingMessage(_Client.Socket);

            return(newMessage);
        }
Esempio n. 7
0
        private NetworkIncommingMessage _CreateMessage()
        {
            NetworkIncommingMessage newMessage = new NetworkIncommingMessage(m_Socket);

            return(newMessage);
        }