Esempio n. 1
0
        public override void Write(byte[] buf, int off, int len)
        {
            CheckNotDisposed();
            ValidateBufferArgs(buf, off, len);
            if (!IsOpen)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen);
            }
            // Relative offset from "off" argument
            int offset = 0;

            if (outputBuffer.Length > 0)
            {
                int capa      = (int)(outputBuffer.Capacity - outputBuffer.Length);
                int writeSize = capa <= len ? capa : len;
                outputBuffer.Write(buf, off, writeSize);
                offset += writeSize;
                if (writeSize == capa)
                {
                    transport.Write(outputBuffer.GetBuffer(), 0, (int)outputBuffer.Length);
                    outputBuffer.SetLength(0);
                }
            }
            while (len - offset >= bufSize)
            {
                transport.Write(buf, off + offset, bufSize);
                offset += bufSize;
            }
            int remain = len - offset;

            if (remain > 0)
            {
                if (outputBuffer.Capacity < bufSize)
                {
                    outputBuffer.Capacity = bufSize;
                }
                outputBuffer.Write(buf, off + offset, remain);
            }
        }
        public override void Flush()
        {
            byte[] buf      = writeBuffer.GetBuffer();
            int    len      = (int)writeBuffer.Length;
            int    data_len = len - header_size;

            if (data_len < 0)
            {
                throw new System.InvalidOperationException();                  // logic error actually
            }
            InitWriteBuffer();

            // Inject message header into the reserved buffer space
            EncodeFrameSize(data_len, ref buf);

            // Send the entire message at once
            transport.Write(buf, 0, len);

            transport.Flush();
        }
Esempio n. 3
0
        private void InternalFlush()
        {
            CheckNotDisposed();
            if (!IsOpen)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen);
            }
            byte[] buf      = writeBuffer.GetBuffer();
            int    len      = (int)writeBuffer.Length;
            int    data_len = len - HeaderSize;

            if (data_len < 0)
            {
                throw new System.InvalidOperationException(); // logic error actually
            }
            // Inject message header into the reserved buffer space
            EncodeFrameSize(data_len, buf);

            // Send the entire message at once
            transport.Write(buf, 0, len);

            InitWriteBuffer();
        }
Esempio n. 4
0
        public override void Flush()
        {
            byte[] buf      = writeBuffer.GetBuffer();
            int    len      = (int)writeBuffer.Length;
            int    data_len = len - header_size;

            if (data_len < 0)
            {
                throw new System.InvalidOperationException();                  // logic error actually
            }
            InitWriteBuffer();

            // Inject message header into the reserved buffer space
            buf[0] = (byte)(0xff & (data_len >> 24));
            buf[1] = (byte)(0xff & (data_len >> 16));
            buf[2] = (byte)(0xff & (data_len >> 8));
            buf[3] = (byte)(0xff & (data_len));

            // Send the entire message at once
            transport.Write(buf, 0, len);

            transport.Flush();
        }