Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8185a62 authored by Guang Zhu's avatar Guang Zhu
Browse files

Revert "New NativeDaemonConnector protocol adds a seqnum."

Reverting because it seems to break `adb reboot`

This reverts commit dc58e730.

Change-Id: Ib8cc4379254694398cbb7f3e7a64c20e1ed8c1ba
parent dc58e730
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -24,11 +24,7 @@ class SocketClient;
class FrameworkListener : public SocketListener {
public:
    static const int CMD_ARGS_MAX = 16;

    /* 1 out of errorRate will be dropped */
    int errorRate;
private:
    int mCommandCount;
    FrameworkCommandCollection *mCommands;

public:
+2 −10
Original line number Diff line number Diff line
@@ -24,9 +24,6 @@ class SocketClient {
    pthread_mutex_t mRefCountMutex;
    int mRefCount;

    pthread_mutex_t mCmdNumMutex;
    int mCmdNum;

public:
    SocketClient(int sock, bool owned);
    virtual ~SocketClient();
@@ -35,11 +32,10 @@ public:
    pid_t getPid() const { return mPid; }
    uid_t getUid() const { return mUid; }
    gid_t getGid() const { return mGid; }
    void setCmdNum(int cmdNum);
    int getCmdNum();

    // Send null-terminated C strings:
    int sendMsg(int code, const char *msg, bool addErrno);
    int sendMsg(const char *msg);

    // Sending binary data:
    int sendData(const void *data, int len);
@@ -50,10 +46,6 @@ public:
    // decRef() when it's done with the client.
    void incRef();
    bool decRef(); // returns true at 0 (but note: SocketClient already deleted)

private:
    // Send null-terminated C strings
    int sendMsg(const char *msg);
};

typedef android::List<SocketClient *> SocketClientCollection;
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public:
    int stopListener();

    void sendBroadcast(int code, const char *msg, bool addErrno);
    void sendBroadcast(const char *msg);

protected:
    virtual bool onDataAvailable(SocketClient *c) = 0;
+3 −17
Original line number Diff line number Diff line
@@ -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);
            }
            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;

+4 −21
Original line number Diff line number Diff line
@@ -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;
}
Loading