summaryrefslogtreecommitdiffstats
path: root/adb/sysdeps.h
diff options
context:
space:
mode:
authorSpencer Low <CompareAndSwap@gmail.com>2015-01-25 14:40:16 -0800
committerSpencer Low <CompareAndSwap@gmail.com>2015-01-26 21:56:26 -0800
commitf055c193b85b5bc077a4e278f84f33a266edccf7 (patch)
treea4978a66a4e4c4303759ac2bcfa4a186b967832a /adb/sysdeps.h
parenta76f057af81b7a03c9c18af0bcb763f7e7f03fbf (diff)
downloadsystem_core-f055c193b85b5bc077a4e278f84f33a266edccf7.zip
system_core-f055c193b85b5bc077a4e278f84f33a266edccf7.tar.gz
system_core-f055c193b85b5bc077a4e278f84f33a266edccf7.tar.bz2
adb: Win32: set socket buffer sizes properly
On Windows, adb_socket_setbufsize() was taking a file descriptor value from the compatibility layer in sysdeps_win32.c (namely, an index into the _win32_fhs array) and passing it to the Winsock setsockopt() call, which wants a Winsock SOCKET handle. Basically, adb_socket_setbufsize() was passing `fd` instead of `_fh_from_int(fd)->fh_socket`, resulting in adb effectively setting a socket buffer size on a random socket in the process. The fix is to introduce adb_setsockopt() which just calls setsockopt() on non-Win32, and which uses the Winsock SOCKET handle on Win32. The change also moves Win32 disable_tcp_nagle() to a header and adds an extra sanity check to adb_shutdown(). Change-Id: I4354e818d27538f7ff5b0e70b28bdb6300e1b98b Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
Diffstat (limited to 'adb/sysdeps.h')
-rw-r--r--adb/sysdeps.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/adb/sysdeps.h b/adb/sysdeps.h
index 304a613..086dd61 100644
--- a/adb/sysdeps.h
+++ b/adb/sysdeps.h
@@ -89,8 +89,6 @@ static __inline__ void close_on_exec(int fd)
/* nothing really */
}
-extern void disable_tcp_nagle(int fd);
-
#define lstat stat /* no symlinks on Win32 */
#define S_ISLNK(m) 0 /* no symlinks on Win32 */
@@ -210,10 +208,21 @@ extern int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t
#undef accept
#define accept ___xxx_accept
+extern int adb_setsockopt(int fd, int level, int optname, const void* optval, socklen_t optlen);
+
+#undef setsockopt
+#define setsockopt ___xxx_setsockopt
+
static __inline__ int adb_socket_setbufsize( int fd, int bufsize )
{
int opt = bufsize;
- return setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (const char*)&opt, sizeof(opt));
+ return adb_setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (const void*)&opt, sizeof(opt));
+}
+
+static __inline__ void disable_tcp_nagle( int fd )
+{
+ int on = 1;
+ adb_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void*)&on, sizeof(on));
}
extern int adb_socketpair( int sv[2] );
@@ -450,6 +459,13 @@ static __inline__ void disable_tcp_nagle(int fd)
setsockopt( fd, IPPROTO_TCP, TCP_NODELAY, (void*)&on, sizeof(on) );
}
+static __inline__ int adb_setsockopt( int fd, int level, int optname, const void* optval, socklen_t optlen )
+{
+ return setsockopt( fd, level, optname, optval, optlen );
+}
+
+#undef setsockopt
+#define setsockopt ___xxx_setsockopt
static __inline__ int unix_socketpair( int d, int type, int protocol, int sv[2] )
{