コード例 #1
0
        private static int HandleEventShutdownInitiatedByTransport(State state, ref QUIC_CONNECTION_EVENT connectionEvent)
        {
            if (!state.Connected && state.ConnectTcs != null)
            {
                Debug.Assert(state.Connection != null);
                state.Connection = null;

                Exception ex = new MsQuicException(connectionEvent.SHUTDOWN_INITIATED_BY_TRANSPORT.Status, "Connection has been shutdown by transport");
                state.ConnectTcs !.SetException(ExceptionDispatchInfo.SetCurrentStackTrace(ex));
                state.ConnectTcs = null;
            }

            // To throw QuicConnectionAbortedException (instead of QuicOperationAbortedException) out of AcceptStreamAsync() since
            // it wasn't our side who shutdown the connection.
            // We should rather keep the Status and propagate it either in a different exception or as a different field of QuicConnectionAbortedException.
            // See: https://github.com/dotnet/runtime/issues/60133
            state.AbortErrorCode = 0;
            state.AcceptQueue.Writer.TryComplete();
            return(QUIC_STATUS_SUCCESS);
        }
コード例 #2
0
 private static unsafe int NativeCallback(QUIC_HANDLE *handle, void *context, QUIC_CONNECTION_EVENT *evnt)
 {
     Console.WriteLine(evnt->Type);
     if (evnt->Type == QUIC_CONNECTION_EVENT_TYPE.CONNECTED)
     {
         QUIC_API_TABLE *ApiTable = (QUIC_API_TABLE *)context;
         void *          buf      = stackalloc byte[128];
         uint            len      = 128;
         if (MsQuic.StatusSucceeded(ApiTable->GetParam(handle, MsQuic.QUIC_PARAM_CONN_REMOTE_ADDRESS, &len, buf)))
         {
             QuicAddr *addr = (QuicAddr *)(buf);
             Console.WriteLine($"Connected Family: {addr->Family}");
         }
     }
     if (evnt->Type == QUIC_CONNECTION_EVENT_TYPE.PEER_STREAM_STARTED)
     {
         Console.WriteLine("Aborting Stream");
         return(MsQuic.QUIC_STATUS_ABORTED);
     }
     if (evnt->Type == QUIC_CONNECTION_EVENT_TYPE.SHUTDOWN_INITIATED_BY_TRANSPORT)
     {
         Console.WriteLine($"{evnt->SHUTDOWN_INITIATED_BY_TRANSPORT.Status.ToString("X8")}: {MsQuicException.GetErrorCodeForStatus(evnt->SHUTDOWN_INITIATED_BY_TRANSPORT.Status)}");
     }
     return(MsQuic.QUIC_STATUS_SUCCESS);
 }