Loading adb/adb.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -474,13 +474,14 @@ void handle_packet(apacket *p, atransport *t) asocket* s = find_local_socket(p->msg.arg1, p->msg.arg0); if (s) { unsigned rid = p->msg.arg0; p->len = p->msg.data_length; if (s->enqueue(s, p) == 0) { // TODO: Convert apacket::data to a type that we can move out of. std::string copy(p->data, p->data + p->msg.data_length); if (s->enqueue(s, std::move(copy)) == 0) { D("Enqueue the socket"); send_ready(s->id, rid, t); } return; } } break; Loading adb/adb.h +0 −5 Original line number Diff line number Diff line Loading @@ -73,11 +73,6 @@ struct amessage { }; struct apacket { apacket* next; size_t len; char* ptr; amessage msg; char data[MAX_PAYLOAD]; }; Loading adb/jdwp_service.cpp +15 −17 Original line number Diff line number Diff line Loading @@ -470,10 +470,9 @@ static void jdwp_socket_close(asocket* s) { free(s); } static int jdwp_socket_enqueue(asocket* s, apacket* p) { static int jdwp_socket_enqueue(asocket* s, std::string) { /* you can't write to this asocket */ D("LS(%d): JDWP socket received data?", s->id); put_apacket(p); s->peer->close(s->peer); return -1; } Loading @@ -486,9 +485,11 @@ static void jdwp_socket_ready(asocket* s) { * on the second one, close the connection */ if (!jdwp->pass) { apacket* p = get_apacket(); p->len = jdwp_process_list((char*)p->data, s->get_max_payload()); peer->enqueue(peer, p); std::string data; data.resize(s->get_max_payload()); size_t len = jdwp_process_list(&data[0], data.size()); data.resize(len); peer->enqueue(peer, std::move(data)); jdwp->pass = true; } else { peer->close(peer); Loading Loading @@ -524,17 +525,14 @@ struct JdwpTracker : public asocket { static std::vector<std::unique_ptr<JdwpTracker>> _jdwp_trackers; static void jdwp_process_list_updated(void) { char buffer[1024]; int len = jdwp_process_list_msg(buffer, sizeof(buffer)); std::string data; data.resize(1024); data.resize(jdwp_process_list_msg(&data[0], data.size())); for (auto& t : _jdwp_trackers) { apacket* p = get_apacket(); memcpy(p->data, buffer, len); p->len = len; if (t->peer) { // The tracker might not have been connected yet. t->peer->enqueue(t->peer, p); t->peer->enqueue(t->peer, data); } } } Loading @@ -560,17 +558,17 @@ static void jdwp_tracker_ready(asocket* s) { JdwpTracker* t = (JdwpTracker*)s; if (t->need_initial) { apacket* p = get_apacket(); std::string data; data.resize(s->get_max_payload()); data.resize(jdwp_process_list_msg(&data[0], data.size())); t->need_initial = false; p->len = jdwp_process_list_msg((char*)p->data, s->get_max_payload()); s->peer->enqueue(s->peer, p); s->peer->enqueue(s->peer, std::move(data)); } } static int jdwp_tracker_enqueue(asocket* s, apacket* p) { static int jdwp_tracker_enqueue(asocket* s, std::string) { /* you can't write to this socket */ D("LS(%d): JDWP tracker received data?", s->id); put_apacket(p); s->peer->close(s->peer); return -1; } Loading adb/range.h 0 → 100644 +65 −0 Original line number Diff line number Diff line #pragma once /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <string> #include <android-base/logging.h> struct Range { explicit Range(std::string data) : data_(std::move(data)) {} Range(const Range& copy) = delete; Range& operator=(const Range& copy) = delete; Range(Range&& move) = default; Range& operator=(Range&& move) = default; bool empty() const { return size() == 0; } size_t size() const { return data_.size() - begin_offset_ - end_offset_; }; void drop_front(size_t n) { CHECK_GE(size(), n); begin_offset_ += n; } void drop_end(size_t n) { CHECK_GE(size(), n); end_offset_ += n; } char* data() { return &data_[0] + begin_offset_; } std::string::iterator begin() { return data_.begin() + begin_offset_; } std::string::iterator end() { return data_.end() - end_offset_; } std::string data_; size_t begin_offset_ = 0; size_t end_offset_ = 0; }; adb/socket.h +8 −4 Original line number Diff line number Diff line Loading @@ -19,9 +19,12 @@ #include <stddef.h> #include <deque> #include <memory> #include <string> #include "fdevent.h" #include "range.h" struct apacket; class atransport; Loading Loading @@ -59,9 +62,10 @@ struct asocket { fdevent fde; int fd; // queue of apackets waiting to be written apacket* pkt_first; apacket* pkt_last; // queue of data waiting to be written std::deque<Range> packet_queue; std::string smart_socket_data; /* enqueue is called by our peer when it has data * for us. It should return 0 if we can accept more Loading @@ -69,7 +73,7 @@ struct asocket { * peer->ready() when we once again are ready to * receive data. */ int (*enqueue)(asocket* s, apacket* pkt); int (*enqueue)(asocket* s, std::string data); /* ready is called by the peer when it is ready for * us to send data via enqueue again Loading Loading
adb/adb.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -474,13 +474,14 @@ void handle_packet(apacket *p, atransport *t) asocket* s = find_local_socket(p->msg.arg1, p->msg.arg0); if (s) { unsigned rid = p->msg.arg0; p->len = p->msg.data_length; if (s->enqueue(s, p) == 0) { // TODO: Convert apacket::data to a type that we can move out of. std::string copy(p->data, p->data + p->msg.data_length); if (s->enqueue(s, std::move(copy)) == 0) { D("Enqueue the socket"); send_ready(s->id, rid, t); } return; } } break; Loading
adb/adb.h +0 −5 Original line number Diff line number Diff line Loading @@ -73,11 +73,6 @@ struct amessage { }; struct apacket { apacket* next; size_t len; char* ptr; amessage msg; char data[MAX_PAYLOAD]; }; Loading
adb/jdwp_service.cpp +15 −17 Original line number Diff line number Diff line Loading @@ -470,10 +470,9 @@ static void jdwp_socket_close(asocket* s) { free(s); } static int jdwp_socket_enqueue(asocket* s, apacket* p) { static int jdwp_socket_enqueue(asocket* s, std::string) { /* you can't write to this asocket */ D("LS(%d): JDWP socket received data?", s->id); put_apacket(p); s->peer->close(s->peer); return -1; } Loading @@ -486,9 +485,11 @@ static void jdwp_socket_ready(asocket* s) { * on the second one, close the connection */ if (!jdwp->pass) { apacket* p = get_apacket(); p->len = jdwp_process_list((char*)p->data, s->get_max_payload()); peer->enqueue(peer, p); std::string data; data.resize(s->get_max_payload()); size_t len = jdwp_process_list(&data[0], data.size()); data.resize(len); peer->enqueue(peer, std::move(data)); jdwp->pass = true; } else { peer->close(peer); Loading Loading @@ -524,17 +525,14 @@ struct JdwpTracker : public asocket { static std::vector<std::unique_ptr<JdwpTracker>> _jdwp_trackers; static void jdwp_process_list_updated(void) { char buffer[1024]; int len = jdwp_process_list_msg(buffer, sizeof(buffer)); std::string data; data.resize(1024); data.resize(jdwp_process_list_msg(&data[0], data.size())); for (auto& t : _jdwp_trackers) { apacket* p = get_apacket(); memcpy(p->data, buffer, len); p->len = len; if (t->peer) { // The tracker might not have been connected yet. t->peer->enqueue(t->peer, p); t->peer->enqueue(t->peer, data); } } } Loading @@ -560,17 +558,17 @@ static void jdwp_tracker_ready(asocket* s) { JdwpTracker* t = (JdwpTracker*)s; if (t->need_initial) { apacket* p = get_apacket(); std::string data; data.resize(s->get_max_payload()); data.resize(jdwp_process_list_msg(&data[0], data.size())); t->need_initial = false; p->len = jdwp_process_list_msg((char*)p->data, s->get_max_payload()); s->peer->enqueue(s->peer, p); s->peer->enqueue(s->peer, std::move(data)); } } static int jdwp_tracker_enqueue(asocket* s, apacket* p) { static int jdwp_tracker_enqueue(asocket* s, std::string) { /* you can't write to this socket */ D("LS(%d): JDWP tracker received data?", s->id); put_apacket(p); s->peer->close(s->peer); return -1; } Loading
adb/range.h 0 → 100644 +65 −0 Original line number Diff line number Diff line #pragma once /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <string> #include <android-base/logging.h> struct Range { explicit Range(std::string data) : data_(std::move(data)) {} Range(const Range& copy) = delete; Range& operator=(const Range& copy) = delete; Range(Range&& move) = default; Range& operator=(Range&& move) = default; bool empty() const { return size() == 0; } size_t size() const { return data_.size() - begin_offset_ - end_offset_; }; void drop_front(size_t n) { CHECK_GE(size(), n); begin_offset_ += n; } void drop_end(size_t n) { CHECK_GE(size(), n); end_offset_ += n; } char* data() { return &data_[0] + begin_offset_; } std::string::iterator begin() { return data_.begin() + begin_offset_; } std::string::iterator end() { return data_.end() - end_offset_; } std::string data_; size_t begin_offset_ = 0; size_t end_offset_ = 0; };
adb/socket.h +8 −4 Original line number Diff line number Diff line Loading @@ -19,9 +19,12 @@ #include <stddef.h> #include <deque> #include <memory> #include <string> #include "fdevent.h" #include "range.h" struct apacket; class atransport; Loading Loading @@ -59,9 +62,10 @@ struct asocket { fdevent fde; int fd; // queue of apackets waiting to be written apacket* pkt_first; apacket* pkt_last; // queue of data waiting to be written std::deque<Range> packet_queue; std::string smart_socket_data; /* enqueue is called by our peer when it has data * for us. It should return 0 if we can accept more Loading @@ -69,7 +73,7 @@ struct asocket { * peer->ready() when we once again are ready to * receive data. */ int (*enqueue)(asocket* s, apacket* pkt); int (*enqueue)(asocket* s, std::string data); /* ready is called by the peer when it is ready for * us to send data via enqueue again Loading