/** * Returns the request status line, like "GET / HTTP/1.1". This is exposed * to the application by {@link HttpURLConnectionImpl#getHeaderFields}, so * it needs to be set even if the transport is SPDY. */ String getRequestLine() { String protocol = (connection == null || connection.getHttpMinorVersion() != 0) ? "HTTP/1.1" : "HTTP/1.0"; return method + " " + requestString() + " " + protocol; }
i.hasPrevious(); ) { Connection connection = i.previous(); if (!connection.getRoute().getAddress().equals(address) || !connection.isAlive() || System.nanoTime() - connection.getIdleStartTimeNs() >= keepAliveDurationNs) { continue; if (!connection.isSpdy()) { try { Platform.get().tagSocket(connection.getSocket()); } catch (SocketException e) { Util.closeQuietly(connection); if (foundConnection != null && foundConnection.isSpdy()) {
i.hasPrevious(); ) { Connection connection = i.previous(); if (!connection.isAlive() || connection.isExpired(keepAliveDurationNs)) { i.remove(); expiredConnections.add(connection); if (expiredConnections.size() == MAX_CONNECTIONS_TO_CLEANUP) break; } else if (connection.isIdle()) { idleConnectionCount++; i.hasPrevious() && idleConnectionCount > maxIdleConnections; ) { Connection connection = i.previous(); if (connection.isIdle()) { expiredConnections.add(connection); i.remove();
/** * Returns true if this connection has been idle for longer than * {@code keepAliveDurationNs}. */ public boolean isExpired(long keepAliveDurationNs) { return isIdle() && System.nanoTime() - getIdleStartTimeNs() > keepAliveDurationNs; }
/** * Shares the SPDY connection with the pool. Callers to this method may * continue to use {@code connection}. */ public void maybeShare(Connection connection) { executorService.submit(connectionsCleanupCallable); if (!connection.isSpdy()) { // Only SPDY connections are sharable. return; } if (connection.isAlive()) { synchronized (this) { connections.addFirst(connection); } } }
/** * Gives {@code connection} to the pool. The pool may store the connection, * or close it, as its policy describes. * * <p>It is an error to use {@code connection} after calling this method. */ public void recycle(Connection connection) { if (connection.isSpdy()) { return; } if (!connection.isAlive()) { Util.closeQuietly(connection); return; } try { Platform.get().untagSocket(connection.getSocket()); } catch (SocketException e) { // When unable to remove tagging, skip recycling and close. Platform.get().logW("Unable to untagSocket(): " + e); Util.closeQuietly(connection); return; } synchronized (this) { connections.addFirst(connection); connection.resetIdleStartTime(); } executorService.submit(connectionsCleanupCallable); }
if (!connection.isConnected()) { connection.connect(client.getConnectTimeout(), client.getReadTimeout(), getTunnelConfig()); client.getConnectionPool().maybeShare(connection); client.getRoutesDatabase().connected(connection.getRoute()); } else { connection.updateReadTimeout(client.getReadTimeout()); if (connection.getRoute().getProxy() != client.getProxy()) {
if (method.equals("GET") || pooled.isReadable()) return pooled; pooled.close(); throw new NoSuchElementException(); return new Connection(nextPostponed()); return new Connection(route);
/** * Called after a socket connection has been created or retrieved from the * pool. Subclasses use this hook to get a reference to the TLS data. */ protected void connected(Connection connection) { policy.setSelectedProxy(connection.getRoute().getProxy()); connected = true; }
public HttpsEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders, Connection connection, RetryableOutputStream requestBody) throws IOException { super(client, policy, method, requestHeaders, connection, requestBody); this.sslSocket = connection != null ? (SSLSocket) connection.getSocket() : null; }
/** * Gives {@code connection} to the pool. The pool may store the connection, * or close it, as its policy describes. * * <p>It is an error to use {@code connection} after calling this method. */ public void recycle(Connection connection) { if (connection.isSpdy()) { return; } if (!connection.isAlive()) { Util.closeQuietly(connection); return; } try { Platform.get().untagSocket(connection.getSocket()); } catch (SocketException e) { // When unable to remove tagging, skip recycling and close. Platform.get().logW("Unable to untagSocket(): " + e); Util.closeQuietly(connection); return; } synchronized (this) { connections.addFirst(connection); connection.resetIdleStartTime(); } executorService.submit(connectionsCleanupCallable); }
if (!connection.isConnected()) { connection.connect(client.getConnectTimeout(), client.getReadTimeout(), getTunnelConfig()); client.getConnectionPool().maybeShare(connection); client.getRoutesDatabase().connected(connection.getRoute()); } else { connection.updateReadTimeout(client.getReadTimeout()); if (connection.getRoute().getProxy() != client.getProxy()) {
if (method.equals("GET") || pooled.isReadable()) return pooled; pooled.close(); throw new NoSuchElementException(); return new Connection(nextPostponed()); return new Connection(route);
/** * Returns true if this connection has been idle for longer than * {@code keepAliveDurationNs}. */ public boolean isExpired(long keepAliveDurationNs) { return isIdle() && System.nanoTime() - getIdleStartTimeNs() > keepAliveDurationNs; }
/** * Called after a socket connection has been created or retrieved from the * pool. Subclasses use this hook to get a reference to the TLS data. */ protected void connected(Connection connection) { policy.setSelectedProxy(connection.getRoute().getProxy()); connected = true; }
/** * Shares the SPDY connection with the pool. Callers to this method may * continue to use {@code connection}. */ public void maybeShare(Connection connection) { executorService.submit(connectionsCleanupCallable); if (!connection.isSpdy()) { // Only SPDY connections are sharable. return; } if (connection.isAlive()) { synchronized (this) { connections.addFirst(connection); } } }
public HttpsEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders, Connection connection, RetryableOutputStream requestBody) throws IOException { super(client, policy, method, requestHeaders, connection, requestBody); this.sslSocket = connection != null ? (SSLSocket) connection.getSocket() : null; }
i.hasPrevious(); ) { Connection connection = i.previous(); if (!connection.getRoute().getAddress().equals(address) || !connection.isAlive() || System.nanoTime() - connection.getIdleStartTimeNs() >= keepAliveDurationNs) { continue; if (!connection.isSpdy()) { try { Platform.get().tagSocket(connection.getSocket()); } catch (SocketException e) { Util.closeQuietly(connection); if (foundConnection != null && foundConnection.isSpdy()) {
i.hasPrevious(); ) { Connection connection = i.previous(); if (!connection.isAlive() || connection.isExpired(keepAliveDurationNs)) { i.remove(); expiredConnections.add(connection); if (expiredConnections.size() == MAX_CONNECTIONS_TO_CLEANUP) break; } else if (connection.isIdle()) { idleConnectionCount++; i.hasPrevious() && idleConnectionCount > maxIdleConnections; ) { Connection connection = i.previous(); if (connection.isIdle()) { expiredConnections.add(connection); i.remove();
/** * Returns the request status line, like "GET / HTTP/1.1". This is exposed * to the application by {@link HttpURLConnectionImpl#getHeaderFields}, so * it needs to be set even if the transport is SPDY. */ String getRequestLine() { String protocol = (connection == null || connection.getHttpMinorVersion() != 0) ? "HTTP/1.1" : "HTTP/1.0"; return method + " " + requestString() + " " + protocol; }