diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/IOStream.h b/tools/emulator/opengl/host/include/libOpenglRender/IOStream.h similarity index 96% rename from tools/emulator/opengl/shared/OpenglCodecCommon/IOStream.h rename to tools/emulator/opengl/host/include/libOpenglRender/IOStream.h index 7cfccc340..ed8c266a5 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/IOStream.h +++ b/tools/emulator/opengl/host/include/libOpenglRender/IOStream.h @@ -33,6 +33,7 @@ public: virtual void *allocBuffer(size_t minSize) = 0; virtual int commitBuffer(size_t size) = 0; virtual const unsigned char *readFully( void *buf, size_t len) = 0; + virtual const unsigned char *read( void *buf, size_t *inout_len) = 0; virtual ~IOStream() { diff --git a/tools/emulator/opengl/host/libs/GLESv1_dec/Android.mk b/tools/emulator/opengl/host/libs/GLESv1_dec/Android.mk index 08fd3a3b2..c86c29203 100644 --- a/tools/emulator/opengl/host/libs/GLESv1_dec/Android.mk +++ b/tools/emulator/opengl/host/libs/GLESv1_dec/Android.mk @@ -19,6 +19,7 @@ LOCAL_SRC_FILES := \ LOCAL_C_INCLUDES += \ $(emulatorOpengl)/shared/OpenglCodecCommon \ + $(emulatorOpengl)/host/include/libOpenglRender \ $(emulatorOpengl)/system/GLESv1_enc LOCAL_STATIC_LIBRARIES := \ diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/Android.mk b/tools/emulator/opengl/shared/OpenglCodecCommon/Android.mk index e56927035..af8c16351 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/Android.mk +++ b/tools/emulator/opengl/shared/OpenglCodecCommon/Android.mk @@ -14,7 +14,7 @@ OpenglCodecCommon := \ LOCAL_SRC_FILES := $(OpenglCodecCommon) -LOCAL_C_INCLUDES += $(emulatorOpengl)/host/include/libOpenGLRender +LOCAL_C_INCLUDES += $(emulatorOpengl)/host/include/libOpenglRender LOCAL_CFLAGS += -DLOG_TAG=\"eglCodecCommon\" LOCAL_MODULE_TAGS := debug @@ -27,7 +27,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := $(OpenglCodecCommon) -LOCAL_C_INCLUDES += $(emulatorOpengl)/host/include/libOpenGLRender +LOCAL_C_INCLUDES += $(emulatorOpengl)/host/include/libOpenglRender LOCAL_MODULE_TAGS := debug LOCAL_MODULE := libOpenglCodecCommon diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp b/tools/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp index 86202d0fb..b33d24f39 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp +++ b/tools/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp @@ -14,25 +14,23 @@ * limitations under the License. */ #include "TcpStream.h" - -#ifdef ANDROID -#include -#endif - +#include #include -#include -#include -#include #include #include #include #include -TcpStream::TcpStream(size_t bufSize) : IOStream(bufSize) +#ifdef __linux__ +#include +#endif + +TcpStream::TcpStream(size_t bufSize) : + IOStream(bufSize), + m_sock(-1), + m_bufsize(bufSize), + m_buf(NULL) { - m_sock = socket(AF_INET, SOCK_STREAM, 0); - m_bufsize = bufSize; - m_buf = NULL; } TcpStream::TcpStream(int sock, size_t bufSize) : @@ -41,7 +39,6 @@ TcpStream::TcpStream(int sock, size_t bufSize) : m_bufsize(bufSize), m_buf(NULL) { - } TcpStream::~TcpStream() @@ -55,39 +52,15 @@ TcpStream::~TcpStream() } -int TcpStream::listen(unsigned short port, bool localhost_only, bool reuse_address) +int TcpStream::listen(unsigned short port, bool localhost_only) { + if (localhost_only) { + m_sock = socket_loopback_server(port, SOCK_STREAM); + } else { + m_sock = socket_inaddr_any_server(port, SOCK_STREAM); + } if (!valid()) return int(ERR_INVALID_SOCKET); - // NOTE: This is a potential security issue. However, since we accept connection - // from local host only, this should be reasonably OK. - - if (reuse_address) { - int one = 1; - if (setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) { - perror("setsockopt resuseaddr"); - } - } - - struct sockaddr_in addr; - memset(&addr, 0, sizeof(addr)); - - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - if (localhost_only) { - addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - } else { - addr.sin_addr.s_addr = INADDR_ANY; - } - - if (::bind(m_sock, (const sockaddr *) &addr, sizeof(addr)) < 0) { - perror("bind"); - return -1; - } - if (::listen(m_sock, 5) < 0) { - perror("listen"); - return -1; - } return 0; } @@ -117,29 +90,8 @@ TcpStream * TcpStream::accept() int TcpStream::connect(const char *hostname, unsigned short port) { - struct addrinfo *ai; - char portstr[10]; - snprintf(portstr, sizeof(portstr), "%d", port); - - if (getaddrinfo(hostname, portstr, NULL, &ai) != 0) { - return -1; - } - - struct addrinfo *i; - i = ai; - while (i != NULL) { - if (::connect(m_sock, i->ai_addr, i->ai_addrlen) >= 0) { - break; - } else { - if (errno != EINTR) { - i = i->ai_next; - } - } - } - - freeaddrinfo(ai); - if (i == NULL) return -1; - + m_sock = socket_network_client(hostname, port, SOCK_STREAM); + if (!valid()) return -1; return 0; } @@ -178,10 +130,11 @@ int TcpStream::writeFully(const void *buf, size_t len) int retval = 0; while (res > 0) { - ssize_t stat = ::send(m_sock, (unsigned char *)(buf) + (len - res), res, 0); + ssize_t stat = ::send(m_sock, (const char *)(buf) + (len - res), res, 0); if (stat < 0) { if (errno != EINTR) { retval = stat; + ERR("TcpStream::writeFully failed, errno = %d\n", errno); break; } } else { @@ -194,10 +147,13 @@ int TcpStream::writeFully(const void *buf, size_t len) const unsigned char *TcpStream::readFully(void *buf, size_t len) { if (!valid()) return NULL; - if (!buf) return NULL; // do not allow NULL buf in that implementation + if (!buf) { + ERR("TcpStream::readFully failed, buf=NULL"); + return NULL; // do not allow NULL buf in that implementation + } size_t res = len; while (res > 0) { - ssize_t stat = ::recv(m_sock, (unsigned char *)(buf) + len - res, len, MSG_WAITALL); + ssize_t stat = ::recv(m_sock, (char *)(buf) + len - res, len, 0); if (stat == 0) { // client shutdown; return NULL; @@ -205,6 +161,7 @@ const unsigned char *TcpStream::readFully(void *buf, size_t len) if (errno == EINTR) { continue; } else { + ERR("TcpStream::readFully failed, errno = %d 0x%x \n", errno,buf); return NULL; } } else { @@ -214,12 +171,33 @@ const unsigned char *TcpStream::readFully(void *buf, size_t len) return (const unsigned char *)buf; } +const unsigned char *TcpStream::read( void *buf, size_t *inout_len) +{ + if (!valid()) return NULL; + if (!buf) { + ERR("TcpStream::read failed, buf=NULL"); + return NULL; // do not allow NULL buf in that implementation + } + + int n; + do { + n = recv(buf, *inout_len); + } while( n < 0 && errno == EINTR ); + + if (n > 0) { + *inout_len = n; + return (const unsigned char *)buf; + } + + return NULL; +} + int TcpStream::recv(void *buf, size_t len) { if (!valid()) return int(ERR_INVALID_SOCKET); int res = 0; while(true) { - res = ::recv(m_sock, buf, len, 0); + res = ::recv(m_sock, (char *)buf, len, 0); if (res < 0) { if (errno == EINTR) { continue; diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/TcpStream.h b/tools/emulator/opengl/shared/OpenglCodecCommon/TcpStream.h index aa65b7ed7..75218434b 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/TcpStream.h +++ b/tools/emulator/opengl/shared/OpenglCodecCommon/TcpStream.h @@ -26,13 +26,14 @@ public: explicit TcpStream(size_t bufsize = 10000); ~TcpStream(); - int listen(unsigned short port, bool localhost_only = true, bool reuse_address = true); + int listen(unsigned short port, bool localhost_only = true); TcpStream *accept(); int connect(const char *hostname, unsigned short port); virtual void *allocBuffer(size_t minSize); virtual int commitBuffer(size_t size); virtual const unsigned char *readFully( void *buf, size_t len); + virtual const unsigned char *read( void *buf, size_t *inout_len); bool valid() { return m_sock >= 0; } int recv(void *buf, size_t len); diff --git a/tools/emulator/opengl/system/GLESv1_enc/Android.mk b/tools/emulator/opengl/system/GLESv1_enc/Android.mk index bf4943bd9..c8fd18b01 100644 --- a/tools/emulator/opengl/system/GLESv1_enc/Android.mk +++ b/tools/emulator/opengl/system/GLESv1_enc/Android.mk @@ -19,6 +19,7 @@ LOCAL_PRELINK_MODULE := false LOCAL_CFLAGS += -DLOG_TAG=\"egl_GLESv1_enc\" LOCAL_C_INCLUDES += \ $(emulatorOpengl)/shared/OpenglCodecCommon \ + $(emulatorOpengl)/host/include/libOpenglRender \ $(glesv1_intermediates) LOCAL_STATIC_LIBRARIES := \ diff --git a/tools/emulator/opengl/tests/gles_android_wrapper/Android.mk b/tools/emulator/opengl/tests/gles_android_wrapper/Android.mk index 5ae33446f..15e2e98f0 100644 --- a/tools/emulator/opengl/tests/gles_android_wrapper/Android.mk +++ b/tools/emulator/opengl/tests/gles_android_wrapper/Android.mk @@ -21,6 +21,7 @@ LOCAL_ADDITIONAL_DEPENDENCIES := \ emulatorOpengl := $(LOCAL_PATH)/../.. LOCAL_C_INCLUDES := $(emulatorOpengl)/shared/OpenglCodecCommon \ + $(emulatorOpengl)/host/include/libOpenglRender \ $(call intermediates-dir-for, SHARED_LIBRARIES, libut_rendercontrol_enc) \ $(call intermediates-dir-for, SHARED_LIBRARIES, libGLESv1_enc) \ $(emulatorOpengl)/system/GLESv1_enc \ diff --git a/tools/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk b/tools/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk index a3a2c4a2a..673fd1184 100644 --- a/tools/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk +++ b/tools/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk @@ -18,7 +18,11 @@ intermediates := $(local-intermediates-dir) LOCAL_STATIC_LIBRARIES := \ libOpenglCodecCommon \ liblog -LOCAL_C_INCLUDES += $(emulatorOpengl)/shared/OpenglCodecCommon $(emulatorOpengl)/tests/ut_rendercontrol_enc + +LOCAL_C_INCLUDES += \ + $(emulatorOpengl)/shared/OpenglCodecCommon \ + $(emulatorOpengl)/host/include/libOpenglRender \ + $(emulatorOpengl)/tests/ut_rendercontrol_enc #we use only *_dec.h as a sentinel for the other generated headers GEN := $(intermediates)/ut_rendercontrol_dec.cpp $(intermediates)/ut_rendercontrol_dec.h diff --git a/tools/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk b/tools/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk index bfcd69944..d9beb8581 100644 --- a/tools/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk +++ b/tools/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk @@ -12,7 +12,9 @@ LOCAL_MODULE_CLASS := SHARED_LIBRARIES ut_intermediates := $(local-intermediates-dir) -LOCAL_C_INCLUDES += $(emulatorOpengl)/shared/OpenglCodecCommon +LOCAL_C_INCLUDES += \ + $(emulatorOpengl)/shared/OpenglCodecCommon \ + $(emulatorOpengl)/host/include/libOpenglRender LOCAL_STATIC_LIBRARIES := \ libOpenglCodecCommon diff --git a/tools/emulator/opengl/tests/ut_renderer/Android.mk b/tools/emulator/opengl/tests/ut_renderer/Android.mk index d51beabe6..28317e9b3 100644 --- a/tools/emulator/opengl/tests/ut_renderer/Android.mk +++ b/tools/emulator/opengl/tests/ut_renderer/Android.mk @@ -43,6 +43,7 @@ LOCAL_CFLAGS := -DPVR_WAR #LOCAL_CFLAGS += -g -O0 LOCAL_C_INCLUDES := $(emulatorOpengl)/shared/OpenglCodecCommon \ + $(emulatorOpengl)/host/include/libOpenglRender \ $(call intermediates-dir-for, SHARED_LIBRARIES, libut_rendercontrol_dec, HOST) \ $(call intermediates-dir-for, SHARED_LIBRARIES, libGLESv1_dec, HOST) \ $(emulatorOpengl)/host/libs/GLESv1_dec \ @@ -50,7 +51,10 @@ LOCAL_C_INCLUDES := $(emulatorOpengl)/shared/OpenglCodecCommon \ $(emulatorOpengl)/tests/ut_rendercontrol_enc LOCAL_SHARED_LIBRARIES := libut_rendercontrol_dec libGLESv1_dec libEGL_host_wrapper -LOCAL_STATIC_LIBRARIES := libOpenglCodecCommon +LOCAL_STATIC_LIBRARIES := \ + libOpenglCodecCommon \ + libcutils + LOCAL_LDLIBS := -lpthread -lX11 -lrt include $(BUILD_HOST_EXECUTABLE)