aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/opengl/shared/OpenglCodecCommon
diff options
context:
space:
mode:
Diffstat (limited to 'emulator/opengl/shared/OpenglCodecCommon')
-rw-r--r--emulator/opengl/shared/OpenglCodecCommon/Android.mk22
-rw-r--r--emulator/opengl/shared/OpenglCodecCommon/ErrorLog.h22
-rw-r--r--emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp248
-rw-r--r--emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h26
-rw-r--r--emulator/opengl/shared/OpenglCodecCommon/SocketStream.cpp4
-rw-r--r--emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp72
-rw-r--r--emulator/opengl/shared/OpenglCodecCommon/UnixStream.cpp8
7 files changed, 166 insertions, 236 deletions
diff --git a/emulator/opengl/shared/OpenglCodecCommon/Android.mk b/emulator/opengl/shared/OpenglCodecCommon/Android.mk
index 5deb1f7..b6a7e07 100644
--- a/emulator/opengl/shared/OpenglCodecCommon/Android.mk
+++ b/emulator/opengl/shared/OpenglCodecCommon/Android.mk
@@ -24,19 +24,21 @@ endif
$(call emugl-begin-host-static-library,libOpenglCodecCommon)
LOCAL_SRC_FILES := $(host_commonSources)
-
-$(call emugl-export,STATIC_LIBRARIES,libcutils)
-$(call emugl-export,C_INCLUDES,$(LOCAL_PATH))
+$(call emugl-import, libemugl_common)
+$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/host/include/libOpenglRender $(LOCAL_PATH))
+$(call emugl-export,LDLIBS,-lstdc++)
$(call emugl-end-module)
### OpenglCodecCommon host, 64-bit #########################################
-$(call emugl-begin-host-static-library,lib64OpenglCodecCommon)
+ifdef EMUGL_BUILD_64BITS
+ $(call emugl-begin-host-static-library,lib64OpenglCodecCommon)
-LOCAL_SRC_FILES := $(host_commonSources)
-
-$(call emugl-export,STATIC_LIBRARIES,lib64cutils)
-$(call emugl-export,C_INCLUDES,$(LOCAL_PATH))
-$(call emugl-export,CFLAGS,-m64)
-$(call emugl-end-module)
+ LOCAL_SRC_FILES := $(host_commonSources)
+ $(call emugl-import, lib64emugl_common)
+ $(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/host/include/libOpenglRender $(LOCAL_PATH))
+ $(call emugl-export,CFLAGS,-m64 -fPIC)
+ $(call emugl-export,LDLIBS,-lstdc++)
+ $(call emugl-end-module)
+endif
diff --git a/emulator/opengl/shared/OpenglCodecCommon/ErrorLog.h b/emulator/opengl/shared/OpenglCodecCommon/ErrorLog.h
index 43577d4..4cad61f 100644
--- a/emulator/opengl/shared/OpenglCodecCommon/ErrorLog.h
+++ b/emulator/opengl/shared/OpenglCodecCommon/ErrorLog.h
@@ -16,22 +16,12 @@
#ifndef _ERROR_LOG_H_
#define _ERROR_LOG_H_
-#ifdef __ANDROID__
-# include <cutils/log.h>
-# define ERR(...) ALOGE(__VA_ARGS__)
-# ifdef EMUGL_DEBUG
-# define DBG(...) ALOGD(__VA_ARGS__)
-# else
-# define DBG(...) ((void)0)
-# endif
+#include <stdio.h>
+#define ERR(...) fprintf(stderr, __VA_ARGS__)
+#ifdef EMUGL_DEBUG
+# define DBG(...) fprintf(stderr, __VA_ARGS__)
#else
-# include <stdio.h>
-# define ERR(...) fprintf(stderr, __VA_ARGS__)
-# ifdef EMUGL_DEBUG
-# define DBG(...) fprintf(stderr, __VA_ARGS__)
-# else
-# define DBG(...) ((void)0)
-# endif
+# define DBG(...) ((void)0)
#endif
-#endif
+#endif // _ERROR_LOG_H_
diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp
index a054562..db7f418 100644
--- a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp
+++ b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp
@@ -16,23 +16,22 @@
#include "GLSharedGroup.h"
-/**** KeyedVector utilities ****/
-
-template <typename T>
-static void clearObjectMap(android::DefaultKeyedVector<GLuint, T>& v) {
- for (size_t i = 0; i < v.size(); i++)
- delete v.valueAt(i);
- v.clear();
-}
+#include <string.h>
/**** BufferData ****/
BufferData::BufferData() : m_size(0) {};
+
BufferData::BufferData(GLsizeiptr size, void * data) : m_size(size)
{
- void * buffer = NULL;
- if (size>0) buffer = m_fixedBuffer.alloc(size);
- if (data) memcpy(buffer, data, size);
+ void* buffer = NULL;
+
+ if (size > 0) {
+ buffer = m_fixedBuffer.alloc(size);
+ if (data) {
+ memcpy(buffer, data, size);
+ }
+ }
}
/**** ProgramData ****/
@@ -204,9 +203,7 @@ bool ProgramData::attachShader(GLuint shader)
return false;
}
}
- // AKA m_shaders.push_back(), but that has an ambiguous call to insertAt()
- // due to the default parameters. This is the desired insertAt() overload.
- m_shaders.insertAt(shader, m_shaders.size(), 1);
+ m_shaders.append(shader);
return true;
}
@@ -215,7 +212,7 @@ bool ProgramData::detachShader(GLuint shader)
size_t n = m_shaders.size();
for (size_t i = 0; i < n; i++) {
if (m_shaders[i] == shader) {
- m_shaders.removeAt(i);
+ m_shaders.remove(i);
return true;
}
}
@@ -225,49 +222,32 @@ bool ProgramData::detachShader(GLuint shader)
/***** GLSharedGroup ****/
GLSharedGroup::GLSharedGroup() :
- m_buffers(android::DefaultKeyedVector<GLuint, BufferData*>(NULL)),
- m_programs(android::DefaultKeyedVector<GLuint, ProgramData*>(NULL)),
- m_shaders(android::DefaultKeyedVector<GLuint, ShaderData*>(NULL))
-{
-}
+ m_buffers(), m_programs(), m_shaders() {}
-GLSharedGroup::~GLSharedGroup()
-{
- m_buffers.clear();
- m_programs.clear();
- clearObjectMap(m_buffers);
- clearObjectMap(m_programs);
- clearObjectMap(m_shaders);
-}
+GLSharedGroup::~GLSharedGroup() {}
BufferData * GLSharedGroup::getBufferData(GLuint bufferId)
{
emugl::Mutex::AutoLock _lock(m_lock);
- return m_buffers.valueFor(bufferId);
+ return m_buffers.get(bufferId);
}
void GLSharedGroup::addBufferData(GLuint bufferId, GLsizeiptr size, void * data)
{
emugl::Mutex::AutoLock _lock(m_lock);
- m_buffers.add(bufferId, new BufferData(size, data));
+ m_buffers.set(bufferId, new BufferData(size, data));
}
void GLSharedGroup::updateBufferData(GLuint bufferId, GLsizeiptr size, void * data)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ssize_t idx = m_buffers.indexOfKey(bufferId);
- if (idx >= 0) {
- delete m_buffers.valueAt(idx);
- m_buffers.editValueAt(idx) = new BufferData(size, data);
- } else {
- m_buffers.add(bufferId, new BufferData(size, data));
- }
+ m_buffers.set(bufferId, new BufferData(size, data));
}
GLenum GLSharedGroup::subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsizeiptr size, void * data)
{
emugl::Mutex::AutoLock _lock(m_lock);
- BufferData * buf = m_buffers.valueFor(bufferId);
+ BufferData * buf = m_buffers.get(bufferId);
if ((!buf) || (buf->m_size < offset+size) || (offset < 0) || (size<0)) return GL_INVALID_VALUE;
//it's safe to update now
@@ -278,32 +258,20 @@ GLenum GLSharedGroup::subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsi
void GLSharedGroup::deleteBufferData(GLuint bufferId)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ssize_t idx = m_buffers.indexOfKey(bufferId);
- if (idx >= 0) {
- delete m_buffers.valueAt(idx);
- m_buffers.removeItemsAt(idx);
- }
+ ssize_t idx = m_buffers.remove(bufferId);
}
void GLSharedGroup::addProgramData(GLuint program)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData *pData = m_programs.valueFor(program);
- if (pData)
- {
- m_programs.removeItem(program);
- delete pData;
- }
-
- m_programs.add(program,new ProgramData());
+ m_programs.set(program, new ProgramData());
}
void GLSharedGroup::initProgramData(GLuint program, GLuint numIndexes)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData *pData = m_programs.valueFor(program);
- if (pData)
- {
+ ProgramData *pData = m_programs.get(program);
+ if (pData) {
pData->initProgramData(numIndexes);
}
}
@@ -311,136 +279,135 @@ void GLSharedGroup::initProgramData(GLuint program, GLuint numIndexes)
bool GLSharedGroup::isProgramInitialized(GLuint program)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
- if (pData)
- {
- return pData->isInitialized();
- }
- return false;
+ ProgramData* pData = m_programs.get(program);
+ return pData && pData->isInitialized();
}
void GLSharedGroup::deleteProgramData(GLuint program)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData *pData = m_programs.valueFor(program);
- if (pData)
- delete pData;
- m_programs.removeItem(program);
+ m_programs.remove(program);
}
void GLSharedGroup::attachShader(GLuint program, GLuint shader)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* programData = m_programs.valueFor(program);
- ssize_t idx = m_shaders.indexOfKey(shader);
- if (programData && idx >= 0) {
- if (programData->attachShader(shader)) {
- refShaderDataLocked(idx);
- }
+ ProgramData* programData = m_programs.get(program);
+ if (programData && programData->attachShader(shader)) {
+ refShaderDataLocked(shader);
}
}
void GLSharedGroup::detachShader(GLuint program, GLuint shader)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* programData = m_programs.valueFor(program);
- ssize_t idx = m_shaders.indexOfKey(shader);
- if (programData && idx >= 0) {
- if (programData->detachShader(shader)) {
- unrefShaderDataLocked(idx);
- }
+ ProgramData* programData = m_programs.get(program);
+ if (programData && programData->detachShader(shader)) {
+ unrefShaderDataLocked(shader);
}
}
-void GLSharedGroup::setProgramIndexInfo(GLuint program, GLuint index, GLint base, GLint size, GLenum type, const char* name)
+void GLSharedGroup::setProgramIndexInfo(GLuint program,
+ GLuint index,
+ GLint base,
+ GLint size,
+ GLenum type,
+ const char* name)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
- if (pData)
- {
- pData->setIndexInfo(index,base,size,type);
-
- if (type == GL_SAMPLER_2D) {
- size_t n = pData->getNumShaders();
- for (size_t i = 0; i < n; i++) {
- GLuint shaderId = pData->getShader(i);
- ShaderData* shader = m_shaders.valueFor(shaderId);
- if (!shader) continue;
- ShaderData::StringList::iterator nameIter = shader->samplerExternalNames.begin();
- ShaderData::StringList::iterator nameEnd = shader->samplerExternalNames.end();
- while (nameIter != nameEnd) {
- if (*nameIter == name) {
- pData->setIndexFlags(index, ProgramData::INDEX_FLAG_SAMPLER_EXTERNAL);
- break;
- }
- ++nameIter;
+ ProgramData* pData = m_programs.get(program);
+ if (!pData) {
+ return;
+ }
+ pData->setIndexInfo(index,base,size,type);
+
+ if (type == GL_SAMPLER_2D) {
+ size_t n = pData->getNumShaders();
+ for (size_t i = 0; i < n; i++) {
+ GLuint shaderId = pData->getShader(i);
+ ShaderData* shader = m_shaders.get(shaderId);
+ if (!shader) continue;
+#if 0 // TODO(digit): Understand why samplerExternalNames is always empty?
+ ShaderData::StringList::iterator nameIter =
+ shader->samplerExternalNames.begin();
+ ShaderData::StringList::iterator nameEnd =
+ shader->samplerExternalNames.end();
+ while (nameIter != nameEnd) {
+ if (*nameIter == name) {
+ pData->setIndexFlags(
+ index,
+ ProgramData::INDEX_FLAG_SAMPLER_EXTERNAL);
+ break;
}
+ ++nameIter;
}
+#endif
}
}
}
+
GLenum GLSharedGroup::getProgramUniformType(GLuint program, GLint location)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
- GLenum type=0;
- if (pData)
- {
- type = pData->getTypeForLocation(location);
- }
- return type;
+ ProgramData* pData = m_programs.get(program);
+ return pData ? pData->getTypeForLocation(location) : 0;
}
bool GLSharedGroup::isProgram(GLuint program)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
- return (pData!=NULL);
+ ProgramData* pData = m_programs.get(program);
+ return (pData != NULL);
}
void GLSharedGroup::setupLocationShiftWAR(GLuint program)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
+ ProgramData* pData = m_programs.get(program);
if (pData) pData->setupLocationShiftWAR();
}
-GLint GLSharedGroup::locationWARHostToApp(GLuint program, GLint hostLoc, GLint arrIndex)
+GLint GLSharedGroup::locationWARHostToApp(GLuint program,
+ GLint hostLoc,
+ GLint arrIndex)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
- if (pData) return pData->locationWARHostToApp(hostLoc, arrIndex);
- else return hostLoc;
+ ProgramData* pData = m_programs.get(program);
+ return pData ? pData->locationWARHostToApp(hostLoc, arrIndex) : hostLoc;
}
GLint GLSharedGroup::locationWARAppToHost(GLuint program, GLint appLoc)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
- if (pData) return pData->locationWARAppToHost(appLoc);
- else return appLoc;
+ ProgramData* pData = m_programs.get(program);
+ return pData ? pData->locationWARAppToHost(appLoc) : appLoc;
}
bool GLSharedGroup::needUniformLocationWAR(GLuint program)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
- if (pData) return pData->needUniformLocationWAR();
- return false;
+ ProgramData* pData = m_programs.get(program);
+ return pData ? pData->needUniformLocationWAR() : false;
}
-GLint GLSharedGroup::getNextSamplerUniform(GLuint program, GLint index, GLint* val, GLenum* target) const
+GLint GLSharedGroup::getNextSamplerUniform(GLuint program,
+ GLint index,
+ GLint* val,
+ GLenum* target) const
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
+ ProgramData* pData = m_programs.get(program);
return pData ? pData->getNextSamplerUniform(index, val, target) : -1;
}
-bool GLSharedGroup::setSamplerUniform(GLuint program, GLint appLoc, GLint val, GLenum* target)
+bool GLSharedGroup::setSamplerUniform(GLuint program,
+ GLint appLoc,
+ GLint val,
+ GLenum* target)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ProgramData* pData = m_programs.valueFor(program);
+ ProgramData* pData = m_programs.get(program);
return pData ? pData->setSamplerUniform(appLoc, val, target) : false;
}
@@ -448,44 +415,39 @@ bool GLSharedGroup::addShaderData(GLuint shader)
{
emugl::Mutex::AutoLock _lock(m_lock);
ShaderData* data = new ShaderData;
- if (data) {
- if (m_shaders.add(shader, data) < 0) {
- delete data;
- data = NULL;
- }
- data->refcount = 1;
- }
- return data != NULL;
+ data->refcount = 1;
+ m_shaders.set(shader, data);
+ return true;
}
ShaderData* GLSharedGroup::getShaderData(GLuint shader)
{
emugl::Mutex::AutoLock _lock(m_lock);
- return m_shaders.valueFor(shader);
+ ShaderData* data = m_shaders.get(shader);
+ if (data) {
+ data->refcount++;
+ }
+ return data;
}
void GLSharedGroup::unrefShaderData(GLuint shader)
{
emugl::Mutex::AutoLock _lock(m_lock);
- ssize_t idx = m_shaders.indexOfKey(shader);
- if (idx >= 0) {
- unrefShaderDataLocked(idx);
- }
+ unrefShaderDataLocked(shader);
}
-void GLSharedGroup::refShaderDataLocked(ssize_t shaderIdx)
+void GLSharedGroup::refShaderDataLocked(GLuint shader)
{
- assert(shaderIdx >= 0 && shaderIdx <= m_shaders.size());
- ShaderData* data = m_shaders.valueAt(shaderIdx);
- data->refcount++;
+ ShaderData* data = m_shaders.get(shader);
+ if (data) {
+ data->refcount++;
+ }
}
-void GLSharedGroup::unrefShaderDataLocked(ssize_t shaderIdx)
+void GLSharedGroup::unrefShaderDataLocked(GLuint shader)
{
- assert(shaderIdx >= 0 && shaderIdx <= m_shaders.size());
- ShaderData* data = m_shaders.valueAt(shaderIdx);
- if (--data->refcount == 0) {
- delete data;
- m_shaders.removeItemsAt(shaderIdx);
+ ShaderData* data = m_shaders.get(shader);
+ if (data && --data->refcount == 0) {
+ m_shaders.remove(shader);
}
}
diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h
index 02278a2..f111f99 100644
--- a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h
+++ b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h
@@ -16,6 +16,11 @@
#ifndef _GL_SHARED_GROUP_H_
#define _GL_SHARED_GROUP_H_
+#include "emugl/common/id_to_object_map.h"
+#include "emugl/common/mutex.h"
+#include "emugl/common/pod_vector.h"
+#include "emugl/common/smart_ptr.h"
+
#define GL_API
#ifndef ANDROID
#define GL_APIENTRY
@@ -30,18 +35,13 @@
#include <stdio.h>
#include <stdlib.h>
#include "ErrorLog.h"
-#include <utils/KeyedVector.h>
-#include <utils/List.h>
-#include <utils/String8.h>
#include "FixedBuffer.h"
-#include "emugl/common/mutex.h"
-#include "emugl/common/smart_ptr.h"
struct BufferData {
BufferData();
BufferData(GLsizeiptr size, void * data);
GLsizeiptr m_size;
- FixedBuffer m_fixedBuffer;
+ FixedBuffer m_fixedBuffer;
};
class ProgramData {
@@ -61,7 +61,7 @@ private:
bool m_initialized;
bool m_locShiftWAR;
- android::Vector<GLuint> m_shaders;
+ emugl::PodVector<GLuint> m_shaders;
public:
enum {
@@ -92,20 +92,22 @@ public:
};
struct ShaderData {
+#if 0 // TODO(digit): Undertand why this is never used?
typedef android::List<android::String8> StringList;
StringList samplerExternalNames;
+#endif
int refcount;
};
class GLSharedGroup {
private:
- android::DefaultKeyedVector<GLuint, BufferData*> m_buffers;
- android::DefaultKeyedVector<GLuint, ProgramData*> m_programs;
- android::DefaultKeyedVector<GLuint, ShaderData*> m_shaders;
+ emugl::IdToObjectMap<BufferData> m_buffers;
+ emugl::IdToObjectMap<ProgramData> m_programs;
+ emugl::IdToObjectMap<ShaderData> m_shaders;
mutable emugl::Mutex m_lock;
- void refShaderDataLocked(ssize_t shaderIdx);
- void unrefShaderDataLocked(ssize_t shaderIdx);
+ void refShaderDataLocked(GLuint shader);
+ void unrefShaderDataLocked(GLuint shader);
public:
GLSharedGroup();
diff --git a/emulator/opengl/shared/OpenglCodecCommon/SocketStream.cpp b/emulator/opengl/shared/OpenglCodecCommon/SocketStream.cpp
index f7a2314..3ef4c6f 100644
--- a/emulator/opengl/shared/OpenglCodecCommon/SocketStream.cpp
+++ b/emulator/opengl/shared/OpenglCodecCommon/SocketStream.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
#include "SocketStream.h"
-#include <cutils/sockets.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -53,6 +52,7 @@ SocketStream::~SocketStream()
#else
::close(m_sock);
#endif
+ m_sock = -1;
}
if (m_buf != NULL) {
free(m_buf);
@@ -140,7 +140,7 @@ const unsigned char *SocketStream::read( void *buf, size_t *inout_len)
int n;
do {
- n = recv(buf, *inout_len);
+ n = this->recv(buf, *inout_len);
} while( n < 0 && errno == EINTR );
if (n > 0) {
diff --git a/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp b/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp
index 8a6e56e..ba355ab 100644
--- a/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp
+++ b/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp
@@ -14,7 +14,8 @@
* limitations under the License.
*/
#include "TcpStream.h"
-#include <cutils/sockets.h>
+#include "emugl/common/sockets.h"
+
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -30,77 +31,48 @@
#define LISTEN_BACKLOG 4
-TcpStream::TcpStream(size_t bufSize) :
- SocketStream(bufSize)
-{
-}
+TcpStream::TcpStream(size_t bufSize) : SocketStream(bufSize) {}
TcpStream::TcpStream(int sock, size_t bufSize) :
- SocketStream(sock, bufSize)
-{
+ SocketStream(sock, bufSize) {
// disable Nagle algorithm to improve bandwidth of small
// packets which are quite common in our implementation.
-#ifdef _WIN32
- DWORD flag;
-#else
- int flag;
-#endif
- flag = 1;
- setsockopt( sock, IPPROTO_TCP, TCP_NODELAY, (const char*)&flag, sizeof(flag) );
+ emugl::socketTcpDisableNagle(sock);
}
-int TcpStream::listen(char addrstr[MAX_ADDRSTR_LEN])
-{
- m_sock = socket_loopback_server(0, SOCK_STREAM);
+int TcpStream::listen(char addrstr[MAX_ADDRSTR_LEN]) {
+ m_sock = emugl::socketTcpLoopbackServer(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);
+ int port = emugl::socketGetPort(m_sock);
+ if (port < 0) {
+ ::close(m_sock);
return int(ERR_INVALID_SOCKET);
}
- snprintf(addrstr, MAX_ADDRSTR_LEN - 1, "%hu", ntohs(addr.sin_port));
+
+ snprintf(addrstr, MAX_ADDRSTR_LEN - 1, "%hu", port);
addrstr[MAX_ADDRSTR_LEN-1] = '\0';
return 0;
}
-SocketStream * TcpStream::accept()
-{
- int clientSock = -1;
-
- while (true) {
- struct sockaddr_in addr;
- socklen_t len = sizeof(addr);
- clientSock = ::accept(m_sock, (sockaddr *)&addr, &len);
-
- if (clientSock < 0 && errno == EINTR) {
- continue;
- }
- break;
- }
+SocketStream * TcpStream::accept() {
+ int clientSock = emugl::socketAccept(m_sock);
+ if (clientSock < 0)
+ return NULL;
- TcpStream *clientStream = NULL;
-
- if (clientSock >= 0) {
- clientStream = new TcpStream(clientSock, m_bufsize);
- }
- return clientStream;
+ return new TcpStream(clientSock, m_bufsize);
}
-int TcpStream::connect(const char* addr)
-{
+int TcpStream::connect(const char* addr) {
int port = atoi(addr);
- return connect("127.0.0.1",port);
+ m_sock = emugl::socketTcpLoopbackClient(port, SOCK_STREAM);
+ return valid() ? 0 : -1;
}
int TcpStream::connect(const char* hostname, unsigned short port)
{
- m_sock = socket_network_client(hostname, port, SOCK_STREAM);
- if (!valid()) return -1;
- return 0;
+ m_sock = emugl::socketTcpClient(hostname, port, SOCK_STREAM);
+ return valid() ? 0 : -1;
}
diff --git a/emulator/opengl/shared/OpenglCodecCommon/UnixStream.cpp b/emulator/opengl/shared/OpenglCodecCommon/UnixStream.cpp
index b2eef6d..7b2f67d 100644
--- a/emulator/opengl/shared/OpenglCodecCommon/UnixStream.cpp
+++ b/emulator/opengl/shared/OpenglCodecCommon/UnixStream.cpp
@@ -14,7 +14,9 @@
* limitations under the License.
*/
#include "UnixStream.h"
-#include <cutils/sockets.h>
+
+#include "emugl/common/sockets.h"
+
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -92,7 +94,7 @@ int UnixStream::listen(char addrstr[MAX_ADDRSTR_LEN])
return -1;
}
- m_sock = socket_local_server(addrstr, ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM);
+ m_sock = emugl::socketLocalServer(addrstr, SOCK_STREAM);
if (!valid()) return int(ERR_INVALID_SOCKET);
return 0;
@@ -123,7 +125,7 @@ SocketStream * UnixStream::accept()
int UnixStream::connect(const char* addr)
{
- m_sock = socket_local_client(addr, ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM);
+ m_sock = emugl::socketLocalClient(addr, SOCK_STREAM);
if (!valid()) return -1;
return 0;