diff options
author | Brad Fitzpatrick <bradfitz@android.com> | 2011-03-17 15:41:20 -0700 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@android.com> | 2011-03-17 15:50:02 -0700 |
commit | 648ebad883e7825353c841950dd7d78664c238e6 (patch) | |
tree | 93a4928755fd9581006bb314b36b76e6304d1375 /include/sysutils/SocketClient.h | |
parent | b51326351a28f70e4c003df8f89d0b450bcd6041 (diff) | |
download | system_core-648ebad883e7825353c841950dd7d78664c238e6.zip system_core-648ebad883e7825353c841950dd7d78664c238e6.tar.gz system_core-648ebad883e7825353c841950dd7d78664c238e6.tar.bz2 |
SocketClient: add optional reference counting
Needed to fix a race in netd.
Bug: 3438459
Change-Id: Icd7f5f035510235f733a25c0621479d3e644b152
Diffstat (limited to 'include/sysutils/SocketClient.h')
-rw-r--r-- | include/sysutils/SocketClient.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/sysutils/SocketClient.h b/include/sysutils/SocketClient.h index 2fcc331..ef6dd9b 100644 --- a/include/sysutils/SocketClient.h +++ b/include/sysutils/SocketClient.h @@ -19,6 +19,10 @@ class SocketClient { /* Peer group ID */ gid_t mGid; + /* Reference count (starts at 1) */ + pthread_mutex_t mRefCountMutex; + int mRefCount; + public: SocketClient(int sock); virtual ~SocketClient() {} @@ -34,6 +38,13 @@ public: // Sending binary data: int sendData(const void *data, int len); + + // Optional reference counting. Reference count starts at 1. If + // it's decremented to 0, it deletes itself. + // SocketListener creates a SocketClient (at refcount 1) and calls + // decRef() when it's done with the client. + void incRef(); + void decRef(); }; typedef android::List<SocketClient *> SocketClientCollection; |