Exemple #1
0
        void OnConnected(ConnectRequest request)
        {
            try
            {
                if (request.Error != null)
                {
                    Logger.Warn($"{nameof(WorkerEventLoop)} failed to connect to dispatcher", request.Error);
                    this.connectCompletion.TryUnwrap(request.Error);
                }
                else
                {
                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info($"{nameof(WorkerEventLoop)} ({this.LoopThreadId}) dispatcher pipe {this.pipeName} connected.");
                    }

                    this.pipe.ReadStart(this.OnRead);
                    this.connectCompletion.TryComplete();
                }
            }
            finally
            {
                request.Dispose();
            }
        }
Exemple #2
0
        void OnConnected(ConnectRequest request)
        {
            try
            {
                if (request.Error is object)
                {
                    if (Logger.WarnEnabled)
                    {
                        Logger.FailedToConnectToDispatcher(request);
                    }
                    _ = _connectCompletion.TrySetException(request.Error);
                }
                else
                {
                    if (Logger.InfoEnabled)
                    {
                        Logger.DispatcherPipeConnected(LoopThreadId, _pipeName);
                    }

                    _pipe.ReadStart(OnRead);
                    _ = _connectCompletion.TryComplete();
                }
            }
            finally
            {
                request.Dispose();
            }
        }
Exemple #3
0
            void FinishConnect(ConnectRequest request)
            {
                NativeChannel        ch      = this.Channel;
                TaskCompletionSource promise = ch.connectPromise;

                try
                {
                    if (request.Error != null)
                    {
                        promise.TrySetException(request.Error);
                        this.CloseIfClosed();
                    }
                    else
                    {
                        ch.DoFinishConnect();
                        promise.TryComplete();
                    }
                }
                catch (Exception exception)
                {
                    promise.TrySetException(exception);
                    this.CloseIfClosed();
                }
                finally
                {
                    request.Dispose();
                    ch.connectPromise = null;
                }
            }
            // Connect request callback from libuv thread
            void INativeUnsafe.FinishConnect(ConnectRequest request)
            {
                var ch = (NativeChannel)this.channel;

                ch.connectCancellationTask?.Cancel();

                TaskCompletionSource promise = ch.connectPromise;
                bool success = false;

                try
                {
                    if (promise != null) // Not cancelled from timed out
                    {
                        OperationException error = request.Error;
                        if (error != null)
                        {
                            if (error.ErrorCode == ErrorCode.ETIMEDOUT)
                            {
                                // Connection timed out should use the standard ConnectTimeoutException
                                promise.TrySetException(new ConnectTimeoutException(error.ToString()));
                            }
                            else
                            {
                                promise.TrySetException(new ChannelException(error));
                            }
                        }
                        else
                        {
                            bool wasActive = ch.Active;
                            ch.DoFinishConnect();
                            success = promise.TryComplete();

                            // Regardless if the connection attempt was cancelled, channelActive()
                            // event should be triggered, because what happened is what happened.
                            if (!wasActive && ch.Active)
                            {
                                ch.Pipeline.FireChannelActive();
                            }
                        }
                    }
                }
                finally
                {
                    request.Dispose();
                    ch.connectPromise = null;
                    if (!success)
                    {
                        this.CloseSafe();
                    }
                }
            }
Exemple #5
0
            // Connect request callback from libuv thread
            void INativeUnsafe.FinishConnect(ConnectRequest request)
            {
                var ch = _channel;

                _ = (ch._connectCancellationTask?.Cancel());

                var  promise = ch._connectPromise;
                bool success = false;

                try
                {
                    if (promise is object) // Not cancelled from timed out
                    {
                        OperationException error = request.Error;
                        if (error is object)
                        {
                            if (error.ErrorCode == ErrorCode.ETIMEDOUT)
                            {
                                // Connection timed out should use the standard ConnectTimeoutException
                                _ = promise.TrySetException(ThrowHelper.GetConnectTimeoutException(error));
                            }
                            else
                            {
                                _ = promise.TrySetException(ThrowHelper.GetChannelException(error));
                            }
                        }
                        else
                        {
                            bool wasActive = ch.Active;
                            ch.DoFinishConnect();
                            success = promise.TryComplete();

                            // Regardless if the connection attempt was cancelled, channelActive()
                            // event should be triggered, because what happened is what happened.
                            if (!wasActive && ch.Active)
                            {
                                _ = ch.Pipeline.FireChannelActive();
                            }
                        }
                    }
                }
                finally
                {
                    request.Dispose();
                    ch._connectPromise = null;
                    if (!success)
                    {
                        CloseSafe();
                    }
                }
            }