aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp
diff options
context:
space:
mode:
authorJesse Hall <jessehall@google.com>2012-07-11 16:25:37 -0700
committerJesse Hall <jessehall@google.com>2012-07-11 16:45:58 -0700
commitdca7f2a6ac56567850e0e03a063e1739e43c5ce2 (patch)
treedb0b5bd48d23a9bd1e03c23f1995802222516775 /emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp
parent310777dae93bc4e402ec8a807ce3151271d1038b (diff)
downloadsdk-dca7f2a6ac56567850e0e03a063e1739e43c5ce2.zip
sdk-dca7f2a6ac56567850e0e03a063e1739e43c5ce2.tar.gz
sdk-dca7f2a6ac56567850e0e03a063e1739e43c5ce2.tar.bz2
Use a per-process server address for the GLES server
Previously we used a hardcoded address (tcp port, unix pipe path, etc.) for the OpenGLRender system. Multiple emulators would all try to listen on the same address, with the system non-deterministically (?) choosing which one accepted each new connection. This resulted in frames going to the wrong emulator window, one emulator shutting down another's OpenGL system, etc. Now the OpenGLRender server requests an unused tcp port or derives a path from the pid, and reports the address back to the emulator client to use for future connections from the guest. Change-Id: I6af2eac0c7f27670a3b6595772eebc7aa2b24688
Diffstat (limited to 'emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp')
-rw-r--r--emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp b/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp
index 4da2cec..8a6e56e 100644
--- a/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp
+++ b/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp
@@ -28,6 +28,8 @@
#include <ws2tcpip.h>
#endif
+#define LISTEN_BACKLOG 4
+
TcpStream::TcpStream(size_t bufSize) :
SocketStream(bufSize)
{
@@ -47,10 +49,22 @@ TcpStream::TcpStream(int sock, size_t bufSize) :
setsockopt( sock, IPPROTO_TCP, TCP_NODELAY, (const char*)&flag, sizeof(flag) );
}
-int TcpStream::listen(unsigned short port)
+int TcpStream::listen(char addrstr[MAX_ADDRSTR_LEN])
{
- m_sock = socket_loopback_server(port, SOCK_STREAM);
- if (!valid()) return int(ERR_INVALID_SOCKET);
+ m_sock = socket_loopback_server(0, SOCK_STREAM);
+ if (!valid())
+ return int(ERR_INVALID_SOCKET);
+
+ /* get the actual port number assigned by the system */
+ struct sockaddr_in addr;
+ socklen_t addrLen = sizeof(addr);
+ memset(&addr, 0, sizeof(addr));
+ if (getsockname(m_sock, (struct sockaddr*)&addr, &addrLen) < 0) {
+ close(m_sock);
+ return int(ERR_INVALID_SOCKET);
+ }
+ snprintf(addrstr, MAX_ADDRSTR_LEN - 1, "%hu", ntohs(addr.sin_port));
+ addrstr[MAX_ADDRSTR_LEN-1] = '\0';
return 0;
}
@@ -78,8 +92,9 @@ SocketStream * TcpStream::accept()
return clientStream;
}
-int TcpStream::connect(unsigned short port)
+int TcpStream::connect(const char* addr)
{
+ int port = atoi(addr);
return connect("127.0.0.1",port);
}