From 0832fb6407d1c85cba20a8cc0aff828db3c134de Mon Sep 17 00:00:00 2001 From: Siva Velusamy Date: Fri, 27 Jan 2012 14:39:03 -0800 Subject: [PATCH] gltrace: Use Unix Domain Socket rather than INET Socket Export trace information via abstract Unix Domain Socket (UDS). This allows tracing of applications without INTERNET permission, and should be faster as well. Change-Id: Iabb67fcc2bc2484afd8128af07dca723b81c52c6 --- opengl/libs/GLES_trace/src/gltrace_eglapi.cpp | 8 +++--- .../libs/GLES_trace/src/gltrace_transport.cpp | 25 +++++++++++-------- .../libs/GLES_trace/src/gltrace_transport.h | 7 +++--- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/opengl/libs/GLES_trace/src/gltrace_eglapi.cpp b/opengl/libs/GLES_trace/src/gltrace_eglapi.cpp index c237d75fc..c44215379 100644 --- a/opengl/libs/GLES_trace/src/gltrace_eglapi.cpp +++ b/opengl/libs/GLES_trace/src/gltrace_eglapi.cpp @@ -77,12 +77,10 @@ static void *commandReceiveTask(void *arg) { } void GLTrace_start() { - char value[PROPERTY_VALUE_MAX]; + char udsName[PROPERTY_VALUE_MAX]; - property_get("debug.egl.debug_port", value, "5039"); - const unsigned short port = (unsigned short)atoi(value); - - int clientSocket = gltrace::acceptClientConnection(port); + property_get("debug.egl.debug_portname", udsName, "gltrace"); + int clientSocket = gltrace::acceptClientConnection(udsName); if (clientSocket < 0) { ALOGE("Error creating GLTrace server socket. Quitting application."); exit(-1); diff --git a/opengl/libs/GLES_trace/src/gltrace_transport.cpp b/opengl/libs/GLES_trace/src/gltrace_transport.cpp index ce3fae59a..5251b12ce 100644 --- a/opengl/libs/GLES_trace/src/gltrace_transport.cpp +++ b/opengl/libs/GLES_trace/src/gltrace_transport.cpp @@ -17,9 +17,10 @@ #include #include +#include #include +#include #include -#include #include @@ -28,22 +29,24 @@ namespace android { namespace gltrace { -int acceptClientConnection(int serverPort) { - int serverSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); +int acceptClientConnection(char *sockname) { + int serverSocket = socket(AF_LOCAL, SOCK_STREAM, 0); if (serverSocket < 0) { ALOGE("Error (%d) while creating socket. Check if app has network permissions.", serverSocket); return -1; } - struct sockaddr_in server, client; + struct sockaddr_un server, client; - server.sin_family = AF_INET; - server.sin_addr.s_addr = htonl(INADDR_ANY); - server.sin_port = htons(serverPort); + memset(&server, 0, sizeof server); + server.sun_family = AF_UNIX; + // the first byte of sun_path should be '\0' for abstract namespace + strcpy(server.sun_path + 1, sockname); - socklen_t sockaddr_len = sizeof(sockaddr_in); - if (bind(serverSocket, (struct sockaddr *) &server, sizeof(server)) < 0) { + // note that sockaddr_len should be set to the exact size of the buffer that is used. + socklen_t sockaddr_len = sizeof(server.sun_family) + strlen(sockname) + 1; + if (bind(serverSocket, (struct sockaddr *) &server, sockaddr_len) < 0) { close(serverSocket); ALOGE("Failed to bind the server socket"); return -1; @@ -55,7 +58,7 @@ int acceptClientConnection(int serverPort) { return -1; } - ALOGD("gltrace::waitForClientConnection: server listening @ port %d", serverPort); + ALOGD("gltrace::waitForClientConnection: server listening @ path %s", sockname); int clientSocket = accept(serverSocket, (struct sockaddr *)&client, &sockaddr_len); if (clientSocket < 0) { @@ -64,7 +67,7 @@ int acceptClientConnection(int serverPort) { return -1; } - ALOGD("gltrace::waitForClientConnection: client connected: %s", inet_ntoa(client.sin_addr)); + ALOGD("gltrace::waitForClientConnection: client connected."); // do not accept any more incoming connections close(serverSocket); diff --git a/opengl/libs/GLES_trace/src/gltrace_transport.h b/opengl/libs/GLES_trace/src/gltrace_transport.h index d31df7b73..36650355a 100644 --- a/opengl/libs/GLES_trace/src/gltrace_transport.h +++ b/opengl/libs/GLES_trace/src/gltrace_transport.h @@ -76,10 +76,11 @@ public: }; /** - * Utility method: start a server at @serverPort, and wait for a client - * connection. Returns the connected client socket on success, or -1 on failure. + * Utility method: start a server listening at @sockName (unix domain socket, + * abstract namespace path), and wait for a client connection. + * Returns the connected client socket on success, or -1 on failure. */ -int acceptClientConnection(int serverPort); +int acceptClientConnection(char *sockName); }; };