emulator: opengl: Add support for unix sockets.

This patch allows the OpenGLES rendering library to use Unix
sockets instead of TCP ones when communicating with its clients.
On certain benchmarks (e.g. 0xBench teapot), this provides a
noticeable improvement (x1.05 fps) without any other changes.

On practice, Unix sockets are faster than TCP sockets, even
local ones. Also, this introduces a moderate amount of
abstraction that will allow us to use Win32 named pipes
on Windows (where TCP sockets are much slower than they
are on Unix).

Note that by default, TCP streams are still used.
The client (emulator) must call the new API 'setStreamMode'
to change it to STREAM_MODE_UNIX between 'initLibrary' and
'startOpenglRenderer' calls.

+ Adjust callers / user appropriately.

Change-Id: I4105bbf07541f3146b50a58d1a5b51e8cf044fab
This commit is contained in:
David 'Digit' Turner
2011-09-07 14:48:42 +02:00
parent 455e444a1f
commit 3d76ec1e3c
17 changed files with 515 additions and 211 deletions

View File

@@ -16,35 +16,16 @@
#ifndef __TCP_STREAM_H
#define __TCP_STREAM_H
#include <stdlib.h>
#include "IOStream.h"
#include "SocketStream.h"
class TcpStream : public IOStream {
class TcpStream : public SocketStream {
public:
typedef enum { ERR_INVALID_SOCKET = -1000 } TcpStreamError;
explicit TcpStream(size_t bufsize = 10000);
~TcpStream();
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);
virtual int listen(unsigned short port);
virtual SocketStream *accept();
virtual int connect(unsigned short port);
int connect(const char* hostname, unsigned short port);
private:
int writeFully(const void *buf, size_t len);
private:
int m_sock;
size_t m_bufsize;
unsigned char *m_buf;
TcpStream(int sock, size_t bufSize);
};