Loading adb/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -74,9 +74,11 @@ LIBADB_windows_SRC_FILES := \ LIBADB_TEST_linux_SRCS := \ fdevent_test.cpp \ socket_test.cpp \ LIBADB_TEST_darwin_SRCS := \ fdevent_test.cpp \ socket_test.cpp \ LIBADB_TEST_windows_SRCS := \ sysdeps_win32_test.cpp \ Loading adb/adb.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -162,6 +162,9 @@ std::string get_trace_setting() { // adbd's comes from the system property persist.adb.trace_mask. static void setup_trace_mask() { const std::string trace_setting = get_trace_setting(); if (trace_setting.empty()) { return; } std::unordered_map<std::string, int> trace_flags = { {"1", 0}, Loading @@ -184,7 +187,7 @@ static void setup_trace_mask() { for (const auto& elem : elements) { const auto& flag = trace_flags.find(elem); if (flag == trace_flags.end()) { D("Unknown trace flag: %s", flag->first.c_str()); D("Unknown trace flag: %s", elem.c_str()); continue; } Loading adb/adb.h +1 −85 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include "adb_trace.h" #include "fdevent.h" #include "socket.h" constexpr size_t MAX_PAYLOAD_V1 = 4 * 1024; constexpr size_t MAX_PAYLOAD_V2 = 256 * 1024; Loading Loading @@ -74,80 +75,6 @@ struct apacket unsigned char data[MAX_PAYLOAD]; }; /* An asocket represents one half of a connection between a local and ** remote entity. A local asocket is bound to a file descriptor. A ** remote asocket is bound to the protocol engine. */ struct asocket { /* chain pointers for the local/remote list of ** asockets that this asocket lives in */ asocket *next; asocket *prev; /* the unique identifier for this asocket */ unsigned id; /* flag: set when the socket's peer has closed ** but packets are still queued for delivery */ int closing; /* flag: quit adbd when both ends close the ** local service socket */ int exit_on_close; /* the asocket we are connected to */ asocket *peer; /* For local asockets, the fde is used to bind ** us to our fd event system. For remote asockets ** these fields are not used. */ fdevent fde; int fd; /* queue of apackets waiting to be written */ apacket *pkt_first; apacket *pkt_last; /* enqueue is called by our peer when it has data ** for us. It should return 0 if we can accept more ** data or 1 if not. If we return 1, we must call ** peer->ready() when we once again are ready to ** receive data. */ int (*enqueue)(asocket *s, apacket *pkt); /* ready is called by the peer when it is ready for ** us to send data via enqueue again */ void (*ready)(asocket *s); /* shutdown is called by the peer before it goes away. ** the socket should not do any further calls on its peer. ** Always followed by a call to close. Optional, i.e. can be NULL. */ void (*shutdown)(asocket *s); /* close is called by the peer when it has gone away. ** we are not allowed to make any further calls on the ** peer once our close method is called. */ void (*close)(asocket *s); /* A socket is bound to atransport */ atransport *transport; size_t get_max_payload() const; }; /* the adisconnect structure is used to record a callback that ** will be called whenever a transport is disconnected (e.g. by the user) ** this should be used to cleanup objects that depend on the Loading Loading @@ -215,18 +142,7 @@ struct alistener void print_packet(const char *label, apacket *p); asocket *find_local_socket(unsigned local_id, unsigned remote_id); void install_local_socket(asocket *s); void remove_socket(asocket *s); void close_all_sockets(atransport *t); asocket *create_local_socket(int fd); asocket *create_local_service_socket(const char* destination, const atransport* transport); asocket *create_remote_socket(unsigned id, atransport *t); void connect_to_remote(asocket *s, const char *destination); void connect_to_smartsocket(asocket *s); void fatal(const char *fmt, ...) __attribute__((noreturn)); void fatal_errno(const char *fmt, ...) __attribute__((noreturn)); Loading adb/fdevent.cpp +18 −6 Original line number Diff line number Diff line Loading @@ -219,6 +219,9 @@ static void fdevent_process() { return; } for (auto& pollfd : pollfds) { if (pollfd.revents != 0) { D("for fd %d, revents = %x", pollfd.fd, pollfd.revents); } unsigned events = 0; if (pollfd.revents & POLLIN) { events |= FDE_READ; Loading Loading @@ -337,3 +340,12 @@ void fdevent_loop() } } } size_t fdevent_installed_count() { return g_poll_node_map.size(); } void fdevent_reset() { g_poll_node_map.clear(); g_pending_list.clear(); } adb/fdevent.h +19 −15 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef __FDEVENT_H #define __FDEVENT_H #include <stddef.h> #include <stdint.h> /* for int64_t */ /* events that may be observed */ Loading @@ -27,10 +28,22 @@ /* features that may be set (via the events set/add/del interface) */ #define FDE_DONT_CLOSE 0x0080 struct fdevent; typedef void (*fd_func)(int fd, unsigned events, void *userdata); struct fdevent { fdevent *next; fdevent *prev; int fd; int force_eof; uint16_t state; uint16_t events; fd_func func; void *arg; }; /* Allocate and initialize a new fdevent object * Note: use FD_TIMER as 'fd' to create a fd-less object * (used to implement timers). Loading Loading @@ -63,18 +76,9 @@ void fdevent_set_timeout(fdevent *fde, int64_t timeout_ms); */ void fdevent_loop(); struct fdevent { fdevent *next; fdevent *prev; int fd; int force_eof; uint16_t state; uint16_t events; fd_func func; void *arg; }; // For debugging only. size_t fdevent_installed_count(); // For debugging only. void fdevent_reset(); #endif Loading
adb/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -74,9 +74,11 @@ LIBADB_windows_SRC_FILES := \ LIBADB_TEST_linux_SRCS := \ fdevent_test.cpp \ socket_test.cpp \ LIBADB_TEST_darwin_SRCS := \ fdevent_test.cpp \ socket_test.cpp \ LIBADB_TEST_windows_SRCS := \ sysdeps_win32_test.cpp \ Loading
adb/adb.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -162,6 +162,9 @@ std::string get_trace_setting() { // adbd's comes from the system property persist.adb.trace_mask. static void setup_trace_mask() { const std::string trace_setting = get_trace_setting(); if (trace_setting.empty()) { return; } std::unordered_map<std::string, int> trace_flags = { {"1", 0}, Loading @@ -184,7 +187,7 @@ static void setup_trace_mask() { for (const auto& elem : elements) { const auto& flag = trace_flags.find(elem); if (flag == trace_flags.end()) { D("Unknown trace flag: %s", flag->first.c_str()); D("Unknown trace flag: %s", elem.c_str()); continue; } Loading
adb/adb.h +1 −85 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include "adb_trace.h" #include "fdevent.h" #include "socket.h" constexpr size_t MAX_PAYLOAD_V1 = 4 * 1024; constexpr size_t MAX_PAYLOAD_V2 = 256 * 1024; Loading Loading @@ -74,80 +75,6 @@ struct apacket unsigned char data[MAX_PAYLOAD]; }; /* An asocket represents one half of a connection between a local and ** remote entity. A local asocket is bound to a file descriptor. A ** remote asocket is bound to the protocol engine. */ struct asocket { /* chain pointers for the local/remote list of ** asockets that this asocket lives in */ asocket *next; asocket *prev; /* the unique identifier for this asocket */ unsigned id; /* flag: set when the socket's peer has closed ** but packets are still queued for delivery */ int closing; /* flag: quit adbd when both ends close the ** local service socket */ int exit_on_close; /* the asocket we are connected to */ asocket *peer; /* For local asockets, the fde is used to bind ** us to our fd event system. For remote asockets ** these fields are not used. */ fdevent fde; int fd; /* queue of apackets waiting to be written */ apacket *pkt_first; apacket *pkt_last; /* enqueue is called by our peer when it has data ** for us. It should return 0 if we can accept more ** data or 1 if not. If we return 1, we must call ** peer->ready() when we once again are ready to ** receive data. */ int (*enqueue)(asocket *s, apacket *pkt); /* ready is called by the peer when it is ready for ** us to send data via enqueue again */ void (*ready)(asocket *s); /* shutdown is called by the peer before it goes away. ** the socket should not do any further calls on its peer. ** Always followed by a call to close. Optional, i.e. can be NULL. */ void (*shutdown)(asocket *s); /* close is called by the peer when it has gone away. ** we are not allowed to make any further calls on the ** peer once our close method is called. */ void (*close)(asocket *s); /* A socket is bound to atransport */ atransport *transport; size_t get_max_payload() const; }; /* the adisconnect structure is used to record a callback that ** will be called whenever a transport is disconnected (e.g. by the user) ** this should be used to cleanup objects that depend on the Loading Loading @@ -215,18 +142,7 @@ struct alistener void print_packet(const char *label, apacket *p); asocket *find_local_socket(unsigned local_id, unsigned remote_id); void install_local_socket(asocket *s); void remove_socket(asocket *s); void close_all_sockets(atransport *t); asocket *create_local_socket(int fd); asocket *create_local_service_socket(const char* destination, const atransport* transport); asocket *create_remote_socket(unsigned id, atransport *t); void connect_to_remote(asocket *s, const char *destination); void connect_to_smartsocket(asocket *s); void fatal(const char *fmt, ...) __attribute__((noreturn)); void fatal_errno(const char *fmt, ...) __attribute__((noreturn)); Loading
adb/fdevent.cpp +18 −6 Original line number Diff line number Diff line Loading @@ -219,6 +219,9 @@ static void fdevent_process() { return; } for (auto& pollfd : pollfds) { if (pollfd.revents != 0) { D("for fd %d, revents = %x", pollfd.fd, pollfd.revents); } unsigned events = 0; if (pollfd.revents & POLLIN) { events |= FDE_READ; Loading Loading @@ -337,3 +340,12 @@ void fdevent_loop() } } } size_t fdevent_installed_count() { return g_poll_node_map.size(); } void fdevent_reset() { g_poll_node_map.clear(); g_pending_list.clear(); }
adb/fdevent.h +19 −15 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef __FDEVENT_H #define __FDEVENT_H #include <stddef.h> #include <stdint.h> /* for int64_t */ /* events that may be observed */ Loading @@ -27,10 +28,22 @@ /* features that may be set (via the events set/add/del interface) */ #define FDE_DONT_CLOSE 0x0080 struct fdevent; typedef void (*fd_func)(int fd, unsigned events, void *userdata); struct fdevent { fdevent *next; fdevent *prev; int fd; int force_eof; uint16_t state; uint16_t events; fd_func func; void *arg; }; /* Allocate and initialize a new fdevent object * Note: use FD_TIMER as 'fd' to create a fd-less object * (used to implement timers). Loading Loading @@ -63,18 +76,9 @@ void fdevent_set_timeout(fdevent *fde, int64_t timeout_ms); */ void fdevent_loop(); struct fdevent { fdevent *next; fdevent *prev; int fd; int force_eof; uint16_t state; uint16_t events; fd_func func; void *arg; }; // For debugging only. size_t fdevent_installed_count(); // For debugging only. void fdevent_reset(); #endif