Beispiel #1
0
        private HttpClientConnection(HttpClientConnectionOptions options)
        {
            options.Validate();

            this.options = options;
            NativeHandle = API.make_new(
                options.ClientBootstrap.NativeHandle.DangerousGetHandle(),
                options.InitialWindowSize,
                options.HostName,
                options.Port,
                options.SocketOptions?.NativeHandle.DangerousGetHandle() ?? IntPtr.Zero,
                options.TlsConnectionOptions?.NativeHandle.DangerousGetHandle() ?? IntPtr.Zero,
                OnConnectionSetup,
                OnConnectionShutdown);
        }
Beispiel #2
0
        public static Task <HttpClientConnection> NewConnection(HttpClientConnectionOptions options)
        {
            options.Validate();

            var bootstrap = new ConnectionBootstrap();

            options.ConnectionSetup += (sender, e) => {
                if (e.ErrorCode != 0)
                {
                    var message = CRT.ErrorString(e.ErrorCode);
                    bootstrap.TaskSource.SetException(new WebException(String.Format("Failed to connect: {0}", message)));
                }
                else
                {
                    bootstrap.TaskSource.SetResult(bootstrap.Connection);
                }
            };

            bootstrap.Connection = new HttpClientConnection(options);
            return(bootstrap.TaskSource.Task);
        }