Add unit tests for local socket.
Add has_write_error flag in asocket, so it will not wait on local_socket_closing_list
to write pending packets in local_socket_close(). Although it doesn't fix any problem,
it helps to make the code more stable.
Add a missing put_apacket() in error handling.
Add a check when adding local socket in local_socket_closing_list.
Bug: 23314034
Change-Id: I75b07ba8ee59b7f277fba2fb919db63065b291be
diff --git a/adb/sockets.cpp b/adb/sockets.cpp
index 104ad6b..bd33d79 100644
--- a/adb/sockets.cpp
+++ b/adb/sockets.cpp
@@ -157,6 +157,8 @@
}
if((r == 0) || (errno != EAGAIN)) {
D( "LS(%d): not ready, errno=%d: %s", s->id, errno, strerror(errno) );
+ put_apacket(p);
+ s->has_write_error = true;
s->close(s);
return 1; /* not ready (error) */
} else {
@@ -252,7 +254,7 @@
/* If we are already closing, or if there are no
** pending packets, destroy immediately
*/
- if (s->closing || s->pkt_first == NULL) {
+ if (s->closing || s->has_write_error || s->pkt_first == NULL) {
int id = s->id;
local_socket_destroy(s);
D("LS(%d): closed", id);
@@ -267,6 +269,7 @@
remove_socket(s);
D("LS(%d): put on socket_closing_list fd=%d", s->id, s->fd);
insert_local_socket(s, &local_socket_closing_list);
+ CHECK_EQ(FDE_WRITE, s->fde.state & FDE_WRITE);
}
static void local_socket_event_func(int fd, unsigned ev, void* _s)
@@ -296,6 +299,7 @@
}
D(" closing after write because r=%d and errno is %d", r, errno);
+ s->has_write_error = true;
s->close(s);
return;
}
@@ -392,6 +396,7 @@
D(" closing because is_eof=%d r=%d s->fde.force_eof=%d",
is_eof, r, s->fde.force_eof);
s->close(s);
+ return;
}
}
@@ -401,7 +406,6 @@
** bytes of readable data.
*/
D("LS(%d): FDE_ERROR (fd=%d)", s->id, s->fd);
-
return;
}
}