public final class RealConnection extends Http2Connection.Listener implements Connection
Modifier and Type | Field and Description |
---|---|
private int |
allocationLimit
The maximum number of concurrent streams that can be carried by this connection.
|
RealConnectionPool |
connectionPool |
private Handshake |
handshake |
private Http2Connection |
http2Connection |
(package private) long |
idleAtNanos
Nanotime timestamp when
allocations.size() reached zero. |
private static int |
MAX_TUNNEL_ATTEMPTS |
(package private) boolean |
noNewExchanges
If true, no new exchanges can be created on this connection.
|
private static java.lang.String |
NPE_THROW_WITH_NULL |
private Protocol |
protocol |
private java.net.Socket |
rawSocket
The low-level TCP socket.
|
private int |
refusedStreamCount |
private Route |
route |
(package private) int |
routeFailureCount
The number of times there was a problem establishing a stream that could be due to route
chosen.
|
private okio.BufferedSink |
sink |
private java.net.Socket |
socket
The application layer socket.
|
private okio.BufferedSource |
source |
(package private) int |
successCount |
(package private) java.util.List<java.lang.ref.Reference<Transmitter>> |
transmitters
Current calls carried by this connection.
|
REFUSE_INCOMING_STREAMS
Constructor and Description |
---|
RealConnection(RealConnectionPool connectionPool,
Route route) |
Modifier and Type | Method and Description |
---|---|
void |
cancel() |
void |
connect(int connectTimeout,
int readTimeout,
int writeTimeout,
int pingIntervalMillis,
boolean connectionRetryEnabled,
Call call,
EventListener eventListener) |
private void |
connectSocket(int connectTimeout,
int readTimeout,
Call call,
EventListener eventListener)
Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket.
|
private void |
connectTls(ConnectionSpecSelector connectionSpecSelector) |
private void |
connectTunnel(int connectTimeout,
int readTimeout,
int writeTimeout,
Call call,
EventListener eventListener)
Does all the work to build an HTTPS connection over a proxy tunnel.
|
private Request |
createTunnel(int readTimeout,
int writeTimeout,
Request tunnelRequest,
HttpUrl url)
To make an HTTPS connection over an HTTP proxy, send an unencrypted CONNECT request to create
the proxy connection.
|
private Request |
createTunnelRequest()
Returns a request that creates a TLS tunnel via an HTTP proxy.
|
private void |
establishProtocol(ConnectionSpecSelector connectionSpecSelector,
int pingIntervalMillis,
Call call,
EventListener eventListener) |
Handshake |
handshake()
Returns the TLS handshake used to establish this connection, or null if the connection is not
HTTPS.
|
(package private) boolean |
isEligible(Address address,
java.util.List<Route> routes)
Returns true if this connection can carry a stream allocation to
address . |
boolean |
isHealthy(boolean doExtensiveChecks)
Returns true if this connection is ready to host new streams.
|
boolean |
isMultiplexed()
Returns true if this is an HTTP/2 connection.
|
(package private) ExchangeCodec |
newCodec(OkHttpClient client,
Interceptor.Chain chain) |
(package private) RealWebSocket.Streams |
newWebSocketStreams(Exchange exchange) |
void |
noNewExchanges()
Prevent further exchanges from being created on this connection.
|
void |
onSettings(Http2Connection connection)
When settings are received, adjust the allocation limit.
|
void |
onStream(Http2Stream stream)
Refuse incoming streams.
|
Protocol |
protocol()
Returns the protocol negotiated by this connection, or
Protocol.HTTP_1_1 if no protocol
has been negotiated. |
Route |
route()
Returns the route used by this connection.
|
private boolean |
routeMatchesAny(java.util.List<Route> candidates)
Returns true if this connection's route has the same address as any of
routes . |
java.net.Socket |
socket()
Returns the socket that this connection is using.
|
private void |
startHttp2(int pingIntervalMillis) |
boolean |
supportsUrl(HttpUrl url) |
(package private) static RealConnection |
testConnection(RealConnectionPool connectionPool,
Route route,
java.net.Socket socket,
long idleAtNanos) |
java.lang.String |
toString() |
(package private) void |
trackFailure(java.io.IOException e)
Track a failure using this connection.
|
private static final java.lang.String NPE_THROW_WITH_NULL
private static final int MAX_TUNNEL_ATTEMPTS
public final RealConnectionPool connectionPool
private final Route route
private java.net.Socket rawSocket
private java.net.Socket socket
private Handshake handshake
private Protocol protocol
private Http2Connection http2Connection
private okio.BufferedSource source
private okio.BufferedSink sink
boolean noNewExchanges
connectionPool
.int routeFailureCount
connectionPool
.int successCount
private int refusedStreamCount
private int allocationLimit
allocations.size() < allocationLimit
then new streams can be created on this connection.final java.util.List<java.lang.ref.Reference<Transmitter>> transmitters
long idleAtNanos
allocations.size()
reached zero.public RealConnection(RealConnectionPool connectionPool, Route route)
public void noNewExchanges()
static RealConnection testConnection(RealConnectionPool connectionPool, Route route, java.net.Socket socket, long idleAtNanos)
public void connect(int connectTimeout, int readTimeout, int writeTimeout, int pingIntervalMillis, boolean connectionRetryEnabled, Call call, EventListener eventListener)
private void connectTunnel(int connectTimeout, int readTimeout, int writeTimeout, Call call, EventListener eventListener) throws java.io.IOException
java.io.IOException
private void connectSocket(int connectTimeout, int readTimeout, Call call, EventListener eventListener) throws java.io.IOException
java.io.IOException
private void establishProtocol(ConnectionSpecSelector connectionSpecSelector, int pingIntervalMillis, Call call, EventListener eventListener) throws java.io.IOException
java.io.IOException
private void startHttp2(int pingIntervalMillis) throws java.io.IOException
java.io.IOException
private void connectTls(ConnectionSpecSelector connectionSpecSelector) throws java.io.IOException
java.io.IOException
private Request createTunnel(int readTimeout, int writeTimeout, Request tunnelRequest, HttpUrl url) throws java.io.IOException
java.io.IOException
private Request createTunnelRequest() throws java.io.IOException
In order to support preemptive authentication we pass a fake “Auth Failed” response to the authenticator. This gives the authenticator the option to customize the CONNECT request. It can decline to do so by returning null, in which case OkHttp will use it as-is
java.io.IOException
boolean isEligible(Address address, @Nullable java.util.List<Route> routes)
address
. If non-null
route
is the resolved route for a connection.private boolean routeMatchesAny(java.util.List<Route> candidates)
routes
. This
requires us to have a DNS address for both hosts, which only happens after route planning. We
can't coalesce connections that use a proxy, since proxies don't tell us the origin server's IP
address.public boolean supportsUrl(HttpUrl url)
ExchangeCodec newCodec(OkHttpClient client, Interceptor.Chain chain) throws java.net.SocketException
java.net.SocketException
RealWebSocket.Streams newWebSocketStreams(Exchange exchange) throws java.net.SocketException
java.net.SocketException
public Route route()
Connection
route
in interface Connection
public void cancel()
public java.net.Socket socket()
Connection
socket
in interface Connection
public boolean isHealthy(boolean doExtensiveChecks)
public void onStream(Http2Stream stream) throws java.io.IOException
onStream
in class Http2Connection.Listener
java.io.IOException
public void onSettings(Http2Connection connection)
onSettings
in class Http2Connection.Listener
public Handshake handshake()
Connection
handshake
in interface Connection
public boolean isMultiplexed()
void trackFailure(@Nullable java.io.IOException e)
public Protocol protocol()
Connection
Protocol.HTTP_1_1
if no protocol
has been negotiated. This method returns Protocol.HTTP_1_1
even if the remote peer is
using Protocol.HTTP_1_0
.protocol
in interface Connection
public java.lang.String toString()
toString
in class java.lang.Object