Ejemplo n.º 1
0
        private EMessage readSingleMessage()
        {
            var msgSize = 0;

            if (UseV100Plus)
            {
                msgSize = eClientSocket.ReadInt();

                if (msgSize > Constants.MaxMsgSize)
                {
                    throw new EClientException(EClientErrors.BAD_LENGTH);
                }

                var buf = new List<byte>();
                var offset = 0;

                while (offset < msgSize)
                {
                    var readBuf = eClientSocket.ReadByteArray(msgSize - offset);

                    buf.AddRange(readBuf);

                    offset += readBuf.Length;
                }

                return new EMessage(buf.ToArray());
            }

            if (inBuf.Count == 0)
                AppendInBuf();

            while (true)
                try
                {
                    msgSize = new EDecoder(this.eClientSocket.ServerVersion, defaultWrapper).ParseAndProcessMsg(inBuf.ToArray());
                    break;
                }
                catch (EndOfStreamException)
                {
                    if (inBuf.Count >= inBuf.Capacity * 3/4)
                        inBuf.Capacity *= 2;

                    AppendInBuf();
                }
            
            var msgBuf = new byte[msgSize];

            inBuf.CopyTo(0, msgBuf, 0, msgSize);
            inBuf.RemoveRange(0, msgSize);
          
            if (inBuf.Count < defaultInBufSize && inBuf.Capacity > defaultInBufSize)
                inBuf.Capacity = defaultInBufSize;

            return new EMessage(msgBuf);
        }
Ejemplo n.º 2
0
 public EReader(EClientSocket clientSocket, EReaderSignal signal)
 {
     eClientSocket = clientSocket;
     eReaderSignal = signal;
     processMsgsDecoder = new EDecoder(eClientSocket.ServerVersion, eClientSocket.Wrapper, eClientSocket);
 }