• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Révision12a26e310be16dd88422fb139ee4b27f8c8aecf5 (tree)
l'heure2009-06-16 06:40:15
AuteurAndroid (Google) Code Review <android-gerrit@goog...>
CommiterAndroid (Google) Code Review

Message de Log

Merge change 4226 into donut

* changes:

libsysutils: Move to a null terminated string protocol using space as a field separator.

Change Summary

Modification

--- a/include/sysutils/FrameworkCommand.h
+++ b/include/sysutils/FrameworkCommand.h
@@ -29,7 +29,7 @@ public:
2929 FrameworkCommand(const char *cmd);
3030 virtual ~FrameworkCommand() { }
3131
32- virtual int runCommand(SocketClient *c, char *data) = 0;
32+ virtual int runCommand(SocketClient *c, int argc, char **argv) = 0;
3333
3434 const char *getCommand() { return mCommand; }
3535 };
--- a/include/sysutils/FrameworkListener.h
+++ b/include/sysutils/FrameworkListener.h
@@ -22,6 +22,8 @@
2222 class SocketClient;
2323
2424 class FrameworkListener : public SocketListener {
25+public:
26+ static const int CMD_ARGS_MAX = 8;
2527 private:
2628 FrameworkCommandCollection *mCommands;
2729
@@ -34,6 +36,6 @@ protected:
3436 virtual bool onDataAvailable(SocketClient *c);
3537
3638 private:
37- void dispatchCommand(SocketClient *c, char *cmd);
39+ void dispatchCommand(SocketClient *c, char *data);
3840 };
3941 #endif
--- a/libsysutils/src/FrameworkCommand.cpp
+++ b/libsysutils/src/FrameworkCommand.cpp
@@ -25,7 +25,7 @@ FrameworkCommand::FrameworkCommand(const char *cmd) {
2525 mCommand = cmd;
2626 }
2727
28-int FrameworkCommand::runCommand(SocketClient *c, char *data) {
28+int FrameworkCommand::runCommand(SocketClient *c, int argc, char **argv) {
2929 LOGW("Command %s has no run handler!", getCommand());
3030 errno = ENOSYS;
3131 return -1;
--- a/libsysutils/src/FrameworkListener.cpp
+++ b/libsysutils/src/FrameworkListener.cpp
@@ -36,17 +36,14 @@ bool FrameworkListener::onDataAvailable(SocketClient *c) {
3636 if ((len = read(c->getSocket(), buffer, sizeof(buffer) -1)) < 0) {
3737 LOGE("read() failed (%s)", strerror(errno));
3838 return errno;
39- } else if (!len) {
40- LOGW("Lost connection to client");
39+ } else if (!len)
4140 return false;
42- }
4341
4442 int offset = 0;
4543 int i;
4644
4745 for (i = 0; i < len; i++) {
48- if (buffer[i] == '\n') {
49- buffer[i] = '\0';
46+ if (buffer[i] == '\0') {
5047 dispatchCommand(c, buffer + offset);
5148 offset = i + 1;
5249 }
@@ -58,13 +55,20 @@ void FrameworkListener::registerCmd(FrameworkCommand *cmd) {
5855 mCommands->push_back(cmd);
5956 }
6057
61-void FrameworkListener::dispatchCommand(SocketClient *cli, char *cmd) {
62- char *next = cmd;
63- char *cm;
64- char *arg;
58+void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) {
59+ int argc;
60+ char *argv[FrameworkListener::CMD_ARGS_MAX];
61+
62+ if (!index(data, '"')) {
63+ char *next = data;
64+ char *field;
65+ int i;
6566
66- if (!(cm = strsep(&next, ":"))) {
67- cli->sendMsg(500, "Malformatted message", false);
67+ for (i = 0; (i < FrameworkListener::CMD_ARGS_MAX) &&
68+ (argv[i] = strsep(&next, " ")); i++);
69+ argc = i+1;
70+ } else {
71+ LOGD("blehhh not supported");
6872 return;
6973 }
7074
@@ -73,8 +77,8 @@ void FrameworkListener::dispatchCommand(SocketClient *cli, char *cmd) {
7377 for (i = mCommands->begin(); i != mCommands->end(); ++i) {
7478 FrameworkCommand *c = *i;
7579
76- if (!strcmp(cm, c->getCommand())) {
77- if (c->runCommand(cli, next)) {
80+ if (!strcmp(argv[0], c->getCommand())) {
81+ if (c->runCommand(cli, argc, argv)) {
7882 LOGW("Handler '%s' error (%s)", c->getCommand(), strerror(errno));
7983 }
8084 return;
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -33,19 +33,10 @@ int SocketClient::sendMsg(const char *msg) {
3333 return -1;
3434 }
3535
36- char *tmp;
37- const char *bp = msg;
38-
39- if (msg[strlen(msg)] != '\n') {
40- tmp = (char *) alloca(strlen(msg) + 1);
41- strcpy(tmp, msg);
42- strcat(tmp, "\n");
43- bp = tmp;
44- }
45-
36+ // Send the message including null character
4637 int rc = 0;
47- const char *p = bp;
48- int brtw = strlen(bp);
38+ const char *p = msg;
39+ int brtw = strlen(msg) + 1;
4940
5041 pthread_mutex_lock(&mWriteMutex);
5142 while(brtw) {
--- a/libsysutils/src/SocketListener.cpp
+++ b/libsysutils/src/SocketListener.cpp
@@ -157,7 +157,6 @@ void SocketListener::runListener() {
157157 if (FD_ISSET(fd, &read_fds)) {
158158 pthread_mutex_unlock(&mClientsLock);
159159 if (!onDataAvailable(*it)) {
160- LOGD("SocketListener closing client socket");
161160 close(fd);
162161 pthread_mutex_lock(&mClientsLock);
163162 delete *it;