adb: fix shell_service_protocol_test for Windows.
Adds missing #ifdef guards to shell_service_protocol_test.cpp so the
test compiles on Windows.
Also fixes a bug in Windows socketpair write implementation. Previously
it was only checking for a closed pipe if the write happened to block.
This adds an additional pre-check to exit immediately on a closed pipe.
These two changes allow the test to compile and pass on Windows.
Change-Id: Ib8853ed72f015fc0d623da47c32982cb3ffa4a3d
diff --git a/adb/Android.mk b/adb/Android.mk
index 385b1c5..67c3eb7 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -133,8 +133,6 @@
$(LIBADB_TEST_SRCS) \
$(LIBADB_TEST_linux_SRCS) \
shell_service_protocol.cpp \
-
-LOCAL_SRC_FILES_linux := \
shell_service_protocol_test.cpp \
LOCAL_SANITIZE := $(adb_target_sanitize)
@@ -155,11 +153,9 @@
$(LIBADB_TEST_SRCS) \
services.cpp \
shell_service_protocol.cpp \
-
-LOCAL_SRC_FILES_linux := \
- $(LIBADB_TEST_linux_SRCS) \
shell_service_protocol_test.cpp \
+LOCAL_SRC_FILES_linux := $(LIBADB_TEST_linux_SRCS)
LOCAL_SRC_FILES_darwin := $(LIBADB_TEST_darwin_SRCS)
LOCAL_SRC_FILES_windows := $(LIBADB_TEST_windows_SRCS)
LOCAL_SANITIZE := $(adb_host_sanitize)
diff --git a/adb/shell_service_protocol_test.cpp b/adb/shell_service_protocol_test.cpp
index 85b2f91..a826035 100644
--- a/adb/shell_service_protocol_test.cpp
+++ b/adb/shell_service_protocol_test.cpp
@@ -72,13 +72,17 @@
read_protocol_->buffer_end_ = read_protocol_->data() + size;
}
+#if !defined(_WIN32)
static sig_t saved_sigpipe_handler_;
+#endif
int read_fd_ = -1, write_fd_ = -1;
ShellProtocol *read_protocol_ = nullptr, *write_protocol_ = nullptr;
};
+#if !defined(_WIN32)
sig_t ShellProtocolTest::saved_sigpipe_handler_ = nullptr;
+#endif
namespace {
diff --git a/adb/sysdeps_win32.cpp b/adb/sysdeps_win32.cpp
index c5aad02..5b23c79 100644
--- a/adb/sysdeps_win32.cpp
+++ b/adb/sysdeps_win32.cpp
@@ -1121,6 +1121,11 @@
BIPD(( "bip_buffer_write: enter %d->%d len %d", bip->fdin, bip->fdout, len ));
BIPDUMP( src, len );
+ if (bip->closed) {
+ errno = EPIPE;
+ return -1;
+ }
+
EnterCriticalSection( &bip->lock );
while (!bip->can_write) {