public final class RealConnection extends Http2Connection.Listener implements Connection
Modifier and Type | Field and Description |
---|---|
int |
allocationLimit
The maximum number of concurrent streams that can be carried by this connection.
|
java.util.List<java.lang.ref.Reference<StreamAllocation>> |
allocations
Current streams carried by this connection.
|
private ConnectionPool |
connectionPool |
private Handshake |
handshake |
private Http2Connection |
http2Connection |
long |
idleAtNanos
Nanotime timestamp when
allocations.size() reached zero. |
private static int |
MAX_TUNNEL_ATTEMPTS |
boolean |
noNewStreams
If true, no new streams 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 Route |
route |
private okio.BufferedSink |
sink |
private java.net.Socket |
socket
The application layer socket.
|
private okio.BufferedSource |
source |
int |
successCount |
REFUSE_INCOMING_STREAMS
Constructor and Description |
---|
RealConnection(ConnectionPool 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.
|
boolean |
isEligible(Address address,
Route route)
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.
|
private boolean |
isValid(javax.net.ssl.SSLSession sslSocketSession) |
HttpCodec |
newCodec(OkHttpClient client,
Interceptor.Chain chain,
StreamAllocation streamAllocation) |
RealWebSocket.Streams |
newWebSocketStreams(StreamAllocation streamAllocation) |
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.
|
java.net.Socket |
socket()
Returns the socket that this connection is using.
|
boolean |
supportsUrl(HttpUrl url) |
static RealConnection |
testConnection(ConnectionPool connectionPool,
Route route,
java.net.Socket socket,
long idleAtNanos) |
java.lang.String |
toString() |
private static final java.lang.String NPE_THROW_WITH_NULL
private static final int MAX_TUNNEL_ATTEMPTS
private final ConnectionPool 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
public boolean noNewStreams
public int successCount
public int allocationLimit
allocations.size() < allocationLimit
then new streams can be created on this connection.public final java.util.List<java.lang.ref.Reference<StreamAllocation>> allocations
public long idleAtNanos
allocations.size()
reached zero.public RealConnection(ConnectionPool connectionPool, Route route)
public static RealConnection testConnection(ConnectionPool 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 connectTls(ConnectionSpecSelector connectionSpecSelector) throws java.io.IOException
java.io.IOException
private boolean isValid(javax.net.ssl.SSLSession sslSocketSession)
private Request createTunnel(int readTimeout, int writeTimeout, Request tunnelRequest, HttpUrl url) throws java.io.IOException
java.io.IOException
private Request createTunnelRequest()
public boolean isEligible(Address address, @Nullable Route route)
address
. If non-null
route
is the resolved route for a connection.public boolean supportsUrl(HttpUrl url)
public HttpCodec newCodec(OkHttpClient client, Interceptor.Chain chain, StreamAllocation streamAllocation) throws java.net.SocketException
java.net.SocketException
public RealWebSocket.Streams newWebSocketStreams(StreamAllocation streamAllocation)
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()
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