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

Commit 218c4070 authored by Yifan Hong's avatar Yifan Hong
Browse files

binder: RpcTransport: change to size_t.

- Change return type to Result<size_t> because negative numbers
  (-1) are converted to an Error().
- Change size argument from int to size_t because size_t is unsigned
  and is the best type to represent a "size".

Test: pass
Bug: 190868302
Fixes: 195592175
Change-Id: Ide26d2d5cc11a9b776fc3dc0a2281300f611b327
parent 5bff7428
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -601,7 +601,7 @@ status_t RpcState::getAndExecuteCommand(const sp<RpcSession::RpcConnection>& con
status_t RpcState::drainCommands(const sp<RpcSession::RpcConnection>& connection,
status_t RpcState::drainCommands(const sp<RpcSession::RpcConnection>& connection,
                                 const sp<RpcSession>& session, CommandType type) {
                                 const sp<RpcSession>& session, CommandType type) {
    uint8_t buf;
    uint8_t buf;
    while (connection->rpcTransport->peek(&buf, sizeof(buf)).value_or(-1) > 0) {
    while (connection->rpcTransport->peek(&buf, sizeof(buf)).value_or(0) > 0) {
        status_t status = getAndExecuteCommand(connection, session, type);
        status_t status = getAndExecuteCommand(connection, session, type);
        if (status != OK) return status;
        if (status != OK) return status;
    }
    }
+3 −3
Original line number Original line Diff line number Diff line
@@ -32,21 +32,21 @@ namespace {
class RpcTransportRaw : public RpcTransport {
class RpcTransportRaw : public RpcTransport {
public:
public:
    explicit RpcTransportRaw(android::base::unique_fd socket) : mSocket(std::move(socket)) {}
    explicit RpcTransportRaw(android::base::unique_fd socket) : mSocket(std::move(socket)) {}
    Result<ssize_t> send(const void *buf, int size) override {
    Result<size_t> send(const void *buf, size_t size) override {
        ssize_t ret = TEMP_FAILURE_RETRY(::send(mSocket.get(), buf, size, MSG_NOSIGNAL));
        ssize_t ret = TEMP_FAILURE_RETRY(::send(mSocket.get(), buf, size, MSG_NOSIGNAL));
        if (ret < 0) {
        if (ret < 0) {
            return ErrnoError() << "send()";
            return ErrnoError() << "send()";
        }
        }
        return ret;
        return ret;
    }
    }
    Result<ssize_t> recv(void *buf, int size) override {
    Result<size_t> recv(void *buf, size_t size) override {
        ssize_t ret = TEMP_FAILURE_RETRY(::recv(mSocket.get(), buf, size, MSG_NOSIGNAL));
        ssize_t ret = TEMP_FAILURE_RETRY(::recv(mSocket.get(), buf, size, MSG_NOSIGNAL));
        if (ret < 0) {
        if (ret < 0) {
            return ErrnoError() << "recv()";
            return ErrnoError() << "recv()";
        }
        }
        return ret;
        return ret;
    }
    }
    Result<ssize_t> peek(void *buf, int size) override {
    Result<size_t> peek(void *buf, size_t size) override {
        ssize_t ret = TEMP_FAILURE_RETRY(::recv(mSocket.get(), buf, size, MSG_PEEK | MSG_DONTWAIT));
        ssize_t ret = TEMP_FAILURE_RETRY(::recv(mSocket.get(), buf, size, MSG_PEEK | MSG_DONTWAIT));
        if (ret < 0) {
        if (ret < 0) {
            return ErrnoError() << "recv(MSG_PEEK)";
            return ErrnoError() << "recv(MSG_PEEK)";
+3 −3
Original line number Original line Diff line number Diff line
@@ -32,10 +32,10 @@ public:
    virtual ~RpcTransport() = default;
    virtual ~RpcTransport() = default;


    // replacement of ::send(). errno may not be set if TLS is enabled.
    // replacement of ::send(). errno may not be set if TLS is enabled.
    virtual android::base::Result<ssize_t> send(const void *buf, int size) = 0;
    virtual android::base::Result<size_t> send(const void *buf, size_t size) = 0;


    // replacement of ::recv(). errno may not be set if TLS is enabled.
    // replacement of ::recv(). errno may not be set if TLS is enabled.
    virtual android::base::Result<ssize_t> recv(void *buf, int size) = 0;
    virtual android::base::Result<size_t> recv(void *buf, size_t size) = 0;


    // replacement of ::recv(MSG_PEEK). errno may not be set if TLS is enabled.
    // replacement of ::recv(MSG_PEEK). errno may not be set if TLS is enabled.
    //
    //
@@ -44,7 +44,7 @@ public:
    // into an internal buffer in userspace. After that, pending() == true.
    // into an internal buffer in userspace. After that, pending() == true.
    // - For raw sockets, this calls ::recv(MSG_PEEK), which leaves the data in the kernel buffer;
    // - For raw sockets, this calls ::recv(MSG_PEEK), which leaves the data in the kernel buffer;
    // pending() is always false.
    // pending() is always false.
    virtual android::base::Result<ssize_t> peek(void *buf, int size) = 0;
    virtual android::base::Result<size_t> peek(void *buf, size_t size) = 0;


    // Returns true if there are data pending in a userspace buffer that RpcTransport holds.
    // Returns true if there are data pending in a userspace buffer that RpcTransport holds.
    //
    //