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

Commit d9f8cef5 authored by Yifan Hong's avatar Yifan Hong
Browse files

binder: RpcSession handle post-connect

On non-blocking sockets, connect() may return EAGAIN / EINPROGRESS.
Handle them properly.

Bug: 195683291
Test: binderRpcTest

Change-Id: Ia98386e41187cb48c528913dd8fd8ab566ec3506
parent b675ffe4
Loading
Loading
Loading
Loading
+28 −4
Original line number Diff line number Diff line
@@ -489,11 +489,35 @@ status_t RpcSession::setupOneSocketConnection(const RpcSocketAddress& addr,
                ALOGW("Connection reset on %s", addr.toString().c_str());
                continue;
            }
            if (errno != EAGAIN && errno != EINPROGRESS) {
                int savedErrno = errno;
                ALOGE("Could not connect socket at %s: %s", addr.toString().c_str(),
                      strerror(savedErrno));
                return -savedErrno;
            }
            // For non-blocking sockets, connect() may return EAGAIN (for unix domain socket) or
            // EINPROGRESS (for others). Call poll() and getsockopt() to get the error.
            status_t pollStatus = mShutdownTrigger->triggerablePoll(serverFd, POLLOUT);
            if (pollStatus != OK) {
                ALOGE("Could not POLLOUT after connect() on non-blocking socket: %s",
                      statusToString(pollStatus).c_str());
                return pollStatus;
            }
            int soError;
            socklen_t soErrorLen = sizeof(soError);
            int ret = getsockopt(serverFd.get(), SOL_SOCKET, SO_ERROR, &soError, &soErrorLen);
            if (ret == -1) {
                int savedErrno = errno;
                ALOGE("Could not getsockopt() after connect() on non-blocking socket: %s",
                      strerror(savedErrno));
                return -savedErrno;
            }
            if (soError != 0) {
                ALOGE("After connect(), getsockopt() returns error for socket at %s: %s",
                      addr.toString().c_str(), strerror(soError));
                return -soError;
            }
        }
        LOG_RPC_DETAIL("Socket at %s client with fd %d", addr.toString().c_str(), serverFd.get());

        return initAndAddConnection(std::move(serverFd), sessionId, incoming);