示例#1
0
        private void putResponse(TcpClient client, MemoryStream ms, ResponseMsg response, SlimSerializer serializer)
        {
            var frameBegin = Consts.PACKET_DELIMITER_LENGTH;

            ms.Position = frameBegin;

            var frame = new WireFrame(Binding.FrameFormat, true, response.RequestID);

            // Write the frame
            var frameSize = frame.Serialize(ms);

            // Write the message
            DoEncodeResponse(ms, response, serializer);

            var size = (int)ms.Position - frameBegin;

            var buffer = ms.GetBuffer(); //no stream expansion beyond this point

            buffer.WriteBEInt32(0, size);

            Binding.DumpMsg(true, response, buffer, 0, (int)ms.Position);

            if (size > Binding.MaxMsgSize)
            {
                Instrumentation.ServerSerializedOverMaxMsgSizeErrorEvent.Happened(Node);
                throw new MessageSizeException(size, Binding.MaxMsgSize, "putResponse()", serializer.BatchTypesAdded);
            }

            client.GetStream().Write(buffer, 0, (int)ms.Position);

            stat_MsgSent();
            stat_BytesSent(size);
        }
示例#2
0
        private int serialize(MemChunk chunk, WireFrame frame, Msg msg)
        {
            chunk.Position = sizeof(int);
            frame.Serialize(chunk);
            Binding.Serializer.Serialize(chunk, msg);
            var size = (int)chunk.Position; //includes 4 byte len prefix

            var buff = chunk.GetBuffer();   //no stream expansion beyond this point

            buff.WriteBEInt32(0, size);
            return(size);
        }
示例#3
0
        private void putRequest(RequestMsg request)
        {
            var ms        = m_MemStream;
            var dataBegin = Consts.PACKET_DELIMITER_LENGTH;

            ms.Position = dataBegin;

            var frame = new WireFrame(Binding.FrameFormat, request.OneWay, request.RequestID);

            // Write the frame
            var frameSize = frame.Serialize(ms);

            // Write the message
            DoEncodeRequest(ms, request);

            var size = (int)ms.Position - dataBegin;

            var buffer = ms.GetBuffer();   //no stream expansion beyond this point

            buffer.WriteBEInt32(0, size);

            Binding.DumpMsg(false, request, buffer, 0, (int)ms.Position);

            if (size > Binding.MaxMsgSize)
            {
                Instrumentation.ClientSerializedOverMaxMsgSizeErrorEvent.Happened(App.Instrumentation, Node);
                //do not tear the socket, however we may have added extra types to Serializer typereg that server never received
                //so in that case we do close the channel
                throw new MessageSizeException(size, Binding.MaxMsgSize, "putRequest(" + request.RequestID + ")", m_Serializer.BatchTypesAdded);
            }

            m_Client.GetStream().Write(buffer, 0, (int)ms.Position);

            stat_MsgSent();
            stat_BytesSent(size);
        }