Exemplo n.º 1
0
        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            int           readlength = 0;
            ReceivePacket packet     = null;
            Object        obj        = null;//解析的对象

            try
            {
                packet = this._protocol.TryToTranslateMessage(connection, e.Buffer, this._maxMessageSize, out readlength);
                if (packet == null)
                {
                    return;
                }
                obj = this._decoder.decode(connection, packet.Buffer);
            }
            catch (Exception ex)
            {
                this.OnError(connection, ex);
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            if (packet != null)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    try { this._handler.OnReceived(connection, obj); }
                    catch (Exception ex) { Log.Trace.Error(ex.Message, ex); }
                });
            }
            e.SetReadlength(readlength);
        }
Exemplo n.º 2
0
        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            int       readlength;
            TResponse response = null;

            try
            {
                response = this._protocol.FindResponse(connection, e.Buffer, out readlength);
            }
            catch (Exception ex)
            {
                this.OnError(connection, ex);
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            if (response != null)
            {
                var request = this._requestCollection.Remove(response.SeqID);
                if (request == null)
                {
                    this.HandleUnknowResponse(connection, response);
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(_ => { try { request.SetResult(response); } catch { } });
                }
            }
            e.SetReadlength(readlength);
        }
Exemplo n.º 3
0
        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection,
                                                  MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            //process message
            int      readlength;
            TMessage message = null;

            try { message = this._protocol.Parse(connection, e.Buffer, out readlength); }
            catch (Exception ex)
            {
                base.OnConnectionError(connection, ex);
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            if (message != null)
            {
                Request <TMessage> request = null;
                if (this._receivingQueue.TryRemove(connection.ConnectionID, message.SeqID, out request))
                {
                    this.OnReceived(connection, request, message);
                }
                else
                {
                    this.OnReceivedUnknowMessage(connection, message);
                }
            }

            //continue receiveing..
            e.SetReadlength(readlength);
        }
Exemplo n.º 4
0
        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            int           readlength;
            Object        response = null;
            ReceivePacket packet   = null;

            try
            {
                packet = this._protocol.TryToTranslateMessage(connection, e.Buffer, DefaultConfigure.MaxMessageSize, out readlength);
            }
            catch (Exception ex)
            {
                this.OnError(connection, ex);
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            if (response != null)
            {
                this.OnResponse(connection, response);
            }
            e.SetReadlength(readlength);
        }
Exemplo n.º 5
0
        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            int          readLength;
            RedisMessage message = null;

            try { message = this._protocol.Parse(connection, e.Buffer, out readLength); }
            catch (Exception ex)
            {
                base.OnConnectionError(connection, ex);
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            this.OnResponse(message);
            e.SetReadlength(readLength);
        }
Exemplo n.º 6
0
        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection,
                                                  MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            int      readlength;
            TMessage message = null;

            try { message = this._protocol.Parse(connection, e.Buffer, this._maxMessageSize, out readlength); }
            catch (Exception ex)
            {
                this.OnConnectionError(connection, ex);
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            if (message != null)
            {
                this._socketService.OnReceived(connection, message);
            }
            e.SetReadlength(readlength);
        }