Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ConnectToTcpHostAsync()

async ValueTask<(Socket, Stream)> System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync ( string host,
int port,
HttpRequestMessage initialRequest,
bool async,
CancellationToken cancellationToken )
inlineprivate

Definition at line 1119 of file HttpConnectionPool.cs.

1120 {
1121 cancellationToken.ThrowIfCancellationRequested();
1122 DnsEndPoint endPoint = new DnsEndPoint(host, port);
1123 Socket socket = null;
1124 try
1125 {
1126 Stream item;
1127 if (Settings._connectCallback != null)
1128 {
1130 if (!async && !valueTask.IsCompleted)
1131 {
1132 Trace("ConnectCallback completing asynchronously for a synchronous request.", "ConnectToTcpHostAsync");
1133 }
1134 item = (await valueTask.ConfigureAwait(continueOnCapturedContext: false)) ?? throw new HttpRequestException(System.SR.net_http_null_from_connect_callback);
1135 }
1136 else
1137 {
1138 socket = new Socket(SocketType.Stream, ProtocolType.Tcp)
1139 {
1140 NoDelay = true
1141 };
1142 if (async)
1143 {
1144 await socket.ConnectAsync(endPoint, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
1145 }
1146 else
1147 {
1148 using (cancellationToken.UnsafeRegister(delegate(object s)
1149 {
1150 ((Socket)s).Dispose();
1151 }, socket))
1152 {
1153 socket.Connect(endPoint);
1154 }
1155 }
1157 }
1158 return (socket, item);
1159 }
1160 catch (Exception ex)
1161 {
1162 socket?.Dispose();
1163 throw (ex is OperationCanceledException ex2 && ex2.CancellationToken == cancellationToken) ? CancellationHelper.CreateOperationCanceledException(null, cancellationToken) : ConnectHelper.CreateWrappedException(ex, endPoint.Host, endPoint.Port, cancellationToken);
1164 }
1165 }
void Trace(string message, [CallerMemberName] string memberName=null)
Func< SocketsHttpConnectionContext, CancellationToken, ValueTask< Stream > > _connectCallback

References System.Net.Http.HttpConnectionSettings._connectCallback, System.cancellationToken, System.Net.Http.CancellationHelper.CreateOperationCanceledException(), System.Net.Http.ConnectHelper.CreateWrappedException(), System.item, System.SR.net_http_null_from_connect_callback, System.Net.Sockets.NoDelay, System.s, System.Net.Http.HttpConnectionPool.Settings, System.Net.Sockets.Socket, and System.Net.Http.HttpConnectionPool.Trace().

Referenced by System.Net.Http.HttpConnectionPool.ConnectAsync(), and System.Net.Http.HttpConnectionPool.EstablishSocksTunnel().