system/corennnnn
修訂 | 67340391ebd4f272f9d4696b55e7e555d0950c34 (tree) |
---|---|
時間 | 2016-09-21 14:45:29 |
作者 | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Merge remote-tracking branch 'x86/marshmallow-x86' into cm-13.0-x86
@@ -85,13 +85,6 @@ struct asocket { | ||
85 | 85 | ** but packets are still queued for delivery |
86 | 86 | */ |
87 | 87 | int closing; |
88 | - /* flag: set when this socket is running. | |
89 | - */ | |
90 | - int running; | |
91 | - /* flag: force close this socket. if this socket is running, other | |
92 | - ** thread set this flag to request close it. | |
93 | - */ | |
94 | - int force_close; | |
95 | 88 | |
96 | 89 | /* flag: quit adbd when both ends close the |
97 | 90 | ** local service socket |
@@ -116,12 +116,12 @@ void remove_socket(asocket *s) | ||
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | -// Note: after return, all sockets refer to transport @t should be closed. | |
120 | -// (Because the atransport is going to removed.) | |
121 | -// force_close && running flag are to implement this. | |
122 | 119 | void close_all_sockets(atransport *t) |
123 | 120 | { |
124 | 121 | asocket *s; |
122 | + /* this is a little gross, but since s->close() *will* modify | |
123 | + ** the list out from under you, your options are limited. | |
124 | + */ | |
125 | 125 | std::lock_guard<recursive_mutex> lock(local_socket_list_lock); |
126 | 126 | restart: |
127 | 127 | for (s = local_socket_list.next; s != &local_socket_list; s = s->next) { |
@@ -238,10 +238,9 @@ static void local_socket_close(asocket* s) { | ||
238 | 238 | } |
239 | 239 | |
240 | 240 | /* If we are already closing, or if there are no |
241 | - ** pending packets, or need force close it, then | |
242 | - ** destroy immediately. | |
241 | + ** pending packets, destroy immediately | |
243 | 242 | */ |
244 | - if (s->closing || s->force_close || s->pkt_first == NULL) { | |
243 | + if (s->closing || s->pkt_first == NULL) { | |
245 | 244 | int id = s->id; |
246 | 245 | local_socket_destroy(s); |
247 | 246 | D("LS(%d): closed\n", id); |
@@ -261,12 +260,8 @@ static void local_socket_close(asocket* s) { | ||
261 | 260 | static void local_socket_event_func(int fd, unsigned ev, void* _s) |
262 | 261 | { |
263 | 262 | asocket* s = reinterpret_cast<asocket*>(_s); |
264 | - s->running = 1; | |
265 | 263 | D("LS(%d): event_func(fd=%d(==%d), ev=%04x)\n", s->id, s->fd, fd, ev); |
266 | 264 | |
267 | - if (s->force_close) | |
268 | - goto out; | |
269 | - | |
270 | 265 | /* put the FDE_WRITE processing before the FDE_READ |
271 | 266 | ** in order to simplify the code. |
272 | 267 | */ |
@@ -280,7 +275,7 @@ static void local_socket_event_func(int fd, unsigned ev, void* _s) | ||
280 | 275 | ** be processed in the next iteration loop |
281 | 276 | */ |
282 | 277 | if (errno == EAGAIN) { |
283 | - goto out; | |
278 | + return; | |
284 | 279 | } |
285 | 280 | } else if (r > 0) { |
286 | 281 | p->ptr += r; |
@@ -289,7 +284,6 @@ static void local_socket_event_func(int fd, unsigned ev, void* _s) | ||
289 | 284 | } |
290 | 285 | |
291 | 286 | D(" closing after write because r=%d and errno is %d\n", r, errno); |
292 | - s->running = 0; | |
293 | 287 | s->close(s); |
294 | 288 | return; |
295 | 289 | } |
@@ -308,7 +302,6 @@ static void local_socket_event_func(int fd, unsigned ev, void* _s) | ||
308 | 302 | */ |
309 | 303 | if (s->closing) { |
310 | 304 | D(" closing because 'closing' is set after write\n"); |
311 | - s->running = 0; | |
312 | 305 | s->close(s); |
313 | 306 | return; |
314 | 307 | } |
@@ -367,7 +360,7 @@ static void local_socket_event_func(int fd, unsigned ev, void* _s) | ||
367 | 360 | ** this handler function will be called again |
368 | 361 | ** to process FDE_WRITE events. |
369 | 362 | */ |
370 | - goto out; | |
363 | + return; | |
371 | 364 | } |
372 | 365 | |
373 | 366 | if (r > 0) { |
@@ -382,9 +375,7 @@ static void local_socket_event_func(int fd, unsigned ev, void* _s) | ||
382 | 375 | if ((s->fde.force_eof && !r) || is_eof) { |
383 | 376 | D(" closing because is_eof=%d r=%d s->fde.force_eof=%d\n", |
384 | 377 | is_eof, r, s->fde.force_eof); |
385 | - s->running = 0; | |
386 | 378 | s->close(s); |
387 | - return; | |
388 | 379 | } |
389 | 380 | } |
390 | 381 |
@@ -395,13 +386,7 @@ static void local_socket_event_func(int fd, unsigned ev, void* _s) | ||
395 | 386 | */ |
396 | 387 | D("LS(%d): FDE_ERROR (fd=%d)\n", s->id, s->fd); |
397 | 388 | |
398 | - goto out; | |
399 | - } | |
400 | -out: | |
401 | - s->running = 0; | |
402 | - if (s->force_close) { | |
403 | - D("LS(%d): force closing (fd=%d)\n", s->id, s->fd); | |
404 | - s->close(s); | |
389 | + return; | |
405 | 390 | } |
406 | 391 | } |
407 | 392 |
@@ -409,7 +394,6 @@ asocket *create_local_socket(int fd) | ||
409 | 394 | { |
410 | 395 | asocket *s = reinterpret_cast<asocket*>(calloc(1, sizeof(asocket))); |
411 | 396 | if (s == NULL) fatal("cannot allocate socket"); |
412 | - memset(s, 0, sizeof(asocket)); | |
413 | 397 | s->fd = fd; |
414 | 398 | s->enqueue = local_socket_enqueue; |
415 | 399 | s->ready = local_socket_ready; |
@@ -555,7 +539,6 @@ asocket *create_remote_socket(unsigned id, atransport *t) | ||
555 | 539 | adisconnect* dis = &reinterpret_cast<aremotesocket*>(s)->disconnect; |
556 | 540 | |
557 | 541 | if (s == NULL) fatal("cannot allocate socket"); |
558 | - memset(s, 0, sizeof(asocket)); | |
559 | 542 | s->id = id; |
560 | 543 | s->enqueue = remote_socket_enqueue; |
561 | 544 | s->ready = remote_socket_ready; |
@@ -888,7 +871,6 @@ static asocket *create_smart_socket(void) | ||
888 | 871 | D("Creating smart socket \n"); |
889 | 872 | asocket *s = reinterpret_cast<asocket*>(calloc(1, sizeof(asocket))); |
890 | 873 | if (s == NULL) fatal("cannot allocate socket"); |
891 | - memset(s, 0, sizeof(asocket)); | |
892 | 874 | s->enqueue = smart_socket_enqueue; |
893 | 875 | s->ready = smart_socket_ready; |
894 | 876 | s->shutdown = NULL; |