diff options
author | Guang Zhu <guangzhu@google.com> | 2012-02-07 19:13:28 -0800 |
---|---|---|
committer | Guang Zhu <guangzhu@google.com> | 2012-02-07 19:26:54 -0800 |
commit | a8185a622e368d1957e18a3ee9d29d45eda12cfc (patch) | |
tree | a98a179d56f71e2280e1b48f4cc5807fa630eac2 /libsysutils/src | |
parent | dc58e73071aa829a5038caf37211f6b3e2d7b275 (diff) | |
download | core-a8185a622e368d1957e18a3ee9d29d45eda12cfc.tar.gz core-a8185a622e368d1957e18a3ee9d29d45eda12cfc.tar.bz2 core-a8185a622e368d1957e18a3ee9d29d45eda12cfc.zip |
Revert "New NativeDaemonConnector protocol adds a seqnum."
Reverting because it seems to break `adb reboot`
This reverts commit dc58e73071aa829a5038caf37211f6b3e2d7b275.
Change-Id: Ib8cc4379254694398cbb7f3e7a64c20e1ed8c1ba
Diffstat (limited to 'libsysutils/src')
-rw-r--r-- | libsysutils/src/FrameworkListener.cpp | 20 | ||||
-rw-r--r-- | libsysutils/src/SocketClient.cpp | 25 | ||||
-rw-r--r-- | libsysutils/src/SocketListener.cpp | 21 |
3 files changed, 21 insertions, 45 deletions
diff --git a/libsysutils/src/FrameworkListener.cpp b/libsysutils/src/FrameworkListener.cpp index 6b56bb5ff..90be7543f 100644 --- a/libsysutils/src/FrameworkListener.cpp +++ b/libsysutils/src/FrameworkListener.cpp @@ -28,8 +28,6 @@ FrameworkListener::FrameworkListener(const char *socketName) : SocketListener(socketName, true) { mCommands = new FrameworkCommandCollection(); - errorRate = 0; - mCommandCount = 0; } bool FrameworkListener::onDataAvailable(SocketClient *c) { @@ -71,7 +69,6 @@ void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) { bool esc = false; bool quote = false; int k; - bool haveCmdNum = false; memset(argv, 0, sizeof(argv)); memset(tmp, 0, sizeof(tmp)); @@ -118,14 +115,9 @@ void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) { *q = *p++; if (!quote && *q == ' ') { *q = '\0'; - if (!haveCmdNum) { - cli->setCmdNum(atoi(tmp)); - haveCmdNum = true; - } else { - if (argc >= CMD_ARGS_MAX) - goto overflow; - argv[argc++] = strdup(tmp); - } + if (argc >= CMD_ARGS_MAX) + goto overflow; + argv[argc++] = strdup(tmp); memset(tmp, 0, sizeof(tmp)); q = tmp; continue; @@ -148,12 +140,6 @@ void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) { goto out; } - if (errorRate && (++mCommandCount % errorRate == 0)) { - /* ignore this command - let the timeout handler handle it */ - SLOGE("Faking a timeout"); - goto out; - } - for (i = mCommands->begin(); i != mCommands->end(); ++i) { FrameworkCommand *c = *i; diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp index 6e270bd16..722dcb291 100644 --- a/libsysutils/src/SocketClient.cpp +++ b/libsysutils/src/SocketClient.cpp @@ -17,11 +17,9 @@ 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); @@ -48,20 +46,19 @@ int SocketClient::sendMsg(int code, const char *msg, bool addErrno) { const char* fmt; char tmp[1]; int len; - int cmdNum = getCmdNum(); if (addErrno) { - fmt = "%d %.3d %s (%s)"; + fmt = "%.3d %s (%s)"; arg = strerror(errno); } else { - fmt = "%d %.3d %s"; + fmt = "%.3d %s"; arg = NULL; } /* Measure length of required buffer */ - len = snprintf(tmp, sizeof tmp, fmt, cmdNum, code, msg, arg); + len = snprintf(tmp, sizeof tmp, fmt, code, msg, arg); /* Allocate in the stack, then write to it */ buf = (char*)alloca(len+1); - snprintf(buf, len+1, fmt, cmdNum, code, msg, arg); + snprintf(buf, len+1, fmt, code, msg, arg); /* Send the zero-terminated message */ return sendMsg(buf); } @@ -135,17 +132,3 @@ 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; -} diff --git a/libsysutils/src/SocketListener.cpp b/libsysutils/src/SocketListener.cpp index 8f5329cd7..3f871ea88 100644 --- a/libsysutils/src/SocketListener.cpp +++ b/libsysutils/src/SocketListener.cpp @@ -29,8 +29,6 @@ #include <sysutils/SocketListener.h> #include <sysutils/SocketClient.h> -#define DBG 0 - SocketListener::SocketListener(const char *socketName, bool listen) { mListen = listen; mSocketName = socketName; @@ -75,7 +73,6 @@ int SocketListener::startListener() { mSocketName, strerror(errno)); return -1; } - if (DBG) SLOGE("got mSock = %d for %s", mSock, mSocketName); } if (mListen && listen(mSock, 4) < 0) { @@ -167,11 +164,11 @@ void SocketListener::runListener() { max = fd; } pthread_mutex_unlock(&mClientsLock); - if (DBG) SLOGE("mListen=%d, max=%d, mSocketName=%s", mListen, max, mSocketName); + if ((rc = select(max + 1, &read_fds, NULL, NULL, NULL)) < 0) { if (errno == EINTR) continue; - SLOGE("select failed (%s) mListen=%d, max=%d", strerror(errno), mListen, max); + SLOGE("select failed (%s)", strerror(errno)); sleep(1); continue; } else if (!rc) @@ -187,7 +184,6 @@ void SocketListener::runListener() { do { alen = sizeof(addr); c = accept(mSock, &addr, &alen); - if (DBG) SLOGE("%s got %d from accept", mSocketName, c); } while (c < 0 && errno == EINTR); if (c < 0) { SLOGE("accept failed (%s)", strerror(errno)); @@ -221,7 +217,6 @@ void SocketListener::runListener() { * connection-based, remove and destroy it */ if (!onDataAvailable(c) && mListen) { /* Remove the client from our array */ - if (DBG) SLOGE("going to zap %d for %s", c->getSocket(), mSocketName); pthread_mutex_lock(&mClientsLock); for (it = mClients->begin(); it != mClients->end(); ++it) { if (*it == c) { @@ -249,3 +244,15 @@ void SocketListener::sendBroadcast(int code, const char *msg, bool addErrno) { } pthread_mutex_unlock(&mClientsLock); } + +void SocketListener::sendBroadcast(const char *msg) { + pthread_mutex_lock(&mClientsLock); + SocketClientCollection::iterator i; + + for (i = mClients->begin(); i != mClients->end(); ++i) { + if ((*i)->sendMsg(msg)) { + SLOGW("Error sending broadcast (%s)", strerror(errno)); + } + } + pthread_mutex_unlock(&mClientsLock); +} |