예제 #1
0
파일: Transports.cs 프로젝트: zlorb/agnos
        //
        // write interface
        //
        public virtual void BeginWrite(int seq)
        {
            if (wlock.IsHeldByCurrentThread())
            {
                throw new IOException("BeginWrite is not reentrant");
            }
#if AGNOS_TRANSPORT_DEBUG
            System.Console.WriteLine("Transport.BeginWrite");
#endif
            wlock.Acquire();
            wseq             = seq;
            wbuffer.Position = 0;
            wbuffer.SetLength(0);
#if AGNOS_TRANSPORT_DEBUG
            System.Console.WriteLine(">> okay");
#endif
        }
예제 #2
0
파일: Transports.cs 프로젝트: zlorb/agnos
        //
        // read interface
        //
        public virtual int BeginRead()
        {
            if (rlock.IsHeldByCurrentThread())
            {
                throw new IOException("BeginRead is not reentrant");
            }

#if AGNOS_TRANSPORT_DEBUG
            System.Console.WriteLine("TransportBegin.BeginRead");
#endif
            rlock.Acquire();

            try {
                int seq                = readSInt32(inStream);
                int packetLength       = readSInt32(inStream);
                int uncompressedLength = readSInt32(inStream);

#if AGNOS_TRANSPORT_DEBUG
                System.Console.WriteLine(">> seq={0}, len={1}, uncomp={2}", seq, packetLength, uncompressedLength);
#endif
                if (readStream != null)
                {
                    throw new InvalidOperationException("readStream must be null at this point");
                }

                readStream = new BoundInputStream(inStream, packetLength, true, false);
                if (uncompressedLength > 0)
                {
                    readStream = new BoundInputStream(new DeflateStream(readStream, CompressionMode.Decompress, false), packetLength, false, true);
                }
                return(seq);
            } catch (Exception) {
                readStream = null;
                rlock.Release();
                throw;
            }
        }