예제 #1
0
        public async void SmokeTest(Func <EndPoint> endpoint, int length, PipeScheduler schedulerMode, int threadCount, int ringSize, bool threadAffinity)
        {
            using var server          = new EchoServer(endpoint(), OutputHelper);
            await using var transport = new IoUringTransport(Options.Create(new IoUringOptions
            {
                ThreadCount               = threadCount,
                SetThreadAffinity         = threadAffinity,
                ApplicationSchedulingMode = schedulerMode,
                RingSize = ringSize
            }));
            await using var connectionFactory = new ConnectionFactory(transport);

            for (int i = 0; i < 3; i++)
            {
                await using var connection = await connectionFactory.ConnectAsync(server.EndPoint);

                for (int j = 0; j < 3; j++)
                {
                    await SendReceiveData(connection.Transport, length);
                }

                await connection.Transport.Output.CompleteAsync();

                await connection.Transport.Input.CompleteAsync();
            }
        }
예제 #2
0
 public static async ValueTask <Connection> ConnectAsync(ConnectionFactory factory, DnsEndPoint endPoint, IConnectionProperties?options, CancellationToken cancellationToken)
 {
     try
     {
         return(await factory.ConnectAsync(endPoint, options, cancellationToken).ConfigureAwait(false));
     }
     catch (OperationCanceledException ex) when(ex.CancellationToken == cancellationToken)
     {
         throw CancellationHelper.CreateOperationCanceledException(innerException: null, cancellationToken);
     }
     catch (Exception ex)
     {
         throw CreateWrappedException(ex, endPoint.Host, endPoint.Port, cancellationToken);
     }
 }
        public Task <ConnectionContext> ConnectAsync(HubServiceEndpoint endpoint, TransferFormat transferFormat, string connectionId, string target, CancellationToken cancellationToken = default, IDictionary <string, string> headers = null)
        {
            if (headers == null)
            {
                headers = new Dictionary <string, string> {
                    { Constants.AsrsUserAgent, _productInfo }
                };
            }
            else
            {
                headers[Constants.AsrsUserAgent] = _productInfo;
            }

            return(_connectionFactory.ConnectAsync(endpoint, transferFormat, connectionId, target, cancellationToken, headers));
        }
예제 #4
0
        public async Task <StringsModel> LoadAsync(StringsModel stringsModel)
        {
            using SqliteConnection connection = await ConnectionFactory.ConnectAsync();

            SqliteCommand query = connection.CreateCommand();

            query.CommandText = "select String from Strings where Identifier = @Identifier and Locale = @Locale";
            query.Parameters.AddWithValue("@Identifier", stringsModel.Identifier);
            query.Parameters.AddWithValue("@Locale", stringsModel.Locale);

            SqliteDataReader reader = await query.ExecuteReaderAsync();

            if (await reader.ReadAsync())
            {
                stringsModel.String = (string)reader["String"];
            }

            return(stringsModel);
        }
예제 #5
0
        public async Task <ShibaConfigModel> LoadAsync()
        {
            _connection = await ConnectionFactory.ConnectAsync();

            SqliteCommand query = _connection.CreateCommand();

            query.CommandText += "select * from ShibaConfig;";

            SqliteDataReader reader = await query.ExecuteReaderAsync();

            ShibaConfigModel shibaConfig = null;

            if (await reader.ReadAsync())
            {
                shibaConfig = new ShibaConfigModel(Convert.ToUInt64(reader["OwnerID"]), reader["Token"].ToString(), reader["MongoConnectionString"].ToString());
            }

            await _connection.CloseAsync();

            await _connection.DisposeAsync();

            return(shibaConfig);
        }
예제 #6
0
        public override async ValueTask ProcessAsync(HttpMessage message)
        {
            var pipelineRequest = message.Request;
            var host            = pipelineRequest.Uri.Host;

            HttpMethod method = MapMethod(pipelineRequest.Method);

            Connection connection = await connectionFactory.ConnectAsync(new DnsEndPoint(host, 80));

            HttpConnection httpConnection = new Http1Connection(connection, HttpPrimitiveVersion.Version11);

            await using (ValueHttpRequest request = (await httpConnection.CreateNewRequestAsync(HttpPrimitiveVersion.Version11, HttpVersionPolicy.RequestVersionExact)).Value) {
                RequestContent pipelineContent = pipelineRequest.Content;
                long           contentLength   = 0;
                if (pipelineContent != null)
                {
                    if (!pipelineContent.TryComputeLength(out contentLength))
                    {
                        throw new NotImplementedException();
                    }
                }
                request.ConfigureRequest(contentLength: contentLength, hasTrailingHeaders: false);

                request.WriteRequest(method, pipelineRequest.Uri.ToUri());

                var pipelineHeaders = pipelineRequest.Headers;
                foreach (var header in pipelineHeaders)
                {
                    request.WriteHeader(header.Name, header.Value);
                }

                checked {
                    if (contentLength != 0)
                    {
                        using var ms = new MemoryStream((int)contentLength); // TODO: can the buffer be disposed here?
                        await pipelineContent.WriteToAsync(ms, message.CancellationToken);

                        await request.WriteContentAsync(ms.GetBuffer().AsMemory(0, (int)ms.Length));
                    }
                }

                await request.CompleteRequestAsync();

                var response = new NoAllocResponse();
                message.Response = response;

                await request.ReadToFinalResponseAsync();

                response.SetStatus((int)request.StatusCode);

                if (await request.ReadToHeadersAsync())
                {
                    await request.ReadHeadersAsync(response, state : null);
                }

                if (await request.ReadToContentAsync())
                {
                    var buffer = new byte[4096];
                    int readLen;
                    do
                    {
                        while ((readLen = await request.ReadContentAsync(buffer)) != 0)
                        {
                            if (readLen < 4096)
                            {
                                response.ContentStream = new MemoryStream(buffer, 0, readLen);
                            }
                            else
                            {
                                throw new NotImplementedException();
                            }
                        }
                    }while (await request.ReadToNextContentAsync());
                }

                if (await request.ReadToTrailingHeadersAsync())
                {
                    await request.ReadHeadersAsync(response, state : null);
                }
            }
        }