示例#1
0
        private void OnRead(UvStreamHandle handle, int status)
        {
            if (status == 0)
            {
                // A zero status does not indicate an error or connection end. It indicates
                // there is no data to be read right now.
                // See the note at http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb.
                // We need to clean up whatever was allocated by OnAlloc.
                return;
            }

            var normalRead = status > 0;
            var normalDone = status == EOF;
            var errorDone  = !(normalDone || normalRead);
            var readCount  = normalRead ? status : 0;

            if (!normalRead)
            {
                handle.ReadStop();
            }

            _inputBuffer.CommitBytes(readCount);

            IOException error = null;

            if (errorDone)
            {
                Exception uvError;
                handle.Libuv.Check(status, out uvError);
                error = new IOException(uvError.Message, uvError);

                _input.CompleteWriting(error);
            }
            else if (readCount == 0)
            {
                _input.CompleteWriting();
            }
            else
            {
                var task = _input.WriteAsync(_inputBuffer);

                if (task.IsFaulted)
                {
                    // TODO: Stop producing forever
                }
                else if (!task.IsCompleted)
                {
                    // TODO: Pause reading until the task completes
                }
            }
        }
示例#2
0
        private void OnRead(UvStreamHandle handle, int status)
        {
            if (status == 0)
            {
                // A zero status does not indicate an error or connection end. It indicates
                // there is no data to be read right now.
                // See the note at http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb.
                // We need to clean up whatever was allocated by OnAlloc.
                return;
            }

            var normalRead = status > 0;
            var normalDone = status == EOF;
            var errorDone  = !(normalDone || normalRead);
            var readCount  = normalRead ? status : 0;

            if (normalRead)
            {
                // Log.ConnectionRead(ConnectionId, readCount);
            }
            else
            {
                handle.ReadStop();
            }

            _buffer.UpdateWritten(readCount);

            IOException error = null;

            if (errorDone)
            {
                Exception uvError;
                handle.Libuv.Check(status, out uvError);
                error = new IOException(uvError.Message, uvError);

                _input.CompleteWriting(error);
            }
            else if (readCount == 0)
            {
                _input.CompleteWriting();
            }
            else
            {
                _input.WriteAsync(_buffer);
            }
        }
示例#3
0
        public void Complete(int status, long requestCorrelation, uint bytesTransferred)
        {
            // Receives
            if (requestCorrelation >= 0)
            {
                if (bytesTransferred > 0)
                {
                    _buffer.UpdateWritten((int)bytesTransferred);
                    _input.WriteAsync(_buffer);

                    ProcessReceives();
                }
                else
                {
                    _input.CompleteWriting();
                }
            }
            else
            {
                SendCompleting(requestCorrelation);
            }
        }