Beispiel #1
0
        private bool ProcessReadBytes(int bytesRead)
        {
            if (bytesRead <= 0)
            {
                Multiplexer.Trace("EOF", physicalName);
                RecordConnectionFailed(ConnectionFailureType.SocketClosed);
                return(false);
            }

            Interlocked.Exchange(ref lastReadTickCount, Environment.TickCount);

            // reset unanswered write timestamp
            VolatileWrapper.Write(ref firstUnansweredWriteTickCount, 0);

            ioBufferBytes += bytesRead;
            Multiplexer.Trace("More bytes available: " + bytesRead + " (" + ioBufferBytes + ")", physicalName);
            int offset = 0, count = ioBufferBytes;
            int handled = ProcessBuffer(ioBuffer, ref offset, ref count);

            Multiplexer.Trace("Processed: " + handled, physicalName);
            if (handled != 0)
            {
                // read stuff
                if (count != 0)
                {
                    Multiplexer.Trace("Copying remaining bytes: " + count, physicalName);
                    //  if anything was left over, we need to copy it to
                    // the start of the buffer so it can be used next time
                    Buffer.BlockCopy(ioBuffer, offset, ioBuffer, 0, count);
                }
                ioBufferBytes = count;
            }
            return(true);
        }
Beispiel #2
0
        public void BeginConnect(TextWriter log)
        {
            VolatileWrapper.Write(ref firstUnansweredWriteTickCount, 0);
            var endpoint = this.Bridge.ServerEndPoint.EndPoint;

            Multiplexer.Trace("Connecting...", physicalName);
            this.socketToken = Multiplexer.SocketManager.BeginConnect(endpoint, this, Multiplexer, log);
        }