aboutsummaryrefslogtreecommitdiffstats
path: root/android/hw-pipe-net.c
diff options
context:
space:
mode:
Diffstat (limited to 'android/hw-pipe-net.c')
-rw-r--r--android/hw-pipe-net.c76
1 files changed, 32 insertions, 44 deletions
diff --git a/android/hw-pipe-net.c b/android/hw-pipe-net.c
index d83d8b1..b3bc6c9 100644
--- a/android/hw-pipe-net.c
+++ b/android/hw-pipe-net.c
@@ -68,7 +68,6 @@ typedef struct {
int wakeWanted;
LoopIo io[1];
AsyncConnector connector[1];
-
} NetPipe;
static void
@@ -251,7 +250,7 @@ netPipe_sendBuffers( void* opaque, const GoldfishPipeBuffer* buffers, int numBuf
buff = buffers;
while (count > 0) {
int avail = buff->size - buffStart;
- int len = write(pipe->io->fd, buff->data + buffStart, avail);
+ int len = socket_send(pipe->io->fd, buff->data + buffStart, avail);
/* the write succeeded */
if (len > 0) {
@@ -272,10 +271,6 @@ netPipe_sendBuffers( void* opaque, const GoldfishPipeBuffer* buffers, int numBuf
break;
}
- /* loop on EINTR */
- if (errno == EINTR)
- continue;
-
/* if we already wrote some stuff, simply return */
if (ret > 0) {
break;
@@ -309,7 +304,7 @@ netPipe_recvBuffers( void* opaque, GoldfishPipeBuffer* buffers, int numBuffers
buff = buffers;
while (count > 0) {
int avail = buff->size - buffStart;
- int len = read(pipe->io->fd, buff->data + buffStart, avail);
+ int len = socket_recv(pipe->io->fd, buff->data + buffStart, avail);
/* the read succeeded */
if (len > 0) {
@@ -330,10 +325,6 @@ netPipe_recvBuffers( void* opaque, GoldfishPipeBuffer* buffers, int numBuffers
break;
}
- /* loop on EINTR */
- if (errno == EINTR)
- continue;
-
/* if we already read some stuff, simply return */
if (ret > 0) {
break;
@@ -381,40 +372,17 @@ void*
netPipe_initTcp( void* hwpipe, void* _looper, const char* args )
{
/* Build SockAddress from arguments. Acceptable formats are:
- *
* <port>
- * <host>:<port>
*/
SockAddress address;
+ uint16_t port;
void* ret;
if (args == NULL) {
D("%s: Missing address!", __FUNCTION__);
return NULL;
}
- D("%s: Address is '%s'", __FUNCTION__, args);
-
- char host[256]; /* max size of regular FDQN+1 */
- int hostlen = 0;
- int port;
- const char* p;
-
- /* Assume that anything after the last ':' is a port number
- * And that what is before it is a port number. Should handle IPv6
- * notation. */
- p = strrchr(args, ':');
- if (p != NULL) {
- hostlen = p - args;
- if (hostlen >= sizeof(host)) {
- D("%s: Address too long!", __FUNCTION__);
- return NULL;
- }
- memcpy(host, args, hostlen);
- host[hostlen] = '\0';
- args = p + 1;
- } else {
- snprintf(host, sizeof host, "127.0.0.1");
- }
+ D("%s: Port is '%s'", __FUNCTION__, args);
/* Now, look at the port number */
{
@@ -423,12 +391,9 @@ netPipe_initTcp( void* hwpipe, void* _looper, const char* args )
if (end == NULL || *end != '\0' || val <= 0 || val > 65535) {
D("%s: Invalid port number: '%s'", __FUNCTION__, args);
}
- port = (int)val;
- }
- if (sock_address_init_resolve(&address, host, port, 0) < 0) {
- D("%s: Could not resolve address", __FUNCTION__);
- return NULL;
+ port = (uint16_t)val;
}
+ sock_address_init_inet(&address, SOCK_ADDRESS_INET_LOOPBACK, port);
ret = netPipe_initFromAddress(hwpipe, &address, _looper);
@@ -436,6 +401,7 @@ netPipe_initTcp( void* hwpipe, void* _looper, const char* args )
return ret;
}
+#ifndef _WIN32
void*
netPipe_initUnix( void* hwpipe, void* _looper, const char* args )
{
@@ -459,7 +425,7 @@ netPipe_initUnix( void* hwpipe, void* _looper, const char* args )
sock_address_done(&address);
return ret;
}
-
+#endif
/**********************************************************************
**********************************************************************
@@ -477,6 +443,7 @@ static const GoldfishPipeFuncs netPipeTcp_funcs = {
netPipe_wakeOn,
};
+#ifndef _WIN32
static const GoldfishPipeFuncs netPipeUnix_funcs = {
netPipe_initUnix,
netPipe_closeFromGuest,
@@ -485,7 +452,7 @@ static const GoldfishPipeFuncs netPipeUnix_funcs = {
netPipe_poll,
netPipe_wakeOn,
};
-
+#endif
#define DEFAULT_OPENGLES_PORT 22468
@@ -493,10 +460,29 @@ static void*
openglesPipe_init( void* hwpipe, void* _looper, const char* args )
{
char temp[32];
+ NetPipe *pipe;
/* For now, simply connect through tcp */
snprintf(temp, sizeof temp, "%d", DEFAULT_OPENGLES_PORT);
- return netPipe_initTcp(hwpipe, _looper, temp);
+ pipe = (NetPipe *)netPipe_initTcp(hwpipe, _looper, temp);
+
+ // Disable TCP nagle algorithm to improve throughput of small packets
+ socket_set_nodelay(pipe->io->fd);
+
+ // On Win32, adjust buffer sizes
+#ifdef _WIN32
+ {
+ int sndbuf = 128 * 1024;
+ int len = sizeof(sndbuf);
+ if (setsockopt(pipe->io->fd, SOL_SOCKET, SO_SNDBUF,
+ (char*)&sndbuf, len) == SOCKET_ERROR) {
+ D("Failed to set SO_SNDBUF to %d error=0x%x\n",
+ sndbuf, WSAGetLastError());
+ }
+ }
+#endif /* _WIN32 */
+
+ return pipe;
}
static const GoldfishPipeFuncs openglesPipe_funcs = {
@@ -515,6 +501,8 @@ android_net_pipes_init(void)
Looper* looper = looper_newCore();
goldfish_pipe_add_type( "tcp", looper, &netPipeTcp_funcs );
+#ifndef _WIN32
goldfish_pipe_add_type( "unix", looper, &netPipeUnix_funcs );
+#endif
goldfish_pipe_add_type( "opengles", looper, &openglesPipe_funcs );
}