From d83e6b1cf9330504abce1d2c8700c9b6b43cc5e8 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 21 Apr 2011 13:44:30 -0700 Subject: Add Socket tagging for granular data accounting. Changes SingleClientConnManager and ThreadSafeClientConnManager to tag any recycled Sockets based on the current thread. (Actual tagging is maintained and applied in BlockGuard.) Change-Id: Ib34897bb2af8641fa65adc664f7858f9d43ffeeb --- .../http/impl/conn/SingleClientConnManager.java | 25 ++++++++++++++++++++++ .../conn/tsccm/ThreadSafeClientConnManager.java | 25 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) (limited to 'src/org/apache/http/impl') diff --git a/src/org/apache/http/impl/conn/SingleClientConnManager.java b/src/org/apache/http/impl/conn/SingleClientConnManager.java index 7999f3e..d770a35 100644 --- a/src/org/apache/http/impl/conn/SingleClientConnManager.java +++ b/src/org/apache/http/impl/conn/SingleClientConnManager.java @@ -31,7 +31,10 @@ package org.apache.http.impl.conn; +import dalvik.system.BlockGuard; + import java.io.IOException; +import java.net.Socket; import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; @@ -249,6 +252,19 @@ public class SingleClientConnManager implements ClientConnectionManager { if (recreate) uniquePoolEntry = new PoolEntry(); + // BEGIN android-changed + // When using a recycled Socket, we need to re-tag it with any + // updated statistics options. + try { + final Socket socket = uniquePoolEntry.connection.getSocket(); + if (socket != null) { + BlockGuard.tagSocketFd(socket.getFileDescriptor$()); + } + } catch (IOException iox) { + log.debug("Problem tagging socket.", iox); + } + // END android-changed + managedConn = new ConnAdapter(uniquePoolEntry, route); return managedConn; @@ -279,6 +295,15 @@ public class SingleClientConnManager implements ClientConnectionManager { } try { + // BEGIN android-changed + // When recycling a Socket, we un-tag it to avoid collecting + // statistics from future users. + final Socket socket = uniquePoolEntry.connection.getSocket(); + if (socket != null) { + BlockGuard.untagSocketFd(socket.getFileDescriptor$()); + } + // END android-changed + // make sure that the response has been read completely if (sca.isOpen() && (this.alwaysShutDown || !sca.isMarkedReusable()) diff --git a/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java b/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java index 0781e05..717acf0 100644 --- a/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java +++ b/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java @@ -30,7 +30,10 @@ package org.apache.http.impl.conn.tsccm; +import dalvik.system.BlockGuard; + import java.io.IOException; +import java.net.Socket; import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; @@ -173,6 +176,18 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { } BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit); + // BEGIN android-changed + // When using a recycled Socket, we need to re-tag it with any + // updated statistics options. + try { + final Socket socket = entry.getConnection().getSocket(); + if (socket != null) { + BlockGuard.tagSocketFd(socket.getFileDescriptor$()); + } + } catch (IOException iox) { + log.debug("Problem tagging socket.", iox); + } + // END android-changed return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry); } @@ -196,6 +211,16 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { } try { + // BEGIN android-changed + // When recycling a Socket, we un-tag it to avoid collecting + // statistics from future users. + final BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry(); + final Socket socket = entry.getConnection().getSocket(); + if (socket != null) { + BlockGuard.untagSocketFd(socket.getFileDescriptor$()); + } + // END android-changed + // make sure that the response has been read completely if (hca.isOpen() && !hca.isMarkedReusable()) { if (log.isDebugEnabled()) { -- cgit v1.1