summaryrefslogtreecommitdiff
path: root/libsysutils/src/SocketClient.cpp
diff options
context:
space:
mode:
authorRobert Greenwalt <rgreenwalt@google.com>2012-02-07 12:23:14 -0800
committerRobert Greenwalt <rgreenwalt@google.com>2012-02-07 16:00:07 -0800
commitdc58e73071aa829a5038caf37211f6b3e2d7b275 (patch)
tree8a92d09200206a41977c40a7dfb8784c24f7118a /libsysutils/src/SocketClient.cpp
parent6f53225ef9f60a18a69b4ad3ba920ada168b719e (diff)
New NativeDaemonConnector protocol adds a seqnum.
Allows for one socket to be multiplexed for multiple requests. bug:5864209 Change-Id: I934c88da25d95e093371f455442bdf2f0ed7a4f4
Diffstat (limited to 'libsysutils/src/SocketClient.cpp')
-rw-r--r--libsysutils/src/SocketClient.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index 722dcb291..6e270bd16 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -17,9 +17,11 @@ SocketClient::SocketClient(int socket, bool owned)
, mUid(-1)
, mGid(-1)
, mRefCount(1)
+ , mCmdNum(0)
{
pthread_mutex_init(&mWriteMutex, NULL);
pthread_mutex_init(&mRefCountMutex, NULL);
+ pthread_mutex_init(&mCmdNumMutex, NULL);
struct ucred creds;
socklen_t szCreds = sizeof(creds);
@@ -46,19 +48,20 @@ int SocketClient::sendMsg(int code, const char *msg, bool addErrno) {
const char* fmt;
char tmp[1];
int len;
+ int cmdNum = getCmdNum();
if (addErrno) {
- fmt = "%.3d %s (%s)";
+ fmt = "%d %.3d %s (%s)";
arg = strerror(errno);
} else {
- fmt = "%.3d %s";
+ fmt = "%d %.3d %s";
arg = NULL;
}
/* Measure length of required buffer */
- len = snprintf(tmp, sizeof tmp, fmt, code, msg, arg);
+ len = snprintf(tmp, sizeof tmp, fmt, cmdNum, code, msg, arg);
/* Allocate in the stack, then write to it */
buf = (char*)alloca(len+1);
- snprintf(buf, len+1, fmt, code, msg, arg);
+ snprintf(buf, len+1, fmt, cmdNum, code, msg, arg);
/* Send the zero-terminated message */
return sendMsg(buf);
}
@@ -132,3 +135,17 @@ bool SocketClient::decRef() {
}
return deleteSelf;
}
+
+void SocketClient::setCmdNum(int cmdNum) {
+ pthread_mutex_lock(&mCmdNumMutex);
+ mCmdNum = cmdNum;
+ pthread_mutex_unlock(&mCmdNumMutex);
+}
+
+int SocketClient::getCmdNum() {
+ int ret;
+ pthread_mutex_lock(&mCmdNumMutex);
+ ret = mCmdNum;
+ pthread_mutex_unlock(&mCmdNumMutex);
+ return ret;
+}