예제 #1
0
        private static void UvConnectCb(IntPtr ptr, int status)
        {
            var req = FromIntPtr <UvConnectRequest>(ptr);

            var callback = req._callback;

            req._callback = null;

            var state = req._state;

            req._state = null;

            UvException error = null;

            if (status < 0)
            {
                req.Libuv.Check(status, out error);
            }

            try
            {
                callback(req, status, error, state);
            }
            catch (Exception ex)
            {
                req._log.LogError(0, ex, "UvConnectRequest");
                throw;
            }
        }
예제 #2
0
        private void OnListenPipe(UvStreamHandle pipe, int status, UvException error)
        {
            if (status < 0)
            {
                return;
            }

            var dispatchPipe = new UvPipeHandle(Log);

            // Add to the list of created pipes for disposal tracking
            _createdPipes.Add(dispatchPipe);

            try
            {
                dispatchPipe.Init(Thread.Loop, Thread.QueueCloseHandle, true);
                pipe.Accept(dispatchPipe);

                // Ensure client sends "Kestrel" before adding pipe to _dispatchPipes.
                var readContext = new PipeReadContext(this);
                dispatchPipe.ReadStart(
                    (handle, status2, state) => ((PipeReadContext)state).AllocCallback(handle, status2),
                    (handle, status2, state) => ((PipeReadContext)state).ReadCallback(handle, status2),
                    readContext);
            }
            catch (UvException ex)
            {
                dispatchPipe.Dispose();
                Log.LogError(0, ex, "ListenerPrimary.OnListenPipe");
            }
        }
예제 #3
0
        private void ConnectionCallback(UvStreamHandle listenSocket, int status, UvException error, object state)
        {
            var listener = (UvListener)state;

            if (error != null)
            {
                listener.Log.LogError(0, error, "Listener.ConnectionCallback");
            }
            else if (!listener._closed)
            {
                UvStreamHandle acceptSocket = null;
                try
                {
                    acceptSocket = CreateAcceptSocket();
                    listenSocket.Accept(acceptSocket);
                    DispatchConnection(acceptSocket);
                }
                catch (UvException ex) when(UvConstants.IsConnectionReset(ex.StatusCode))
                {
                    Log.ConnectionReset("(null)");
                    acceptSocket?.Dispose();
                }
                catch (UvException ex)
                {
                    Log.LogError(0, ex, "Listener.OnConnection");
                    acceptSocket?.Dispose();
                }
            }
        }
예제 #4
0
        public UvWriteResult GetResult()
        {
            Debug.Assert(_callback == _callbackCompleted);

            var exception = _exception;
            var status    = _status;

            // Reset the awaitable state
            _exception = null;
            _status    = 0;
            _callback  = null;

            return(new UvWriteResult(status, exception));
        }
예제 #5
0
 private Exception LogAndWrapReadError(UvException uvError)
 {
     if (uvError.StatusCode == UvConstants.ECANCELED)
     {
         // The operation was canceled by the server not the client. No need for additional logs.
         return(new ConnectionAbortedException(uvError.Message, uvError));
     }
     else if (UvConstants.IsConnectionReset(uvError.StatusCode))
     {
         // Log connection resets at a lower (Debug) level.
         Log.ConnectionReset(ConnectionId);
         return(new ConnectionResetException(uvError.Message, uvError));
     }
     else
     {
         Log.ConnectionError(ConnectionId, uvError);
         return(new IOException(uvError.Message, uvError));
     }
 }
예제 #6
0
        private async Task ConnectedCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource <int> tcs)
        {
            connect.Dispose();
            if (error != null)
            {
                tcs.SetException(error);
                return;
            }

            var writeReq = new UvWriteReq(Log);

            try
            {
                DispatchPipe.ReadStart(
                    (handle, status2, state) => ((UvListenerSecondary)state)._buf,
                    (handle, status2, state) => ((UvListenerSecondary)state).ReadStartCallback(handle, status2),
                    this);

                writeReq.Init(_thread);
                var result = await writeReq.WriteAsync(
                    DispatchPipe,
                    new ArraySegment <ArraySegment <byte> >(new[] { new ArraySegment <byte>(_pipeMessage) }));

                if (result.Error != null)
                {
                    tcs.SetException(result.Error);
                }
                else
                {
                    tcs.SetResult(0);
                }
            }
            catch (Exception ex)
            {
                DispatchPipe.Dispose();
                tcs.SetException(ex);
            }
            finally
            {
                writeReq.Dispose();
            }
        }
예제 #7
0
        private static void ConnectCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource <int> tcs)
        {
            var listener = (UvListenerSecondary)tcs.Task.AsyncState;

            _ = listener.ConnectedCallback(connect, status, error, tcs);
        }
예제 #8
0
 public UvWriteResult(int status, UvException error)
 {
     Status = status;
     Error  = error;
 }
예제 #9
0
 public void Check(int statusCode, out UvException error)
 {
     // Note: method is explicitly small so the success case is easily inlined
     error = statusCode < 0 ? GetError(statusCode) : null;
 }
예제 #10
0
 public void ip6_addr(string ip, int port, out SockAddr addr, out UvException error)
 {
     Check(_uv_ip6_addr(ip, port, out addr), out error);
 }