Пример #1
0
        private RequestMsg deserialize(ref WireMsg wmsg)
        {
            var chunk = wmsg.Data;

            chunk.Position = sizeof(int);

            WireFrame  frame;
            RequestMsg result      = null;
            var        arrivalTime = Binding.StatTimeTicks;

            object received = null;

            try
            {
                try
                {
                    frame      = new WireFrame(chunk);
                    wmsg.Frame = frame;
                    received   = Binding.Serializer.Deserialize(chunk);
                }
                catch
                {
                    Instrumentation.ServerDeserializationErrorEvent.Happened(Node);
                    throw;
                }

                if (received == null)
                {
                    throw new ProtocolException(StringConsts.GLUE_UNEXPECTED_MSG_ERROR + "RequestMsg. Got <null>");
                }

                result = received as RequestMsg;

                if (result == null)
                {
                    throw new ProtocolException(StringConsts.GLUE_UNEXPECTED_MSG_ERROR + "RequestMsg");
                }

                stat_MsgReceived();
                stat_BytesReceived(chunk.Position);
            }
            catch
            {
                stat_Errors();
                throw;
            }
            finally
            {
                Binding.DumpMsg(true, received as Msg, chunk.GetBuffer(), 0, (int)chunk.Position);
            }


            result.__SetArrivalTimeStampTicks(arrivalTime);


            return(result);
        }
Пример #2
0
        private RequestMsg getRequest(TcpClient client, MemoryStream ms, SlimSerializer serializer)
        {
            var nets = client.GetStream();


            var msb        = ms.GetBuffer();
            var frameBegin = Consts.PACKET_DELIMITER_LENGTH;

            SyncBinding.socketRead(nets, msb, 0, frameBegin);

            var size = msb.ReadBEInt32();

            if (size < 1 || size > Binding.MaxMsgSize)
            {
                Instrumentation.ServerGotOverMaxMsgSizeErrorEvent.Happened(Node);
                // This is unrecoverable error - close the channel!
                throw new MessageSizeException(size, Binding.MaxMsgSize, "getRequest()", closeChannel: true);
            }


            ms.SetLength(Consts.PACKET_DELIMITER_LENGTH + size); //this may invalidate msb
            SyncBinding.socketRead(nets, ms.GetBuffer(), Consts.PACKET_DELIMITER_LENGTH, size);

            var arrivalTime = Binding.StatTimeTicks;

            ms.Position = Consts.PACKET_DELIMITER_LENGTH;
            RequestMsg result = null;


            WireFrame frame;

            try
            {
                try
                {
                    frame  = new WireFrame(ms);
                    result = DoDecodeRequest(frame, ms, serializer);
                }
                catch
                {
                    Instrumentation.ServerDeserializationErrorEvent.Happened(Node);
                    throw;
                }
            }
            finally
            {
                Binding.DumpMsg(true, result, ms.GetBuffer(), 0, size + Consts.PACKET_DELIMITER_LENGTH);
            }

            result.__SetArrivalTimeStampTicks(arrivalTime);


            stat_MsgReceived();
            stat_BytesReceived(size);
            return(result);
        }