summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao2018-05-14 13:14:33 -0500
committerJosh Gao2018-05-22 16:54:49 -0500
commit71f775a9448d483e031767f0a1afb5ef104a36d0 (patch)
tree4ca25d608075c4f24f5a650f8122786a7594eba2
parent2744084981f29726ddccc64220a191002a772a32 (diff)
downloadplatform-system-core-71f775a9448d483e031767f0a1afb5ef104a36d0.tar.gz
platform-system-core-71f775a9448d483e031767f0a1afb5ef104a36d0.tar.xz
platform-system-core-71f775a9448d483e031767f0a1afb5ef104a36d0.zip
adb: remove fdevent_install, fdevent_remove.
Remove fdevent_install and fdevent_remove in favor of using fdevent_create and fdevent_destroy, so that we can put RAII types (i.e. unique_fd) into fdevent without worrying about -Wexit-time-destructors or structs that are freed instead of deleted. Bug: http://b/79786774 Test: python test_device.py Change-Id: I8471cc00574ed492fe1b196944976cdaae8b7cff
-rw-r--r--adb/adb_listeners.cpp10
-rw-r--r--adb/client/transport_mdns.cpp27
-rw-r--r--adb/daemon/auth.cpp18
-rw-r--r--adb/fdevent.cpp38
-rw-r--r--adb/fdevent.h25
-rw-r--r--adb/fdevent_test.cpp30
-rw-r--r--adb/socket.h4
-rw-r--r--adb/sockets.cpp26
-rw-r--r--adb/transport.cpp9
9 files changed, 86 insertions, 101 deletions
diff --git a/adb/adb_listeners.cpp b/adb/adb_listeners.cpp
index fecf452c1..ea5a44e46 100644
--- a/adb/adb_listeners.cpp
+++ b/adb/adb_listeners.cpp
@@ -42,7 +42,7 @@ class alistener {
42 alistener(const std::string& _local_name, const std::string& _connect_to); 42 alistener(const std::string& _local_name, const std::string& _connect_to);
43 ~alistener(); 43 ~alistener();
44 44
45 fdevent fde; 45 fdevent* fde = nullptr;
46 int fd = -1; 46 int fd = -1;
47 47
48 std::string local_name; 48 std::string local_name;
@@ -60,7 +60,7 @@ alistener::alistener(const std::string& _local_name, const std::string& _connect
60 60
61alistener::~alistener() { 61alistener::~alistener() {
62 // Closes the corresponding fd. 62 // Closes the corresponding fd.
63 fdevent_remove(&fde); 63 fdevent_destroy(fde);
64 64
65 if (transport) { 65 if (transport) {
66 transport->RemoveDisconnect(&disconnect); 66 transport->RemoveDisconnect(&disconnect);
@@ -222,11 +222,11 @@ InstallStatus install_listener(const std::string& local_name, const char* connec
222 222
223 close_on_exec(listener->fd); 223 close_on_exec(listener->fd);
224 if (listener->connect_to == "*smartsocket*") { 224 if (listener->connect_to == "*smartsocket*") {
225 fdevent_install(&listener->fde, listener->fd, ss_listener_event_func, listener.get()); 225 listener->fde = fdevent_create(listener->fd, ss_listener_event_func, listener.get());
226 } else { 226 } else {
227 fdevent_install(&listener->fde, listener->fd, listener_event_func, listener.get()); 227 listener->fde = fdevent_create(listener->fd, listener_event_func, listener.get());
228 } 228 }
229 fdevent_set(&listener->fde, FDE_READ); 229 fdevent_set(listener->fde, FDE_READ);
230 230
231 listener->transport = transport; 231 listener->transport = transport;
232 232
diff --git a/adb/client/transport_mdns.cpp b/adb/client/transport_mdns.cpp
index 01f140a98..283fac554 100644
--- a/adb/client/transport_mdns.cpp
+++ b/adb/client/transport_mdns.cpp
@@ -35,7 +35,7 @@
35#include "sysdeps.h" 35#include "sysdeps.h"
36 36
37static DNSServiceRef service_ref; 37static DNSServiceRef service_ref;
38static fdevent service_ref_fde; 38static fdevent* service_ref_fde;
39 39
40// Use adb_DNSServiceRefSockFD() instead of calling DNSServiceRefSockFD() 40// Use adb_DNSServiceRefSockFD() instead of calling DNSServiceRefSockFD()
41// directly so that the socket is put through the appropriate compatibility 41// directly so that the socket is put through the appropriate compatibility
@@ -68,27 +68,26 @@ class AsyncServiceRef {
68 } 68 }
69 69
70 virtual ~AsyncServiceRef() { 70 virtual ~AsyncServiceRef() {
71 if (! initialized_) { 71 if (!initialized_) {
72 return; 72 return;
73 } 73 }
74 74
75 DNSServiceRefDeallocate(sdRef_); 75 DNSServiceRefDeallocate(sdRef_);
76 fdevent_remove(&fde_); 76 fdevent_destroy(fde_);
77 } 77 }
78 78
79 protected: 79 protected:
80 DNSServiceRef sdRef_; 80 DNSServiceRef sdRef_;
81 81
82 void Initialize() { 82 void Initialize() {
83 fdevent_install(&fde_, adb_DNSServiceRefSockFD(sdRef_), 83 fde_ = fdevent_create(adb_DNSServiceRefSockFD(sdRef_), pump_service_ref, &sdRef_);
84 pump_service_ref, &sdRef_); 84 fdevent_set(fde_, FDE_READ);
85 fdevent_set(&fde_, FDE_READ);
86 initialized_ = true; 85 initialized_ = true;
87 } 86 }
88 87
89 private: 88 private:
90 bool initialized_ = false; 89 bool initialized_ = false;
91 fdevent fde_; 90 fdevent* fde_;
92}; 91};
93 92
94class ResolvedService : public AsyncServiceRef { 93class ResolvedService : public AsyncServiceRef {
@@ -252,14 +251,12 @@ static void DNSSD_API register_mdns_transport(DNSServiceRef sdRef,
252 if (errorCode != kDNSServiceErr_NoError) { 251 if (errorCode != kDNSServiceErr_NoError) {
253 D("Got error %d during mDNS browse.", errorCode); 252 D("Got error %d during mDNS browse.", errorCode);
254 DNSServiceRefDeallocate(sdRef); 253 DNSServiceRefDeallocate(sdRef);
255 fdevent_remove(&service_ref_fde); 254 fdevent_destroy(service_ref_fde);
256 return; 255 return;
257 } 256 }
258 257
259 auto discovered = new DiscoveredService(interfaceIndex, serviceName, 258 auto discovered = new DiscoveredService(interfaceIndex, serviceName, regtype, domain);
260 regtype, domain); 259 if (!discovered->Initialized()) {
261
262 if (! discovered->Initialized()) {
263 delete discovered; 260 delete discovered;
264 } 261 }
265} 262}
@@ -274,9 +271,9 @@ void init_mdns_transport_discovery_thread(void) {
274 } 271 }
275 272
276 fdevent_run_on_main_thread([]() { 273 fdevent_run_on_main_thread([]() {
277 fdevent_install(&service_ref_fde, adb_DNSServiceRefSockFD(service_ref), pump_service_ref, 274 service_ref_fde =
278 &service_ref); 275 fdevent_create(adb_DNSServiceRefSockFD(service_ref), pump_service_ref, &service_ref);
279 fdevent_set(&service_ref_fde, FDE_READ); 276 fdevent_set(service_ref_fde, FDE_READ);
280 }); 277 });
281} 278}
282 279
diff --git a/adb/daemon/auth.cpp b/adb/daemon/auth.cpp
index 3fd2b3194..f0c36294b 100644
--- a/adb/daemon/auth.cpp
+++ b/adb/daemon/auth.cpp
@@ -35,8 +35,8 @@
35#include <openssl/rsa.h> 35#include <openssl/rsa.h>
36#include <openssl/sha.h> 36#include <openssl/sha.h>
37 37
38static fdevent listener_fde; 38static fdevent* listener_fde = nullptr;
39static fdevent framework_fde; 39static fdevent* framework_fde = nullptr;
40static int framework_fd = -1; 40static int framework_fd = -1;
41 41
42static void usb_disconnected(void* unused, atransport* t); 42static void usb_disconnected(void* unused, atransport* t);
@@ -106,8 +106,10 @@ static void usb_disconnected(void* unused, atransport* t) {
106 106
107static void framework_disconnected() { 107static void framework_disconnected() {
108 LOG(INFO) << "Framework disconnect"; 108 LOG(INFO) << "Framework disconnect";
109 fdevent_remove(&framework_fde); 109 if (framework_fde) {
110 framework_fd = -1; 110 fdevent_destroy(framework_fde);
111 framework_fd = -1;
112 }
111} 113}
112 114
113static void adbd_auth_event(int fd, unsigned events, void*) { 115static void adbd_auth_event(int fd, unsigned events, void*) {
@@ -168,8 +170,8 @@ static void adbd_auth_listener(int fd, unsigned events, void* data) {
168 } 170 }
169 171
170 framework_fd = s; 172 framework_fd = s;
171 fdevent_install(&framework_fde, framework_fd, adbd_auth_event, nullptr); 173 framework_fde = fdevent_create(framework_fd, adbd_auth_event, nullptr);
172 fdevent_add(&framework_fde, FDE_READ); 174 fdevent_add(framework_fde, FDE_READ);
173 175
174 if (needs_retry) { 176 if (needs_retry) {
175 needs_retry = false; 177 needs_retry = false;
@@ -198,8 +200,8 @@ void adbd_auth_init(void) {
198 return; 200 return;
199 } 201 }
200 202
201 fdevent_install(&listener_fde, fd, adbd_auth_listener, NULL); 203 listener_fde = fdevent_create(fd, adbd_auth_listener, NULL);
202 fdevent_add(&listener_fde, FDE_READ); 204 fdevent_add(listener_fde, FDE_READ);
203} 205}
204 206
205void send_auth_request(atransport* t) { 207void send_auth_request(atransport* t) {
diff --git a/adb/fdevent.cpp b/adb/fdevent.cpp
index cf441cf91..b3ff457ec 100644
--- a/adb/fdevent.cpp
+++ b/adb/fdevent.cpp
@@ -117,29 +117,17 @@ static std::string dump_fde(const fdevent* fde) {
117 return android::base::StringPrintf("(fdevent %d %s)", fde->fd, state.c_str()); 117 return android::base::StringPrintf("(fdevent %d %s)", fde->fd, state.c_str());
118} 118}
119 119
120fdevent* fdevent_create(int fd, fd_func func, void* arg) { 120void fdevent_install(fdevent* fde, int fd, fd_func func, void* arg) {
121 check_main_thread();
122 fdevent *fde = (fdevent*) malloc(sizeof(fdevent));
123 if(fde == 0) return 0;
124 fdevent_install(fde, fd, func, arg);
125 fde->state |= FDE_CREATED;
126 return fde;
127}
128
129void fdevent_destroy(fdevent* fde) {
130 check_main_thread(); 121 check_main_thread();
131 if(fde == 0) return; 122 CHECK_GE(fd, 0);
132 if(!(fde->state & FDE_CREATED)) { 123 memset(fde, 0, sizeof(fdevent));
133 LOG(FATAL) << "destroying fde not created by fdevent_create(): " << dump_fde(fde);
134 }
135 fdevent_remove(fde);
136 free(fde);
137} 124}
138 125
139void fdevent_install(fdevent* fde, int fd, fd_func func, void* arg) { 126fdevent* fdevent_create(int fd, fd_func func, void* arg) {
140 check_main_thread(); 127 check_main_thread();
141 CHECK_GE(fd, 0); 128 CHECK_GE(fd, 0);
142 memset(fde, 0, sizeof(fdevent)); 129
130 fdevent* fde = new fdevent();
143 fde->state = FDE_ACTIVE; 131 fde->state = FDE_ACTIVE;
144 fde->fd = fd; 132 fde->fd = fd;
145 fde->func = func; 133 fde->func = func;
@@ -152,12 +140,18 @@ void fdevent_install(fdevent* fde, int fd, fd_func func, void* arg) {
152 } 140 }
153 auto pair = g_poll_node_map.emplace(fde->fd, PollNode(fde)); 141 auto pair = g_poll_node_map.emplace(fde->fd, PollNode(fde));
154 CHECK(pair.second) << "install existing fd " << fd; 142 CHECK(pair.second) << "install existing fd " << fd;
155 D("fdevent_install %s", dump_fde(fde).c_str()); 143
144 fde->state |= FDE_CREATED;
145 return fde;
156} 146}
157 147
158void fdevent_remove(fdevent* fde) { 148void fdevent_destroy(fdevent* fde) {
159 check_main_thread(); 149 check_main_thread();
160 D("fdevent_remove %s", dump_fde(fde).c_str()); 150 if (fde == 0) return;
151 if (!(fde->state & FDE_CREATED)) {
152 LOG(FATAL) << "destroying fde not created by fdevent_create(): " << dump_fde(fde);
153 }
154
161 if (fde->state & FDE_ACTIVE) { 155 if (fde->state & FDE_ACTIVE) {
162 g_poll_node_map.erase(fde->fd); 156 g_poll_node_map.erase(fde->fd);
163 if (fde->state & FDE_PENDING) { 157 if (fde->state & FDE_PENDING) {
@@ -170,6 +164,8 @@ void fdevent_remove(fdevent* fde) {
170 fde->state = 0; 164 fde->state = 0;
171 fde->events = 0; 165 fde->events = 0;
172 } 166 }
167
168 delete fde;
173} 169}
174 170
175static void fdevent_update(fdevent* fde, unsigned events) { 171static void fdevent_update(fdevent* fde, unsigned events) {
diff --git a/adb/fdevent.h b/adb/fdevent.h
index 896400ad5..2d8efd8db 100644
--- a/adb/fdevent.h
+++ b/adb/fdevent.h
@@ -33,17 +33,17 @@
33typedef void (*fd_func)(int fd, unsigned events, void *userdata); 33typedef void (*fd_func)(int fd, unsigned events, void *userdata);
34 34
35struct fdevent { 35struct fdevent {
36 fdevent *next; 36 fdevent* next = nullptr;
37 fdevent *prev; 37 fdevent* prev = nullptr;
38 38
39 int fd; 39 int fd = -1;
40 int force_eof; 40 int force_eof = 0;
41 41
42 uint16_t state; 42 uint16_t state = 0;
43 uint16_t events; 43 uint16_t events = 0;
44 44
45 fd_func func; 45 fd_func func = nullptr;
46 void *arg; 46 void* arg = nullptr;
47}; 47};
48 48
49/* Allocate and initialize a new fdevent object 49/* Allocate and initialize a new fdevent object
@@ -57,15 +57,6 @@ fdevent *fdevent_create(int fd, fd_func func, void *arg);
57*/ 57*/
58void fdevent_destroy(fdevent *fde); 58void fdevent_destroy(fdevent *fde);
59 59
60/* Initialize an fdevent object that was externally allocated
61*/
62void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg);
63
64/* Uninitialize an fdevent object that was initialized by
65** fdevent_install()
66*/
67void fdevent_remove(fdevent *item);
68
69/* Change which events should cause notifications 60/* Change which events should cause notifications
70*/ 61*/
71void fdevent_set(fdevent *fde, unsigned events); 62void fdevent_set(fdevent *fde, unsigned events);
diff --git a/adb/fdevent_test.cpp b/adb/fdevent_test.cpp
index 2f0ff1805..0cb24390a 100644
--- a/adb/fdevent_test.cpp
+++ b/adb/fdevent_test.cpp
@@ -31,14 +31,14 @@
31class FdHandler { 31class FdHandler {
32 public: 32 public:
33 FdHandler(int read_fd, int write_fd) : read_fd_(read_fd), write_fd_(write_fd) { 33 FdHandler(int read_fd, int write_fd) : read_fd_(read_fd), write_fd_(write_fd) {
34 fdevent_install(&read_fde_, read_fd_, FdEventCallback, this); 34 read_fde_ = fdevent_create(read_fd_, FdEventCallback, this);
35 fdevent_add(&read_fde_, FDE_READ); 35 fdevent_add(read_fde_, FDE_READ);
36 fdevent_install(&write_fde_, write_fd_, FdEventCallback, this); 36 write_fde_ = fdevent_create(write_fd_, FdEventCallback, this);
37 } 37 }
38 38
39 ~FdHandler() { 39 ~FdHandler() {
40 fdevent_remove(&read_fde_); 40 fdevent_destroy(read_fde_);
41 fdevent_remove(&write_fde_); 41 fdevent_destroy(write_fde_);
42 } 42 }
43 43
44 private: 44 private:
@@ -50,7 +50,7 @@ class FdHandler {
50 char c; 50 char c;
51 ASSERT_EQ(1, adb_read(fd, &c, 1)); 51 ASSERT_EQ(1, adb_read(fd, &c, 1));
52 handler->queue_.push(c); 52 handler->queue_.push(c);
53 fdevent_add(&handler->write_fde_, FDE_WRITE); 53 fdevent_add(handler->write_fde_, FDE_WRITE);
54 } 54 }
55 if (events & FDE_WRITE) { 55 if (events & FDE_WRITE) {
56 ASSERT_EQ(fd, handler->write_fd_); 56 ASSERT_EQ(fd, handler->write_fd_);
@@ -59,7 +59,7 @@ class FdHandler {
59 handler->queue_.pop(); 59 handler->queue_.pop();
60 ASSERT_EQ(1, adb_write(fd, &c, 1)); 60 ASSERT_EQ(1, adb_write(fd, &c, 1));
61 if (handler->queue_.empty()) { 61 if (handler->queue_.empty()) {
62 fdevent_del(&handler->write_fde_, FDE_WRITE); 62 fdevent_del(handler->write_fde_, FDE_WRITE);
63 } 63 }
64 } 64 }
65 } 65 }
@@ -67,8 +67,8 @@ class FdHandler {
67 private: 67 private:
68 const int read_fd_; 68 const int read_fd_;
69 const int write_fd_; 69 const int write_fd_;
70 fdevent read_fde_; 70 fdevent* read_fde_;
71 fdevent write_fde_; 71 fdevent* write_fde_;
72 std::queue<char> queue_; 72 std::queue<char> queue_;
73}; 73};
74 74
@@ -137,7 +137,7 @@ TEST_F(FdeventTest, smoke) {
137} 137}
138 138
139struct InvalidFdArg { 139struct InvalidFdArg {
140 fdevent fde; 140 fdevent* fde;
141 unsigned expected_events; 141 unsigned expected_events;
142 size_t* happened_event_count; 142 size_t* happened_event_count;
143}; 143};
@@ -145,7 +145,7 @@ struct InvalidFdArg {
145static void InvalidFdEventCallback(int, unsigned events, void* userdata) { 145static void InvalidFdEventCallback(int, unsigned events, void* userdata) {
146 InvalidFdArg* arg = reinterpret_cast<InvalidFdArg*>(userdata); 146 InvalidFdArg* arg = reinterpret_cast<InvalidFdArg*>(userdata);
147 ASSERT_EQ(arg->expected_events, events); 147 ASSERT_EQ(arg->expected_events, events);
148 fdevent_remove(&arg->fde); 148 fdevent_destroy(arg->fde);
149 if (++*(arg->happened_event_count) == 2) { 149 if (++*(arg->happened_event_count) == 2) {
150 fdevent_terminate_loop(); 150 fdevent_terminate_loop();
151 } 151 }
@@ -157,15 +157,15 @@ static void InvalidFdThreadFunc() {
157 InvalidFdArg read_arg; 157 InvalidFdArg read_arg;
158 read_arg.expected_events = FDE_READ | FDE_ERROR; 158 read_arg.expected_events = FDE_READ | FDE_ERROR;
159 read_arg.happened_event_count = &happened_event_count; 159 read_arg.happened_event_count = &happened_event_count;
160 fdevent_install(&read_arg.fde, INVALID_READ_FD, InvalidFdEventCallback, &read_arg); 160 read_arg.fde = fdevent_create(INVALID_READ_FD, InvalidFdEventCallback, &read_arg);
161 fdevent_add(&read_arg.fde, FDE_READ); 161 fdevent_add(read_arg.fde, FDE_READ);
162 162
163 const int INVALID_WRITE_FD = std::numeric_limits<int>::max(); 163 const int INVALID_WRITE_FD = std::numeric_limits<int>::max();
164 InvalidFdArg write_arg; 164 InvalidFdArg write_arg;
165 write_arg.expected_events = FDE_READ | FDE_ERROR; 165 write_arg.expected_events = FDE_READ | FDE_ERROR;
166 write_arg.happened_event_count = &happened_event_count; 166 write_arg.happened_event_count = &happened_event_count;
167 fdevent_install(&write_arg.fde, INVALID_WRITE_FD, InvalidFdEventCallback, &write_arg); 167 write_arg.fde = fdevent_create(INVALID_WRITE_FD, InvalidFdEventCallback, &write_arg);
168 fdevent_add(&write_arg.fde, FDE_WRITE); 168 fdevent_add(write_arg.fde, FDE_WRITE);
169 fdevent_loop(); 169 fdevent_loop();
170} 170}
171 171
diff --git a/adb/socket.h b/adb/socket.h
index e0fd87f19..27e5b0534 100644
--- a/adb/socket.h
+++ b/adb/socket.h
@@ -58,8 +58,8 @@ struct asocket {
58 * us to our fd event system. For remote asockets 58 * us to our fd event system. For remote asockets
59 * these fields are not used. 59 * these fields are not used.
60 */ 60 */
61 fdevent fde = {}; 61 fdevent* fde = nullptr;
62 int fd = 0; 62 int fd = -1;
63 63
64 // queue of data waiting to be written 64 // queue of data waiting to be written
65 std::deque<Range> packet_queue; 65 std::deque<Range> packet_queue;
diff --git a/adb/sockets.cpp b/adb/sockets.cpp
index 7bc0165b0..4f4fbfbaa 100644
--- a/adb/sockets.cpp
+++ b/adb/sockets.cpp
@@ -121,10 +121,10 @@ static SocketFlushResult local_socket_flush_incoming(asocket* s) {
121 s->packet_queue.pop_front(); 121 s->packet_queue.pop_front();
122 } else if (rc > 0) { 122 } else if (rc > 0) {
123 r.drop_front(rc); 123 r.drop_front(rc);
124 fdevent_add(&s->fde, FDE_WRITE); 124 fdevent_add(s->fde, FDE_WRITE);
125 return SocketFlushResult::TryAgain; 125 return SocketFlushResult::TryAgain;
126 } else if (rc == -1 && errno == EAGAIN) { 126 } else if (rc == -1 && errno == EAGAIN) {
127 fdevent_add(&s->fde, FDE_WRITE); 127 fdevent_add(s->fde, FDE_WRITE);
128 return SocketFlushResult::TryAgain; 128 return SocketFlushResult::TryAgain;
129 } else { 129 } else {
130 // We failed to write, but it's possible that we can still read from the socket. 130 // We failed to write, but it's possible that we can still read from the socket.
@@ -140,7 +140,7 @@ static SocketFlushResult local_socket_flush_incoming(asocket* s) {
140 return SocketFlushResult::Destroyed; 140 return SocketFlushResult::Destroyed;
141 } 141 }
142 142
143 fdevent_del(&s->fde, FDE_WRITE); 143 fdevent_del(s->fde, FDE_WRITE);
144 return SocketFlushResult::Completed; 144 return SocketFlushResult::Completed;
145} 145}
146 146
@@ -173,7 +173,7 @@ static bool local_socket_flush_outgoing(asocket* s) {
173 break; 173 break;
174 } 174 }
175 D("LS(%d): fd=%d post avail loop. r=%d is_eof=%d forced_eof=%d", s->id, s->fd, r, is_eof, 175 D("LS(%d): fd=%d post avail loop. r=%d is_eof=%d forced_eof=%d", s->id, s->fd, r, is_eof,
176 s->fde.force_eof); 176 s->fde->force_eof);
177 177
178 if (avail != max_payload && s->peer) { 178 if (avail != max_payload && s->peer) {
179 data.resize(max_payload - avail); 179 data.resize(max_payload - avail);
@@ -200,13 +200,13 @@ static bool local_socket_flush_outgoing(asocket* s) {
200 ** we disable notification of READs. They'll 200 ** we disable notification of READs. They'll
201 ** be enabled again when we get a call to ready() 201 ** be enabled again when we get a call to ready()
202 */ 202 */
203 fdevent_del(&s->fde, FDE_READ); 203 fdevent_del(s->fde, FDE_READ);
204 } 204 }
205 } 205 }
206 206
207 // Don't allow a forced eof if data is still there. 207 // Don't allow a forced eof if data is still there.
208 if ((s->fde.force_eof && !r) || is_eof) { 208 if ((s->fde->force_eof && !r) || is_eof) {
209 D(" closing because is_eof=%d r=%d s->fde.force_eof=%d", is_eof, r, s->fde.force_eof); 209 D(" closing because is_eof=%d r=%d s->fde.force_eof=%d", is_eof, r, s->fde->force_eof);
210 s->close(s); 210 s->close(s);
211 return false; 211 return false;
212 } 212 }
@@ -236,19 +236,19 @@ static int local_socket_enqueue(asocket* s, apacket::payload_type data) {
236static void local_socket_ready(asocket* s) { 236static void local_socket_ready(asocket* s) {
237 /* far side is ready for data, pay attention to 237 /* far side is ready for data, pay attention to
238 readable events */ 238 readable events */
239 fdevent_add(&s->fde, FDE_READ); 239 fdevent_add(s->fde, FDE_READ);
240} 240}
241 241
242// be sure to hold the socket list lock when calling this 242// be sure to hold the socket list lock when calling this
243static void local_socket_destroy(asocket* s) { 243static void local_socket_destroy(asocket* s) {
244 int exit_on_close = s->exit_on_close; 244 int exit_on_close = s->exit_on_close;
245 245
246 D("LS(%d): destroying fde.fd=%d", s->id, s->fde.fd); 246 D("LS(%d): destroying fde.fd=%d", s->id, s->fd);
247 247
248 /* IMPORTANT: the remove closes the fd 248 /* IMPORTANT: the remove closes the fd
249 ** that belongs to this socket 249 ** that belongs to this socket
250 */ 250 */
251 fdevent_remove(&s->fde); 251 fdevent_destroy(s->fde);
252 252
253 remove_socket(s); 253 remove_socket(s);
254 delete s; 254 delete s;
@@ -290,11 +290,11 @@ static void local_socket_close(asocket* s) {
290 */ 290 */
291 D("LS(%d): closing", s->id); 291 D("LS(%d): closing", s->id);
292 s->closing = 1; 292 s->closing = 1;
293 fdevent_del(&s->fde, FDE_READ); 293 fdevent_del(s->fde, FDE_READ);
294 remove_socket(s); 294 remove_socket(s);
295 D("LS(%d): put on socket_closing_list fd=%d", s->id, s->fd); 295 D("LS(%d): put on socket_closing_list fd=%d", s->id, s->fd);
296 local_socket_closing_list.push_back(s); 296 local_socket_closing_list.push_back(s);
297 CHECK_EQ(FDE_WRITE, s->fde.state & FDE_WRITE); 297 CHECK_EQ(FDE_WRITE, s->fde->state & FDE_WRITE);
298} 298}
299 299
300static void local_socket_event_func(int fd, unsigned ev, void* _s) { 300static void local_socket_event_func(int fd, unsigned ev, void* _s) {
@@ -343,7 +343,7 @@ asocket* create_local_socket(int fd) {
343 s->close = local_socket_close; 343 s->close = local_socket_close;
344 install_local_socket(s); 344 install_local_socket(s);
345 345
346 fdevent_install(&s->fde, fd, local_socket_event_func, s); 346 s->fde = fdevent_create(fd, local_socket_event_func, s);
347 D("LS(%d): created (fd=%d)", s->id, s->fd); 347 D("LS(%d): created (fd=%d)", s->id, s->fd);
348 return s; 348 return s;
349} 349}
diff --git a/adb/transport.cpp b/adb/transport.cpp
index fa7cc8c69..4c9c90c8d 100644
--- a/adb/transport.cpp
+++ b/adb/transport.cpp
@@ -300,7 +300,7 @@ void kick_transport(atransport* t) {
300 300
301static int transport_registration_send = -1; 301static int transport_registration_send = -1;
302static int transport_registration_recv = -1; 302static int transport_registration_recv = -1;
303static fdevent transport_registration_fde; 303static fdevent* transport_registration_fde;
304 304
305#if ADB_HOST 305#if ADB_HOST
306 306
@@ -565,10 +565,9 @@ void init_transport_registration(void) {
565 transport_registration_send = s[0]; 565 transport_registration_send = s[0];
566 transport_registration_recv = s[1]; 566 transport_registration_recv = s[1];
567 567
568 fdevent_install(&transport_registration_fde, transport_registration_recv, 568 transport_registration_fde =
569 transport_registration_func, 0); 569 fdevent_create(transport_registration_recv, transport_registration_func, 0);
570 570 fdevent_set(transport_registration_fde, FDE_READ);
571 fdevent_set(&transport_registration_fde, FDE_READ);
572} 571}
573 572
574void kick_all_transports() { 573void kick_all_transports() {