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

Commit d0fa13e5 authored by Josh Gao's avatar Josh Gao
Browse files

adb: switch connect_to_remote to string_view.

Test: test_adb.py
Test: test_device.py
Test: $ANDROID_HOST_OUT/nativetest64/adb_test/adb_test
Test: adb shell /data/nativetest64/adbd_test/adbd_test
Change-Id: Icce121a4c62bf0fa636a35bcae31d057cdff8fd2
parent bd767209
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ static void listener_event_func(int _fd, unsigned ev, void* _l)
        s = create_local_socket(fd);
        if (s) {
            s->transport = listener->transport;
            connect_to_remote(s, listener->connect_to.c_str());
            connect_to_remote(s, listener->connect_to);
            return;
        }

+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ asocket *create_local_socket(int fd);
asocket* create_local_service_socket(std::string_view destination, atransport* transport);

asocket *create_remote_socket(unsigned id, atransport *t);
void connect_to_remote(asocket *s, const char *destination);
void connect_to_remote(asocket* s, std::string_view destination);
void connect_to_smartsocket(asocket *s);

// Internal functions that are only made available here for testing purposes.
+8 −5
Original line number Diff line number Diff line
@@ -462,16 +462,19 @@ asocket* create_remote_socket(unsigned id, atransport* t) {
    return s;
}

void connect_to_remote(asocket* s, const char* destination) {
void connect_to_remote(asocket* s, std::string_view destination) {
    D("Connect_to_remote call RS(%d) fd=%d", s->id, s->fd);
    apacket* p = get_apacket();

    D("LS(%d): connect('%s')", s->id, destination);
    LOG(VERBOSE) << "LS(" << s->id << ": connect(" << destination << ")";
    p->msg.command = A_OPEN;
    p->msg.arg0 = s->id;

    // adbd expects a null-terminated string.
    p->payload.assign(destination, destination + strlen(destination) + 1);
    // adbd used to expect a null-terminated string.
    // Keep doing so to maintain backward compatibility.
    p->payload.resize(destination.size() + 1);
    memcpy(p->payload.data(), destination.data(), destination.size());
    p->payload[destination.size()] = '\0';
    p->msg.data_length = p->payload.size();

    CHECK_LE(p->msg.data_length, s->get_max_payload());
@@ -826,7 +829,7 @@ static int smart_socket_enqueue(asocket* s, apacket::payload_type data) {
    /* give him our transport and upref it */
    s->peer->transport = s->transport;

    connect_to_remote(s->peer, s->smart_socket_data.data() + 4);
    connect_to_remote(s->peer, std::string_view(s->smart_socket_data).substr(4));
    s->peer = nullptr;
    s->close(s);
    return 1;