Beispiel #1
0
        public LibuvConnection(UvStreamHandle socket,
                               ILibuvTrace log,
                               LibuvThread thread,
                               IPEndPoint remoteEndPoint,
                               IPEndPoint localEndPoint,
                               PipeOptions inputOptions  = null,
                               PipeOptions outputOptions = null,
                               long?maxReadBufferSize    = null,
                               long?maxWriteBufferSize   = null)
        {
            _socket = socket;

            LocalEndPoint  = localEndPoint;
            RemoteEndPoint = remoteEndPoint;

            ConnectionClosed = _connectionClosedTokenSource.Token;
            Log    = log;
            Thread = thread;

            maxReadBufferSize ??= 0;
            maxWriteBufferSize ??= 0;

            inputOptions ??= new PipeOptions(MemoryPool, PipeScheduler.ThreadPool, Thread, maxReadBufferSize.Value, maxReadBufferSize.Value / 2, useSynchronizationContext: false);
            outputOptions ??= new PipeOptions(MemoryPool, Thread, PipeScheduler.ThreadPool, maxWriteBufferSize.Value, maxWriteBufferSize.Value / 2, useSynchronizationContext: false);

            var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions);

            // Set the transport and connection id
            Transport   = pair.Transport;
            Application = pair.Application;
        }
Beispiel #2
0
 public LibuvOutputConsumer(
     PipeReader pipe,
     LibuvThread thread,
     UvStreamHandle socket,
     string connectionId,
     ILibuvTrace log)
 {
     _pipe         = pipe;
     _thread       = thread;
     _socket       = socket;
     _connectionId = connectionId;
     _log          = log;
 }
Beispiel #3
0
        public Task StartAsync(
            EndPoint endPoint,
            LibuvThread thread)
        {
            EndPoint = endPoint;
            Thread   = thread;

            return(Thread.PostAsync(listener =>
            {
                listener.ListenSocket = listener.CreateListenSocket();
                listener.ListenSocket.Listen(LibuvConstants.ListenBacklog, ConnectionCallback, listener);
            }, this));
        }
Beispiel #4
0
        public LibuvConnection(UvStreamHandle socket, ILibuvTrace log, LibuvThread thread, IPEndPoint remoteEndPoint, IPEndPoint localEndPoint)
        {
            _socket = socket;

            RemoteAddress = remoteEndPoint?.Address;
            RemotePort    = remoteEndPoint?.Port ?? 0;

            LocalAddress = localEndPoint?.Address;
            LocalPort    = localEndPoint?.Port ?? 0;

            ConnectionClosed = _connectionClosedTokenSource.Token;
            Log    = log;
            Thread = thread;
        }
Beispiel #5
0
        public LibuvOutputConsumer(
            IPipeReader pipe,
            LibuvThread thread,
            UvStreamHandle socket,
            string connectionId,
            ILibuvTrace log)
        {
            _pipe         = pipe;
            _thread       = thread;
            _socket       = socket;
            _connectionId = connectionId;
            _log          = log;

            _pipe.OnWriterCompleted(OnWriterCompleted, this);
        }
Beispiel #6
0
        public Task StartAsync(
            EndPoint endPoint,
            LibuvThread thread)
        {
            EndPoint = endPoint;
            Thread   = thread;

            return(Thread.PostAsync(listener =>
            {
                listener.ListenSocket = listener.CreateListenSocket();
#pragma warning disable CS0618
                listener.ListenSocket.Listen(TransportContext.Options.Backlog, ConnectionCallback, listener);
#pragma warning restore CS0618
            }, this));
        }
Beispiel #7
0
        public Task StartAsync(
            string pipeName,
            byte[] pipeMessage,
            EndPoint endPoint,
            LibuvThread thread)
        {
            _pipeName    = pipeName;
            _pipeMessage = pipeMessage;
            _buf         = thread.Loop.Libuv.buf_init(_ptr, 4);

            EndPoint     = endPoint;
            Thread       = thread;
            DispatchPipe = new UvPipeHandle(Log);

            var tcs = new TaskCompletionSource <int>(this, TaskCreationOptions.RunContinuationsAsynchronously);

            Thread.Post(StartCallback, tcs);
            return(tcs.Task);
        }
Beispiel #8
0
        public LibuvConnection(UvStreamHandle socket, ILibuvTrace log, LibuvThread thread)
        {
            _socket = socket;

            if (_socket is UvTcpHandle tcpHandle)
            {
                var remoteEndPoint = tcpHandle.GetPeerIPEndPoint();
                var localEndPoint  = tcpHandle.GetSockIPEndPoint();

                RemoteAddress = remoteEndPoint.Address;
                RemotePort    = remoteEndPoint.Port;

                LocalAddress = localEndPoint.Address;
                LocalPort    = localEndPoint.Port;
            }

            Log    = log;
            Thread = thread;
        }
Beispiel #9
0
        public async Task StartAsync(
            string pipeName,
            byte[] pipeMessage,
            IEndPointInformation endPointInformation,
            LibuvThread thread)
        {
            _pipeName    = pipeName;
            _pipeMessage = pipeMessage;

            if (_fileCompletionInfoPtr == IntPtr.Zero)
            {
                var fileCompletionInfo = new FILE_COMPLETION_INFORMATION {
                    Key = IntPtr.Zero, Port = IntPtr.Zero
                };
                _fileCompletionInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(fileCompletionInfo));
                Marshal.StructureToPtr(fileCompletionInfo, _fileCompletionInfoPtr, false);
            }

            await StartAsync(endPointInformation, thread).ConfigureAwait(false);

            await Thread.PostAsync(listener => listener.PostCallback(), this).ConfigureAwait(false);
        }
Beispiel #10
0
 public WriteReqPool(LibuvThread thread, ILibuvTrace log)
 {
     _thread = thread;
     _log    = log;
 }
Beispiel #11
0
 public WriteReqPool(LibuvThread thread, ILogger log)
 {
     _thread = thread;
     _log    = log;
 }