示例#1
0
        private static void WriteCallback(UvWriteReq2 req, int status, Exception ex, object state)
        {
            var connection = ((UvTcpConnection)state);

            connection._outgoing.Dequeue().Dispose();
            connection._connectionCompleted?.TrySetResult(null);
        }
示例#2
0
 private static void Unpin(UvWriteReq2 req)
 {
     foreach (var pin in req._pins)
     {
         pin.Free();
     }
     req._pins.Clear();
 }
示例#3
0
        private async Task ProcessWrites(UvTcpHandle handle)
        {
            var writeReq = new UvWriteReq2(_listener.Log);

            writeReq.Init(_listener.Loop);

            try
            {
                while (true)
                {
                    await _output;

                    var buffer = _output.BeginRead();

                    if (buffer.IsEmpty && _output.Completion.IsCompleted)
                    {
                        break;
                    }

                    // Up the reference count of the buffer so that we own the disposal of it
                    var cloned = buffer.Clone();
                    _outgoing.Enqueue(cloned);
                    writeReq.Write(handle, ref cloned, _writeCallback, this);

                    _output.EndRead(buffer);
                }
            }
            finally
            {
                _output.CompleteReading();

                // There's pending writes happening
                if (_outgoing.Count > 0)
                {
                    _connectionCompleted = new TaskCompletionSource <object>();

                    await _connectionCompleted.Task;
                }

                writeReq.Dispose();

                handle.Dispose();
            }
        }