diff options
author | Yabin Cui <yabinc@google.com> | 2015-09-15 16:27:09 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2015-09-16 15:00:59 -0700 |
commit | c1b1f6ff5de82b457923eea3f0bbad1ac2e459d7 (patch) | |
tree | cd1845dd60311ff07e9eadad5a9833f7a9a0a0c8 /adb/sockets.cpp | |
parent | fa965d9639dc264bb0d18e71dff998a4f648b50d (diff) | |
download | system_core-c1b1f6ff5de82b457923eea3f0bbad1ac2e459d7.tar.gz system_core-c1b1f6ff5de82b457923eea3f0bbad1ac2e459d7.tar.bz2 system_core-c1b1f6ff5de82b457923eea3f0bbad1ac2e459d7.zip |
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
Diffstat (limited to 'adb/sockets.cpp')
-rw-r--r-- | adb/sockets.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/adb/sockets.cpp b/adb/sockets.cpp index 104ad6b12..bd33d79bc 100644 --- a/adb/sockets.cpp +++ b/adb/sockets.cpp @@ -157,6 +157,8 @@ static int local_socket_enqueue(asocket *s, apacket *p) } 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 @@ static void local_socket_close_locked(asocket *s) /* 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 @@ static void local_socket_close_locked(asocket *s) 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 @@ static void local_socket_event_func(int fd, unsigned ev, void* _s) } 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 @@ static void local_socket_event_func(int fd, unsigned ev, void* _s) 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 @@ static void local_socket_event_func(int fd, unsigned ev, void* _s) ** bytes of readable data. */ D("LS(%d): FDE_ERROR (fd=%d)", s->id, s->fd); - return; } } |