SocketClient.h revision 4520246d3534c087f3e9253c34f99dd1e45b7bd7
1#ifndef _SOCKET_CLIENT_H 2#define _SOCKET_CLIENT_H 3 4#include "../../../frameworks/base/include/utils/List.h" 5 6#include <pthread.h> 7#include <sys/types.h> 8 9class SocketClient { 10 int mSocket; 11 bool mSocketOwned; 12 pthread_mutex_t mWriteMutex; 13 14 /* Peer process ID */ 15 pid_t mPid; 16 17 /* Peer user ID */ 18 uid_t mUid; 19 20 /* Peer group ID */ 21 gid_t mGid; 22 23 /* Reference count (starts at 1) */ 24 pthread_mutex_t mRefCountMutex; 25 int mRefCount; 26 27public: 28 SocketClient(int sock, bool owned); 29 virtual ~SocketClient(); 30 31 int getSocket() { return mSocket; } 32 pid_t getPid() const { return mPid; } 33 uid_t getUid() const { return mUid; } 34 gid_t getGid() const { return mGid; } 35 36 // Send null-terminated C strings: 37 int sendMsg(int code, const char *msg, bool addErrno); 38 int sendMsg(const char *msg); 39 40 // Sending binary data: 41 int sendData(const void *data, int len); 42 43 // Optional reference counting. Reference count starts at 1. If 44 // it's decremented to 0, it deletes itself. 45 // SocketListener creates a SocketClient (at refcount 1) and calls 46 // decRef() when it's done with the client. 47 void incRef(); 48 bool decRef(); // returns true at 0 (but note: SocketClient already deleted) 49}; 50 51typedef android::List<SocketClient *> SocketClientCollection; 52#endif 53