//#define _MK_DBG_
-typedef HDC Display;
-
#define IsViewable 2
#define False 0
#define True 1
#include "mesa_glu.h"
#include "mesa_mipmap.c"
-
-static HDC active_win = 0; /* FIXME */
-static int active_win_x = 0;
-static int active_win_y = 0;
-
typedef struct
{
HGLRC context;
{
void* key;
void* value;
- void* hWnd; /* Surface?? ˤ?? Window Handle*/
- void* cDC; /*Context?? ˤ?? Dummy Window Handle*/
+ void* hWnd; /* Surface?? Ã\80§?? Window Handle*/
+ void* cDC; /*Context?? Ã\80§?? Dummy Window Handle*/
} Assoc;
#define MAX_FBCONFIG 10
#include "opengl_utils.h"
+#include "opengl_server.h"
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
Assoc association_fakecontext_visual[MAX_ASSOC_SIZE];
} ProcessStruct;
-static ProcessStruct processTab[MAX_HANDLED_PROCESS];
-
-void init_process_tab(void)
-{
- memset(processTab, 0, sizeof(processTab));
-}
-
int last_process_id = 0;
/*PIXELFORMATDESCRIPTOR* visInfo;*/
} AssocAttribListVisual;
-static int nTabAssocAttribListVisual = 0;
-static AssocAttribListVisual* tabAssocAttribListVisual = NULL;
-
-
-
-
#define ARG_TO_CHAR(x) (char)(x)
#define ARG_TO_UNSIGNED_CHAR(x) (unsigned char)(x)
#define ARG_TO_SHORT(x) (short)(x)
int display_function_call = 0;
-
-static int last_assigned_internal_num = 0;
-static int last_active_internal_num = 0;
-
static void init_gl_state(GLState* state)
{
state->textureAllocator = &state->ownTextureAllocator;
if (state->elementPointerATI) free(state->elementPointerATI);
}
-
static void _create_context(ProcessStruct* process, HGLRC ctxt, int fake_ctxt, HGLRC shareList, int fake_shareList)
{
process->glstates = realloc(process->glstates, (process->nbGLStates+1)*sizeof(GLState*));
}
}
-static int get_visual_info_from_visual_id(Display dpy, int visualid, PIXELFORMATDESCRIPTOR* rpfd)
+static int get_visual_info_from_visual_id( OGLS_Conn *pConn, int visualid, PIXELFORMATDESCRIPTOR* rpfd)
{
int i;
if( 0 < visualid )
{
- for(i=0;i<nTabAssocAttribListVisual;i++)
+ AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+ for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
{
if ( tabAssocAttribListVisual[i].visualID == visualid)
{
- DescribePixelFormat((HDC)dpy, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), rpfd);
+ DescribePixelFormat((HDC)pConn->Display, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), rpfd);
return 1;
}
}
hdc = (HDC) dpy;
int n;
- fprintf(stderr, "get_default_visual\n");
-
if ((n = DescribePixelFormat(hdc, 0, 0, NULL)) > 0)
{
int i;
if( i < n ) return i + 1;
}
- fprintf(stderr, "get_default_visual() - Error \n");
return 0;
}
-/* Surface?? ˤ?? Window ????*/
-static HDC create_swindow(HDC clientdrawable, ProcessStruct* process, int x, int y, int width, int height)
+/* Surface?? 위?? Window ????*/
+static HDC create_swindow(OGLS_Conn *pConn, HDC clientdrawable, ProcessStruct* process, int x, int y, int width, int height)
{
RECT rect;
HWND hWnd;
hDC = GetDC(hWnd);
if(hDC)
{
- active_win = hDC;
+ pConn->active_win = hDC;
ShowWindow(hWnd,SW_HIDE);
set_association_clientdrawable_serverwnd(process, (void *) clientdrawable, (void *) hWnd);
}
return hDC;
}
-/* pbuffer?? ˤ?? Window ????*/
+/* pbuffer?? 위?? Window ????*/
static HDC create_pbwindow(void *fakepbuffer, ProcessStruct* process, int x, int y, int width, int height)
{
RECT rect;
return hDC;
}
-/* context?? ˤ?? Dummy Window ????*/
+/* context?? Ã\80§?? Dummy Window ????*/
static HDC create_cwindow(int fake_ctx, ProcessStruct* process, int x, int y, int width, int height)
{
RECT rect;
return hDC;
}
-static void destroy_glwindow(HWND hWnd, HDC hDC )
+static void destroy_glwindow(OGLS_Conn *pConn, HWND hWnd, HDC hDC )
{
ReleaseDC( hWnd, hDC );
DestroyWindow(hWnd);
/*PostQuitMessage(0);*/
- if( active_win == hDC)
- active_win = 0;
+ if( pConn->active_win == hDC)
+ pConn->active_win = 0;
}
static int get_server_texture(ProcessStruct* process, unsigned int client_texture)
}
-int do_function_call(Display dpy, int func_number, int pid, long* args, char* ret_string)
+int do_function_call(OGLS_Conn *pConn, int func_number, int pid, long* args, char* ret_string)
{
char ret_char = 0;
int ret_int = 0;
const char* ret_str = NULL;
int iProcess;
ProcessStruct* process = NULL;
+ ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
for(iProcess=0;iProcess<MAX_HANDLED_PROCESS;iProcess++)
{
+ ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
if (processTab[iProcess].process_id == pid)
{
process = &processTab[iProcess];
process = &processTab[iProcess];
memset(process, 0, sizeof(ProcessStruct));
process->process_id = pid;
- process->internal_num = last_assigned_internal_num++;
+ process->internal_num = pConn->last_assigned_internal_num++;
init_gl_state(&process->default_state);
process->current_state = &process->default_state;
break;
return 0;
}
- if (process->internal_num != last_active_internal_num)
+ if (process->internal_num != pConn->last_active_internal_num)
{
wglMakeCurrent(process->current_state->drawable, process->current_state->context);
- last_active_internal_num = process->internal_num;
+ pConn->last_active_internal_num = process->internal_num;
}
process->instr_counter++;
destroy_gl_state(&process->default_state);
free(process->glstates);
- active_win = 0;
+ pConn->active_win = 0;
memmove(&processTab[iProcess], &processTab[iProcess+1], (MAX_HANDLED_PROCESS - 1 - iProcess) * sizeof(ProcessStruct));
if (!(params[0] == pos.x && params[1] == pos.y && params[2] == pos.width && params[3] == pos.height))
{
int redim = !(params[2] == pos.width && params[3] == pos.height);
- active_win_x = params[0];
- active_win_y = params[1];
+ pConn->active_win_x = params[0];
+ pConn->active_win_y = params[1];
- fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
- fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
+ //fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
+ //fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
if (redim)
{
}
else
{
- hdc = (HDC) dpy;
+ hdc = (HDC) pConn->Display;
if ((n = DescribePixelFormat(hdc, 0, 0, NULL)) > 0)
{
visualid = fbConfig->visualID;
ret_int = visualid;
- for( i = 0; i < nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
+ AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+ for( i = 0; i < pConn->nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
- if( i >= nTabAssocAttribListVisual )
+ if( i >= pConn->nTabAssocAttribListVisual )
{
- tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
+ pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+ realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = 0;
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = NULL;
- tabAssocAttribListVisual[nTabAssocAttribListVisual].visualID = visualid;
- nTabAssocAttribListVisual++;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visualID = visualid;
+ pConn->nTabAssocAttribListVisual++;
}
if (display_function_call) fprintf(stderr, "visualid = %d\n", ret_int);
if (1 || display_function_call) fprintf(stderr, "visualid=%d, fake_shareList=%d\n", visualid, fake_shareList);
- if(get_visual_info_from_visual_id(dpy, visualid, &pfd))
+ if(get_visual_info_from_visual_id(pConn, visualid, &pfd))
{
SetPixelFormat(hdc, visualid - 1, &pfd);
ctxt = wglCreateContext (hdc);
}
else
{
- if((visualid = get_default_visual(dpy, &pfd)))
+ if((visualid = get_default_visual(pConn->Display, &pfd)))
{
SetPixelFormat(hdc, visualid - 1, &pfd);
ctxt = wglCreateContext (hdc);
if( visualid == 0 )
{
- visualid = get_default_visual(dpy, &pfd);
+ visualid = get_default_visual(pConn->Display, &pfd);
}
drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
if (drawable == 0)
{
- drawable = create_swindow(client_drawable, process, 0, 0, 480, 800);
+ drawable = create_swindow(pConn, client_drawable, process, 0, 0, 480, 800);
set_association_clientdrawable_serverdrawable(process, (void*)client_drawable, (void*)drawable);
}
if (visualid)
{
- if( get_visual_info_from_visual_id(dpy, visualid, &pfd))
+ if( get_visual_info_from_visual_id(pConn, visualid, &pfd))
{
ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
}
else
{
- if( get_default_visual(dpy, &pfd))
+ if( get_default_visual(pConn->Display, &pfd))
ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
else
ret_int = GLX_BAD_VISUAL;
}
else
{
- if( get_default_visual(dpy, &pfd))
+ if( get_default_visual(pConn->Display, &pfd))
ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
else
ret_int = GLX_BAD_VISUAL;
{
PIXELFORMATDESCRIPTOR pfd;
unsigned int visualid = 0;
+ AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
int i;
if ((int*)args[2] == NULL)
ret_int = 0;
- visualid = get_default_visual(dpy, &pfd);
+ visualid = get_default_visual(pConn->Display, &pfd);
- for( i = 0; i < nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
+ for( i = 0; i < pConn->nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
- if( i >= nTabAssocAttribListVisual ) {
- tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
+ if( i >= pConn->nTabAssocAttribListVisual ) {
+ pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+ realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = 0;
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = NULL;
- tabAssocAttribListVisual[nTabAssocAttribListVisual].visualID = i;
- nTabAssocAttribListVisual++;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visualID = i;
+ pConn->nTabAssocAttribListVisual++;
}
ret_int = visualid;
if( drawable && hWnd )
{
- destroy_glwindow(hWnd, drawable);
+ destroy_glwindow(pConn, hWnd, drawable);
#if defined( _MK_DBG_ )
printf("DestoryWindw( HWND 0x%p, HDC 0x%p) Client Drawable 0x%p\n", hWnd, drawable, client_drawable);
wglDeleteContext(ctxt);
get_association_fakecontext_glxwnd(process, (void*)(long)fake_ctxt, hWnd, hdc);
- destroy_glwindow(hWnd, hdc);
+ destroy_glwindow(pConn, hWnd, hdc);
unset_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
unset_association_fakecontext_visualid(process, (void*)(long)fake_ctxt);
free(pb_info);
}
- destroy_glwindow(hWnd, pbuffer);
+ destroy_glwindow(pConn, hWnd, pbuffer);
#if defined( _MK_DBG_ )
printf("DestoryPbuffer( HWND 0x%p, HDC 0x%p) fake pbuffer 0x%p\n", hWnd, pbuffer, fakepbuffer);
#else
+#include <arpa/inet.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <mesa_glx.h>
#include "opengl_func.h"
+#include "opengl_server.h"
#include "mesa_glu.h"
#include "mesa_mipmap.c"
return vis;
}
-
-static Display* parent_dpy = NULL;
-static Window qemu_parent_window = 0;
-
-static Window active_win = 0; /* FIXME */
-static int active_win_x = 0;
-static int active_win_y = 0;
-
-void opengl_exec_set_parent_window(Display* _dpy, Window _parent_window)
+void opengl_exec_set_parent_window(OGLS_Conn *pConn, Window _parent_window)
{
- parent_dpy = _dpy;
- qemu_parent_window = _parent_window;
- if (active_win)
+ pConn->parent_dpy = pConn->Display;
+ pConn->qemu_parent_window = _parent_window;
+ if (pConn->active_win)
{
- XReparentWindow(_dpy, active_win, _parent_window, active_win_x, active_win_y);
+ XReparentWindow(pConn->Display, pConn->active_win, _parent_window, pConn->active_win_x, pConn->active_win_y);
}
}
-static int local_connection = 0;
-void opengl_exec_set_local_connection(void)
-{
- local_connection = 1;
-}
-
-static Window create_window(Display* dpy, Window local_parent_window, XVisualInfo* vis, const char *name,
+static Window create_window(OGLS_Conn *pConn, Window local_parent_window, XVisualInfo* vis, const char *name,
int x, int y, int width, int height)
{
int scrnum;
Window root;
Window win;
- scrnum = DefaultScreen( dpy );
- root = RootWindow( dpy, scrnum );
+ scrnum = DefaultScreen( pConn->Display );
+ root = RootWindow( pConn->Display, scrnum );
/* window attributes */
attr.background_pixel = 0;
attr.border_pixel = 0;
- attr.colormap = XCreateColormap( dpy, root, vis->visual, AllocNone);
+ attr.colormap = XCreateColormap( pConn->Display, root, vis->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask /*| KeyPressMask*/;
attr.save_under = True;
//if (local_parent_window == NULL && qemu_parent_window == NULL)
if (local_parent_window)
{
- win = XCreateWindow( dpy, local_parent_window, 0, 0, width, height,
+ win = XCreateWindow( pConn->Display, local_parent_window, 0, 0, width, height,
0, vis->depth, InputOutput,
vis->visual, mask, &attr );
}
- else if (qemu_parent_window)
+ else if (pConn->qemu_parent_window)
{
- win = XCreateWindow( dpy, qemu_parent_window, 0, 0, width, height,
+ win = XCreateWindow( pConn->Display, pConn->qemu_parent_window, 0, 0, width, height,
0, vis->depth, InputOutput,
vis->visual, mask, &attr );
}
else
{
- win = XCreateWindow( dpy, root, 0, 0, width, height,
+ win = XCreateWindow( pConn->Display, root, 0, 0, width, height,
0, vis->depth, InputOutput,
vis->visual, mask, &attr );
}
sizehints.width = width;
sizehints.height = height;
sizehints.flags = USSize | USPosition;
- XSetWMNormalHints(dpy, win, &sizehints);
- XSetStandardProperties(dpy, win, name, name,
+ XSetWMNormalHints(pConn->Display, win, &sizehints);
+ XSetStandardProperties(pConn->Display, win, name, name,
None, (char **)NULL, 0, &sizehints);
}
- /* Host Window?? ???? ?ʴ´?. if( win )
- XMapWindow(dpy, win);*/
+ /* Host Window?? ?琉??? ?苛쨈?. if( win )
+ XMapWindow(pConn->Display, win);*/
- XSync(dpy, 0);
+ XSync(pConn->Display, 0);
/*
int loop = 1;
while (loop) {
- while (XPending(dpy) > 0) {
+ while (XPending(pConn->Display) > 0) {
XEvent event;
- XNextEvent(dpy, &event);
+ XNextEvent(pConn->Display, &event);
switch (event.type) {
case CreateNotify:
{
}
}*/
- active_win = win;
+ pConn->active_win = win;
return win;
}
-static void destroy_window(Display* dpy, Window win )
+static void destroy_window(OGLS_Conn *pConn, Window win )
{
/*int i;*/
- XDestroyWindow(dpy, win);
+ XDestroyWindow(pConn->Display, win);
- XSync(dpy, 0);
+ XSync(pConn->Display, 0);
/*int loop = 1;
while (loop) {
- while (XPending(dpy) > 0) {
+ while (XPending(pConn->Display) > 0) {
XEvent event;
- XNextEvent(dpy, &event);
+ XNextEvent(pConn->Display, &event);
switch (event.type) {
case DestroyNotify:
{
}
}*/
- if( active_win == win)
- active_win = 0;
+ if( pConn->active_win == win)
+ pConn->active_win = 0;
}
Assoc association_fakecontext_visual[MAX_ASSOC_SIZE];
} ProcessStruct;
-static ProcessStruct processTab[MAX_HANDLED_PROCESS];
-
-void init_process_tab(void)
-{
- memset(processTab, 0, sizeof(processTab));
-}
-
int last_process_id = 0;
XVisualInfo* visInfo;
} AssocAttribListVisual;
-static int nTabAssocAttribListVisual = 0;
-static AssocAttribListVisual* tabAssocAttribListVisual = NULL;
-
static int _compute_length_of_attrib_list_including_zero(const int* attribList, int booleanMustHaveValue)
{
int i = 0;
return i + 1;
}
-static int glXChooseVisualFunc(Display* dpy, const int* _attribList)
+static int glXChooseVisualFunc( OGLS_Conn *pConn, const int* _attribList)
{
+ AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+
if (_attribList == NULL)
return 0;
int attribListLength = _compute_length_of_attrib_list_including_zero(_attribList, 0);
}
}
- for(i=0;i<nTabAssocAttribListVisual;i++)
+ for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
{
if (tabAssocAttribListVisual[i].attribListLength == attribListLength &&
memcmp(tabAssocAttribListVisual[i].attribList, attribList, attribListLength * sizeof(int)) == 0)
return (tabAssocAttribListVisual[i].visInfo) ? tabAssocAttribListVisual[i].visInfo->visualid : 0;
}
}
- XVisualInfo* visInfo = glXChooseVisual(dpy, 0, attribList);
- tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = attribListLength;
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = (int*)malloc(sizeof(int) * attribListLength);
- memcpy(tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList, attribList, sizeof(int) * attribListLength);
- tabAssocAttribListVisual[nTabAssocAttribListVisual].visInfo = visInfo;
- nTabAssocAttribListVisual++;
+ XVisualInfo* visInfo = glXChooseVisual(pConn->Display, 0, attribList);
+ pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+ realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = attribListLength;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = (int*)malloc(sizeof(int) * attribListLength);
+ memcpy(tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList, attribList, sizeof(int) * attribListLength);
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = visInfo;
+ pConn->nTabAssocAttribListVisual++;
free(attribList);
return (visInfo) ? visInfo->visualid : 0;
}
-static XVisualInfo* get_visual_info_from_visual_id(Display* dpy, int visualid)
+static XVisualInfo* get_visual_info_from_visual_id( OGLS_Conn *pConn, int visualid)
{
int i, n;
XVisualInfo template;
XVisualInfo* visInfo;
- for(i=0;i<nTabAssocAttribListVisual;i++)
+
+ AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+
+ for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
{
if (tabAssocAttribListVisual[i].visInfo &&
tabAssocAttribListVisual[i].visInfo->visualid == visualid)
}
}
template.visualid = visualid;
- visInfo = XGetVisualInfo(dpy, VisualIDMask, &template, &n);
- tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = 0;
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = NULL;
- tabAssocAttribListVisual[nTabAssocAttribListVisual].visInfo = visInfo;
- nTabAssocAttribListVisual++;
+ visInfo = XGetVisualInfo(pConn->Display, VisualIDMask, &template, &n);
+ pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+ realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = visInfo;
+ pConn->nTabAssocAttribListVisual++;
return visInfo;
}
if (state->elementPointerATI) free(state->elementPointerATI);
}
-static int last_assigned_internal_num = 0;
-static int last_active_internal_num = 0;
-
static void init_gl_state(GLState* state)
{
state->textureAllocator = &state->ownTextureAllocator;
}
}
-void _create_context(ProcessStruct* process, GLXContext ctxt, int fake_ctxt, GLXContext shareList, int fake_shareList)
+static void _create_context(ProcessStruct* process, GLXContext ctxt, int fake_ctxt, GLXContext shareList, int fake_shareList)
{
process->glstates = realloc(process->glstates, (process->nbGLStates+1)*sizeof(GLState*));
process->glstates[process->nbGLStates] = malloc(sizeof(GLState));
process->nbGLStates++;
}
-int do_function_call(Display* dpy, int func_number, int pid, long* args, char* ret_string)
+int do_function_call(OGLS_Conn *pConn, int func_number, int pid, long* args, char* ret_string)
{
char ret_char = 0;
int ret_int = 0;
const char* ret_str = NULL;
int iProcess;
ProcessStruct* process = NULL;
+ ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
- if (parent_dpy)
+ if (pConn->parent_dpy)
{
- dpy = parent_dpy;
+ pConn->Display = pConn->parent_dpy;
}
for(iProcess=0;iProcess<MAX_HANDLED_PROCESS;iProcess++)
{
+ ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
if (processTab[iProcess].process_id == pid)
{
process = &processTab[iProcess];
process = &processTab[iProcess];
memset(process, 0, sizeof(ProcessStruct));
process->process_id = pid;
- process->internal_num = last_assigned_internal_num++;
+ process->internal_num = pConn->last_assigned_internal_num++;
init_gl_state(&process->default_state);
process->current_state = &process->default_state;
break;
fprintf(stderr, "Too many processes !\n");
return 0;
}
- if (process->internal_num != last_active_internal_num)
+ if (process->internal_num != pConn->last_active_internal_num)
{
- glXMakeCurrent(dpy, process->current_state->drawable, process->current_state->context);
- last_active_internal_num = process->internal_num;
+ glXMakeCurrent(pConn->Display, process->current_state->drawable, process->current_state->context);
+ pConn->last_active_internal_num = process->internal_num;
}
process->instr_counter++;
+
if (display_function_call) fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
+ //fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
switch (func_number)
{
for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
{
GLXContext ctxt = process->association_fakecontext_glxcontext[i].value;
- fprintf(stderr, "Destroy context corresponding to fake_context = %ld\n",
- (long)process->association_fakecontext_glxcontext[i].key);
- glXDestroyContext(dpy, ctxt);
+ //fprintf(stderr, "Destroy context corresponding to fake_context = %ld\n",
+ // (long)process->association_fakecontext_glxcontext[i].key);
+ glXDestroyContext(pConn->Display, ctxt);
}
GET_EXT_PTR(void, glXDestroyPbuffer, (Display*, GLXPbuffer));
GLXPbuffer pbuffer = (GLXPbuffer)process->association_fakepbuffer_pbuffer[i].value;
fprintf(stderr, "Destroy pbuffer corresponding to fake_pbuffer = %ld\n",
(long)process->association_fakepbuffer_pbuffer[i].key);
- if (!is_gl_vendor_ati(dpy))
- ptr_func_glXDestroyPbuffer(dpy, pbuffer);
+ if (!is_gl_vendor_ati(pConn->Display))
+ ptr_func_glXDestroyPbuffer(pConn->Display, pbuffer);
}
for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
{
- fprintf(stderr, "Destroy window corresponding to client_drawable = %p\n",
- process->association_clientdrawable_serverdrawable[i].key);
+ //fprintf(stderr, "Destroy window corresponding to client_drawable = %p\n",
+ // process->association_clientdrawable_serverdrawable[i].key);
Window win = (Window)process->association_clientdrawable_serverdrawable[i].value;
- XDestroyWindow(dpy, win);
+ XDestroyWindow(pConn->Display, win);
int loop = 1;
while (loop) {
- while (XPending(dpy) > 0) {
+ while (XPending(pConn->Display) > 0) {
XEvent event;
- XNextEvent(dpy, &event);
+ XNextEvent(pConn->Display, &event);
switch (event.type) {
case DestroyNotify:
{
destroy_gl_state(&process->default_state);
free(process->glstates);
- active_win = 0;
+ pConn->active_win = 0;
memmove(&processTab[iProcess], &processTab[iProcess+1], (MAX_HANDLED_PROCESS - 1 - iProcess) * sizeof(ProcessStruct));
if (args[1] == IsViewable)
{
WindowPosStruct pos;
- _get_window_pos(dpy, drawable, &pos);
+ _get_window_pos(pConn->Display, drawable, &pos);
if (pos.map_state != args[1])
{
- XMapWindow(dpy, drawable);
+ XMapWindow(pConn->Display, drawable);
int loop = 0; //1;
while (loop) {
- while (XPending(dpy) > 0) {
+ while (XPending(pConn->Display) > 0) {
XEvent event;
- XNextEvent(dpy, &event);
+ XNextEvent(pConn->Display, &event);
switch (event.type) {
case ConfigureNotify:
{
if (drawable)
{
WindowPosStruct pos;
- _get_window_pos(dpy, drawable, &pos);
+ _get_window_pos(pConn->Display, drawable, &pos);
if (!(params[0] == pos.x && params[1] == pos.y && params[2] == pos.width && params[3] == pos.height))
{
int redim = !(params[2] == pos.width && params[3] == pos.height);
- active_win_x = params[0];
- active_win_y = params[1];
+ pConn->active_win_x = params[0];
+ pConn->active_win_y = params[1];
/*
fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
*/
- XMoveResizeWindow(dpy, drawable, params[0], params[1], params[2], params[3]);
- _get_window_pos(dpy, drawable, &pos);
+ XMoveResizeWindow(pConn->Display, drawable, params[0], params[1], params[2], params[3]);
+ _get_window_pos(pConn->Display, drawable, &pos);
process->currentDrawablePos = pos;
//if (getenv("FORCE_GL_VIEWPORT"))
if (redim)
glViewport(0, 0, params[2], params[3]);
int loop = 0; //1;
while (loop) {
- while (XPending(dpy) > 0) {
+ while (XPending(pConn->Display) > 0) {
XEvent event;
- XNextEvent(dpy, &event);
+ XNextEvent(pConn->Display, &event);
switch (event.type) {
case ConfigureNotify:
{
case glXChooseVisual_func:
{
- ret_int = glXChooseVisualFunc(dpy, (int*)args[2]);
+ ret_int = glXChooseVisualFunc(pConn, (int*)args[2]);
break;
}
case glXQueryExtensionsString_func:
{
- ret_str = glXQueryExtensionsString(dpy, 0);
+ ret_str = glXQueryExtensionsString(pConn->Display, 0);
break;
}
case glXQueryServerString_func:
{
- ret_str = glXQueryServerString(dpy, 0, args[2]);
+ ret_str = glXQueryServerString(pConn->Display, 0, args[2]);
break;
}
case glXGetClientString_func:
{
- ret_str = glXGetClientString(dpy, args[1]);
+ ret_str = glXGetClientString(pConn->Display, args[1]);
break;
}
case glXGetScreenDriver_func:
{
GET_EXT_PTR(const char*, glXGetScreenDriver, (Display* , int ));
- ret_str = ptr_func_glXGetScreenDriver(dpy, 0);
+ ret_str = ptr_func_glXGetScreenDriver(pConn->Display, 0);
break;
}
if (1 || display_function_call) fprintf(stderr, "visualid=%d, fake_shareList=%d\n", visualid, fake_shareList);
GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
- XVisualInfo* vis = get_visual_info_from_visual_id(dpy, visualid);
+ XVisualInfo* vis = get_visual_info_from_visual_id(pConn, visualid);
GLXContext ctxt;
if (vis)
{
- ctxt = glXCreateContext(dpy, vis, shareList, args[3]);
+ ctxt = glXCreateContext(pConn->Display, vis, shareList, args[3]);
}
else
{
- vis = get_default_visual(dpy);
+ vis = get_default_visual(pConn->Display);
int saved_visualid = vis->visualid;
vis->visualid = (visualid) ? visualid : saved_visualid;
- ctxt = glXCreateContext(dpy, vis, shareList, args[3]);
+ ctxt = glXCreateContext(pConn->Display, vis, shareList, args[3]);
vis->visualid = saved_visualid;
}
GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
process->next_available_context_number ++;
int fake_ctxt = process->next_available_context_number;
- GLXContext ctxt = ptr_func_glXCreateNewContext(dpy, fbconfig, args[2], shareList, args[4]);
+ GLXContext ctxt = ptr_func_glXCreateNewContext(pConn->Display, fbconfig, args[2], shareList, args[4]);
set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
- vis = ptr_func_glXGetVisualFromFBConfig(dpy, fbconfig); /* visual info ????*/
+ vis = ptr_func_glXGetVisualFromFBConfig(pConn->Display, fbconfig); /* visual info ????*/
set_association_fakecontext_visual(process, (void *)(long)fake_ctxt, vis);
ret_int = fake_ctxt;
}
else
{
- glXCopyContext(dpy, src_ctxt, dst_ctxt, args[3]);
+ glXCopyContext(pConn->Display, src_ctxt, dst_ctxt, args[3]);
}
break;
}
}
}
- glXDestroyContext(dpy, ctxt);
+ glXDestroyContext(pConn->Display, ctxt);
unset_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
break;
case glXQueryVersion_func:
{
- ret_int = glXQueryVersion(dpy, (int*)args[1], (int*)args[2]);
+ ret_int = glXQueryVersion(pConn->Display, (int*)args[1], (int*)args[2]);
break;
}
if (client_drawable == 0 && fake_ctxt == 0)
{
- ret_int = glXMakeCurrent(dpy, 0, NULL);
+ ret_int = glXMakeCurrent(pConn->Display, 0, NULL);
process->current_state = &process->default_state;
}
else if ((drawable = (GLXDrawable)get_association_fakepbuffer_pbuffer(process, (void*)client_drawable)))
}
else
{
- ret_int = glXMakeCurrent(dpy, drawable, ctxt);
+ ret_int = glXMakeCurrent(pConn->Display, drawable, ctxt);
}
}
else
{
XVisualInfo* vis = (XVisualInfo*)get_association_fakecontext_visual(process, (void*)(long)fake_ctxt);
if (vis == NULL)
- vis = get_default_visual(dpy);
- /*if (local_connection)
+ vis = get_default_visual(pConn->Display);
+ /*if (pConn->local_connection)
drawable = client_drawable;
else*/
{
- if (/*local_connection &&*/ client_drawable == RootWindow(dpy, 0))
+ if (/*pConn->local_connection &&*/ client_drawable == RootWindow(pConn->Display, 0))
{
drawable = client_drawable;
}
else
{
- drawable = create_window(dpy, (local_connection) ? (Window)client_drawable : 0, vis, "", 0, 0, 480, 800);/* Default Window ũ?⸦ Simulator ũ???? ?????Ѵ?.*/
+ drawable = create_window(pConn, (pConn->local_connection) ? (Window)client_drawable : 0, vis, "", 0, 0, 480, 800);/* Default Window 크?綬�Simulator 크???? ?????磯?.*/
}
//fprintf(stderr, "creating window\n");
}
set_association_clientdrawable_serverdrawable(process, (void*)client_drawable, (void*)drawable);
}
- ret_int = glXMakeCurrent(dpy, drawable, ctxt);
+ ret_int = glXMakeCurrent(pConn->Display, drawable, ctxt);
}
}
}
else
{
- if (client_cursor.pixels && local_connection == 0)
+ if (client_cursor.pixels && pConn->local_connection == 0)
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushClientAttrib(GL_ALL_ATTRIB_BITS);
glPopAttrib();
}
- glXSwapBuffers(dpy, drawable);
+ glXSwapBuffers(pConn->Display, drawable);
}
break;
}
}
else
{
- ret_char = glXIsDirect(dpy, ctxt);
+ ret_char = glXIsDirect(pConn->Display, ctxt);
}
break;
}
int visualid = args[1];
XVisualInfo* vis = NULL;
if (visualid)
- vis = get_visual_info_from_visual_id(dpy, visualid);
+ vis = get_visual_info_from_visual_id(pConn, visualid);
if (vis == NULL)
- vis = get_default_visual(dpy);
- ret_int = glXGetConfig(dpy, vis, args[2], (int*)args[3]);
+ vis = get_default_visual(pConn->Display);
+ ret_int = glXGetConfig(pConn->Display, vis, args[2], (int*)args[3]);
break;
}
int* res = (int*)args[5];
if (visualid)
- vis = get_visual_info_from_visual_id(dpy, visualid);
+ vis = get_visual_info_from_visual_id(pConn, visualid);
if (vis == NULL)
- vis = get_default_visual(dpy);
+ vis = get_default_visual(pConn->Display);
for(i=0;i<n;i++)
{
- res[i] = glXGetConfig(dpy, vis, attribs[i], &values[i]);
+ res[i] = glXGetConfig(pConn->Display, vis, attribs[i], &values[i]);
}
break;
}
case glXQueryExtension_func:
{
- ret_int = glXQueryExtension(dpy, (int*)args[1], (int*)args[2]);
+ ret_int = glXQueryExtension(pConn->Display, (int*)args[1], (int*)args[2]);
break;
}
}
else
{
- GLXFBConfig* fbconfigs = ptr_func_glXChooseFBConfig(dpy, args[1], (int*)args[2], (int*)args[3]);
+ GLXFBConfig* fbconfigs = ptr_func_glXChooseFBConfig(pConn->Display, args[1], (int*)args[2], (int*)args[3]);
if (fbconfigs)
{
process->fbconfigs[process->nfbconfig] = fbconfigs;
}
else
{
- GLXFBConfigSGIX* fbconfigs = ptr_func_glXChooseFBConfigSGIX(dpy, args[1], (int*)args[2], (int*)args[3]);
+ GLXFBConfigSGIX* fbconfigs = ptr_func_glXChooseFBConfigSGIX(pConn->Display, args[1], (int*)args[2], (int*)args[3]);
if (fbconfigs)
{
process->fbconfigs[process->nfbconfig] = fbconfigs;
}
else
{
- GLXFBConfig* fbconfigs = ptr_func_glXGetFBConfigs(dpy, args[1], (int*)args[2]);
+ GLXFBConfig* fbconfigs = ptr_func_glXGetFBConfigs(pConn->Display, args[1], (int*)args[2]);
if (fbconfigs)
{
process->fbconfigs[process->nfbconfig] = fbconfigs;
GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
- destroy_window(dpy, (Window)drawable);
+ destroy_window(pConn, (Window)drawable);
int i;
for(i=0;process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
if (fbconfig)
{
- GLXPbuffer pbuffer = ptr_func_glXCreatePbuffer(dpy, fbconfig, (int*)args[2]);
+ GLXPbuffer pbuffer = ptr_func_glXCreatePbuffer(pConn->Display, fbconfig, (int*)args[2]);
fprintf(stderr, "glXCreatePbuffer --> %X\n", (int)pbuffer);
if (pbuffer)
{
GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
if (fbconfig)
{
- GLXPbufferSGIX pbuffer = ptr_func_glXCreateGLXPbufferSGIX(dpy, fbconfig, args[2], args[3], (int*)args[4]);
+ GLXPbufferSGIX pbuffer = ptr_func_glXCreateGLXPbufferSGIX(pConn->Display, fbconfig, args[2], args[3], (int*)args[4]);
if (pbuffer)
{
process->next_available_pbuffer_number ++;
}
else
{
- if (!is_gl_vendor_ati(dpy))
- ptr_func_glXDestroyPbuffer(dpy, pbuffer);
+ if (!is_gl_vendor_ati(pConn->Display))
+ ptr_func_glXDestroyPbuffer(pConn->Display, pbuffer);
unset_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
}
break;
}
else
{
- if (!is_gl_vendor_ati(dpy))
- ptr_func_glXDestroyGLXPbufferSGIX(dpy, pbuffer);
+ if (!is_gl_vendor_ati(pConn->Display))
+ ptr_func_glXDestroyGLXPbufferSGIX(pConn->Display, pbuffer);
unset_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
}
break;
}
else
{
- ptr_func_glXBindTexImageATI(dpy, pbuffer, args[2]);
+ ptr_func_glXBindTexImageATI(pConn->Display, pbuffer, args[2]);
}
break;
}
}
else
{
- ptr_func_glXReleaseTexImageATI(dpy, pbuffer, args[2]);
+ ptr_func_glXReleaseTexImageATI(pConn->Display, pbuffer, args[2]);
}
break;
}
}
else
{
- ret_int = ptr_func_glXBindTexImageARB(dpy, pbuffer, args[2]);
+ ret_int = ptr_func_glXBindTexImageARB(pConn->Display, pbuffer, args[2]);
}
break;
}
}
else
{
- ret_int = ptr_func_glXReleaseTexImageARB(dpy, pbuffer, args[2]);
+ ret_int = ptr_func_glXReleaseTexImageARB(pConn->Display, pbuffer, args[2]);
}
break;
}
ret_int = 0;
GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
if (fbconfig)
- ret_int = ptr_func_glXGetFBConfigAttrib(dpy, fbconfig, args[2], (int*)args[3]);
+ ret_int = ptr_func_glXGetFBConfigAttrib(pConn->Display, fbconfig, args[2], (int*)args[3]);
break;
}
{
if (fbconfig)
{
- res[i] = ptr_func_glXGetFBConfigAttrib(dpy, fbconfig, attribs[i], &values[i]);
+ res[i] = ptr_func_glXGetFBConfigAttrib(pConn->Display, fbconfig, attribs[i], &values[i]);
}
else
{
ret_int = 0;
GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
if (fbconfig)
- ret_int = ptr_func_glXGetFBConfigAttribSGIX(dpy, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
+ ret_int = ptr_func_glXGetFBConfigAttribSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
break;
}
}
else
{
- ret_int = ptr_func_glXQueryContext(dpy, ctxt, args[2], (int*)args[3]);
+ ret_int = ptr_func_glXQueryContext(pConn->Display, ctxt, args[2], (int*)args[3]);
}
break;
}
}
else
{
- ptr_func_glXQueryDrawable(dpy, drawable, args[2], (int*)args[3]);
+ ptr_func_glXQueryDrawable(pConn->Display, drawable, args[2], (int*)args[3]);
}
break;
}
ret_int = 0;
GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
if (fbconfig)
- ret_int = ptr_func_glXQueryGLXPbufferSGIX(dpy, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
+ ret_int = ptr_func_glXQueryGLXPbufferSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
break;
}
GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)args[3]);
process->next_available_context_number ++;
int fake_ctxt = process->next_available_context_number;
- GLXContext ctxt = ptr_func_glXCreateContextWithConfigSGIX(dpy, (GLXFBConfigSGIX)fbconfig, args[2], shareList, args[4]);
+ GLXContext ctxt = ptr_func_glXCreateContextWithConfigSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], shareList, args[4]);
set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
ret_int = fake_ctxt;
}
GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
if (fbconfig)
{
- XVisualInfo* vis = ptr_func_glXGetVisualFromFBConfig(dpy, fbconfig);
+ AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
+ XVisualInfo* vis = ptr_func_glXGetVisualFromFBConfig(pConn->Display, fbconfig);
ret_int = (vis) ? vis->visualid : 0;
if (vis)
{
- tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (nTabAssocAttribListVisual+1));
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribListLength = 0;
- tabAssocAttribListVisual[nTabAssocAttribListVisual].attribList = NULL;
- tabAssocAttribListVisual[nTabAssocAttribListVisual].visInfo = vis;
- nTabAssocAttribListVisual++;
+ pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
+ realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
+ tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = vis;
+ pConn->nTabAssocAttribListVisual++;
+ pConn->tabAssocAttribListVisual = tabAssocAttribListVisual;
}
if (display_function_call) fprintf(stderr, "visualid = %d\n", ret_int);
}
case glGetIntegerv_func:
{
glGetIntegerv(args[0], (int*)args[1]);
- fprintf(stderr,"glGetIntegerv(%X)=%d\n", (int)args[0], *(int*)args[1]);
+ //fprintf(stderr,"glGetIntegerv(%X)=%d\n", (int)args[0], *(int*)args[1]);
break;
}
return ret_int;
}
-
#endif
+void create_process_tab( OGLS_Conn *pConn )
+{
+ if (pConn == NULL) {
+ fprintf(stderr, "create_process_tab: pConn is NULL.\n");
+ return;
+ }
+ pConn->processTab = malloc( sizeof(ProcessStruct)*MAX_HANDLED_PROCESS );
+ if( !pConn->processTab )
+ {
+ perror( "init_process_tab" );
+ return ;
+ }
+
+ memset(pConn->processTab, 0, sizeof(ProcessStruct)*MAX_HANDLED_PROCESS );
+}
+
+void remove_process_tab( OGLS_Conn *pConn )
+{
+ if( !pConn->processTab ) return ;
+ free( pConn->processTab );
+ pConn->processTab = NULL;
+}
*/
/* gcc -Wall -O2 -g opengl_server.c opengl_exec.c -o opengl_server -I../i386-softmmu -I. -I.. -lGL */
+/* gcc -g -o opengl_server opengl_server.c opengl_exec.c -I../i386-softmmu -I. -I.. -I/c/mingw/include -lopengl32 -lws2_32 -lgdi32 -lpthread */
#include <stdio.h>
-#include <errno.h>
#include <stdlib.h>
-#include <unistd.h>
#include <string.h>
#include <assert.h>
+#include <pthread.h>
+
+#ifdef _WIN32 // or __MINGW32__
+ #include <windows.h>
+// #include <winsock2.h>
+#else // _WIN32
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <arpa/inet.h>
#include <sys/time.h>
-#include <signal.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
+ #include <unistd.h>
+ #include <arpa/inet.h>
+ #include <errno.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netinet/tcp.h>
+ #include <netdb.h>
+ #include <signal.h>
-#define PORT 5555
+ #include <X11/Xlib.h>
+ #include <X11/Xutil.h>
+
+#endif // _WIN32
+#define PORT 5555
#define ENABLE_GL_LOG
#include "opengl_func.h"
#include "opengl_utils.h"
-
-static int refresh_rate = 1000;
-static int must_save = 0;
-static int timestamp = 1; /* only valid if must_save == 1. include timestamps in the save file to enable real-time playback */
+#include "opengl_server.h"
extern int display_function_call;
-extern void init_process_tab(void);
-extern int do_function_call(Display*, int, int, long*, char*);
-extern void opengl_exec_set_local_connection(void);
-extern void opengl_exec_set_parent_window(Display* _dpy, Window _parent_window);
+
+#ifdef _WIN32
+HWND displayHWND;
+static Display CreateDisplay(void)
+ {
+ HWND hWnd;
+ WNDCLASS wc;
+ LPSTR ClassName ="DISPLAY";
+ HINSTANCE hInstance = 0;
+
+ /* only register the window class once - use hInstance as a flag. */
+ hInstance = GetModuleHandle(NULL);
+ wc.style = CS_OWNDC;
+ wc.lpfnWndProc = (WNDPROC)DefWindowProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = hInstance;
+ wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = NULL;
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = ClassName;
+
+ RegisterClass(&wc);
+
+ displayHWND = CreateWindow(ClassName, ClassName, (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU ),
+ 0, 0, 10, 10, NULL, (HMENU)NULL, hInstance, NULL);
+
+
+ ShowWindow(hWnd, SW_HIDE);
+
+ return GetDC(displayHWND);
+}
+#else
+extern void opengl_exec_set_parent_window(OGLS_Conn *pConn, Window _parent_window);
+#endif // _WIN32
#ifdef ENABLE_GL_LOG
static FILE* f = NULL;
-static char* filename = "/tmp/debug_gl.bin";
+static const char* filename = "/tmp/debug_gl.bin";
#define write_gl_debug_init() do { if (f == NULL) f = fopen(filename, "wb"); } while(0)
-static void inline write_gl_debug_cmd_char(char my_int)
+inline static void write_gl_debug_cmd_char(char my_int)
{
write_gl_debug_init();
fwrite(&my_int, sizeof(my_int), 1, f);
}
-static void inline write_gl_debug_cmd_short(short my_int)
+inline static void write_gl_debug_cmd_short(short my_int)
{
write_gl_debug_init();
fwrite(&my_int, sizeof(my_int), 1, f);
}
-static void inline write_gl_debug_cmd_int(int my_int)
+inline static void write_gl_debug_cmd_int(int my_int)
{
write_gl_debug_init();
fwrite(&my_int, sizeof(my_int), 1, f);
}
-static void inline write_gl_debug_cmd_longlong(long long my_longlong)
+inline static void write_gl_debug_cmd_longlong(long long my_longlong)
{
write_gl_debug_init();
fwrite(&my_longlong, sizeof(my_longlong), 1, f);
}
-static void inline write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
+inline static void write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
{
write_gl_debug_init();
fwrite(&size, sizeof(int), 1, f);
fwrite(buffer, size, 1, f);
}
-static void inline write_gl_debug_cmd_buffer_without_size(int size, void* buffer)
+inline static void write_gl_debug_cmd_buffer_without_size(int size, void* buffer)
{
write_gl_debug_init();
if (size)
fwrite(buffer, size, 1, f);
}
-static void inline write_gl_debug_end()
+inline static void write_gl_debug_end(void)
{
write_gl_debug_init();
fclose(f);
#endif
-static void write_sock_data(int sock, void* data, int len)
+static int write_sock_data(int sock, void* data, int len)
{
+ int offset = 0;
+
if (len && data)
{
- int offset = 0;
while(offset < len)
{
int nwritten = write(sock, data + offset, len - offset);
if (nwritten == -1)
{
+#ifndef _WIN32
if (errno == EINTR)
continue;
+#endif
perror("write");
- assert(nwritten != -1);
+ //assert(nwritten != -1);
+ return -1;
}
offset += nwritten;
}
}
+
+ return offset;
}
-static void inline write_sock_int(int sock, int my_int)
+inline static int write_sock_int(int sock, int my_int)
{
- write_sock_data(sock, &my_int, sizeof(int));
+ return write_sock_data(sock, &my_int, sizeof(int));
}
static int total_read = 0;
int nread = read(sock, data + offset, len - offset);
if (nread == -1)
{
+#ifndef _WIN32
if (errno == EINTR)
continue;
+#endif
perror("read");
- assert(nread != -1);
+ //assert(nread != -1);
}
if (nread == 0)
{
- fprintf(stderr, "nread = 0\n");
+ //fprintf(stderr, "nread = 0\n");
+ }
+ //assert(nread > 0);
+ if (nread > 0)
+ {
+ offset += nread;
+ total_read += nread;
}
- assert(nread > 0);
- offset += nread;
- total_read += nread;
}
}
}
-static int inline read_sock_int(int sock)
+inline static int read_sock_int(int sock)
{
int ret;
read_sock_data(sock, &ret, sizeof(int));
return ret;
}
-static short inline read_sock_short(int sock)
+inline static short read_sock_short(int sock)
{
short ret;
read_sock_data(sock, &ret, sizeof(short));
return ret;
}
-
-static Display* dpy = NULL;
-static int parent_xid = -1;
-
-
-static struct timeval last_time, current_time, time_stamp_start;
-static int count_last_time = 0, count_current = 0;
-
-static struct timeval last_read_time, current_read_time;
-
-int has_x_error = 0;
-
-int read_from_client (int sock)
+static int OGLS_readConn( OGLS_Conn *pConn )
{
+ int sock = pConn->sock;
long args[50];
int args_size[50];
char ret_string[32768];
char command_buffer[65536*16];
- if (dpy == NULL)
+ if( pConn->Display == NULL )
{
- init_process_tab();
- dpy = XOpenDisplay(NULL);
- if (parent_xid != -1)
+ create_process_tab(pConn);
+#ifdef _WIN32
+ pConn->Display = CreateDisplay();
+#else
+ pConn->Display = XOpenDisplay(NULL);
+ if (pConn->pOption->parent_xid != -1)
{
- opengl_exec_set_parent_window(dpy, parent_xid);
+ opengl_exec_set_parent_window(pConn, pConn->pOption->parent_xid);
}
+#endif // _WIN32
}
int i;
read_sock_data(sock, command_buffer, command_buffer_size);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(_serialized_calls_func);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_short(_serialized_calls_func);
#endif
while(commmand_buffer_offset < command_buffer_size)
fprintf(stderr, "func_number >= 0 && func_number < GL_N_CALLS failed at "
"commmand_buffer_offset=%d (command_buffer_size=%d)\n",
commmand_buffer_offset, command_buffer_size);
- exit(-1);
+ //exit(-1);
+ return -1;
}
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(func_number);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_short(func_number);
#endif
commmand_buffer_offset += sizeof(short);
{
args[i] = *(int*)(command_buffer + commmand_buffer_offset);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_char(args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_char(args[i]);
#endif
commmand_buffer_offset += sizeof(int);
break;
{
args[i] = *(int*)(command_buffer + commmand_buffer_offset);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_short(args[i]);
#endif
commmand_buffer_offset += sizeof(int);
break;
{
args[i] = *(int*)(command_buffer + commmand_buffer_offset);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_int(args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_int(args[i]);
#endif
commmand_buffer_offset += sizeof(int);
break;
}
}
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
#endif
commmand_buffer_offset += args_size[i];
args_size[i] = compute_arg_length(stderr, func_number, i, args);
args[i] = (args_size[i]) ? (long)(command_buffer + commmand_buffer_offset) : 0;
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
#endif
commmand_buffer_offset += args_size[i];
break;
args[i] = (long)(command_buffer + commmand_buffer_offset);
args_size[i] = tab_args_type_length[args_type[i]];
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
#endif
commmand_buffer_offset += tab_args_type_length[args_type[i]];
break;
}
if (display_function_call) display_gl_call(stderr, func_number, args, args_size);
-
- do_function_call(dpy, func_number, 1, args, ret_string);
+ do_function_call(pConn, func_number, 1, args, ret_string);
}
}
else
{
#ifdef ENABLE_GL_LOG
- if (must_save && func_number != _synchronize_func) write_gl_debug_cmd_short(func_number);
+ if (pConn->pOption->must_save && func_number != _synchronize_func) write_gl_debug_cmd_short(func_number);
#endif
for(i=0;i<nb_args;i++)
case TYPE_CHAR:
args[i] = read_sock_int(sock);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_char(args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_char(args[i]);
#endif
break;
case TYPE_SHORT:
args[i] = read_sock_int(sock);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_short(args[i]);
#endif
break;
case TYPE_FLOAT:
args[i] = read_sock_int(sock);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_int(args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_int(args[i]);
#endif
break;
}
}
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
#endif
break;
}
args[i] = (args_size[i]) ? (long)malloc(args_size[i]) : 0;
read_sock_data(sock, (void*)args[i], args_size[i]);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
#endif
break;
}
}
//fprintf(stderr, "%p %d\n", (void*)args[i], args_size[i]);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_int(args_size[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_int(args_size[i]);
#endif
break;
}
args[i] = (long)malloc(args_size[i]);
read_sock_data(sock, (void*)args[i], args_size[i]);
#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
+ if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
#endif
break;
if (getenv("ALWAYS_FLUSH")) fflush(f);
- int ret = do_function_call(dpy, func_number, 1, args, ret_string);
+ int ret = do_function_call(pConn, func_number, 1, args, ret_string);
#ifdef ENABLE_GL_LOG
- if (must_save && func_number == glXGetVisualFromFBConfig_func)
+ if (pConn->pOption->must_save && func_number == glXGetVisualFromFBConfig_func)
{
write_gl_debug_cmd_int(ret);
}
CASE_OUT_POINTERS:
//fprintf(stderr, "%p %d\n", (void*)args[i], args_size[i]);
- write_sock_data(sock, (void*)args[i], args_size[i]);
+ if( 0> write_sock_data(sock, (void*)args[i], args_size[i]) )
+ {
+ perror( "write_sock_data" ) ;
+ return -1 ;
+ }
+
if (display_function_call)
{
if (args_type[i] == TYPE_OUT_1INT)
if (signature->ret_type == TYPE_CONST_CHAR)
{
- write_sock_int(sock, strlen(ret_string) + 1);
- write_sock_data(sock, ret_string, strlen(ret_string) + 1);
+ if( 0 > write_sock_int(sock, strlen(ret_string) + 1) )
+ {
+ perror( "write_sock_int" ) ;
+ return -1 ;
+ }
+ if( 0 > write_sock_data(sock, ret_string, strlen(ret_string) + 1) )
+ {
+ perror( "write_sock_data" ) ;
+ return -1 ;
+ }
}
else if (signature->ret_type != TYPE_NONE)
{
- write_sock_int(sock, ret);
+ if( 0 > write_sock_int(sock, ret) )
+ {
+ perror( "write_sock_int" ) ;
+ return -1 ;
+ }
}
#ifdef ENABLE_GL_LOG
- if (must_save && func_number == _exit_process_func)
+ if (pConn->pOption->must_save && func_number == _exit_process_func)
{
write_gl_debug_end();
}
else if (func_number == glXSwapBuffers_func)
{
int diff_time;
- count_current++;
- gettimeofday(¤t_time, NULL);
+ pConn->count_current++;
+ gettimeofday(&pConn->current_time, NULL);
#ifdef ENABLE_GL_LOG
- if (must_save && timestamp)
+ if (pConn->pOption->must_save && pConn->pOption->timestamp)
{
- long long ts = (current_time.tv_sec - time_stamp_start.tv_sec) * (long long)1000000 + current_time.tv_usec - time_stamp_start.tv_usec;
+ long long ts = (pConn->current_time.tv_sec - pConn->time_stamp_start.tv_sec) * (long long)1000000 + pConn->current_time.tv_usec - pConn->time_stamp_start.tv_usec;
/* -1 is special code that indicates time synchro */
write_gl_debug_cmd_short(timesynchro_func);
write_gl_debug_cmd_longlong(ts);
}
#endif
- diff_time = (current_time.tv_sec - last_time.tv_sec) * 1000 + (current_time.tv_usec - last_time.tv_usec) / 1000;
- if (diff_time > refresh_rate)
+ diff_time = (pConn->current_time.tv_sec - pConn->last_time.tv_sec) * 1000 + (pConn->current_time.tv_usec - pConn->last_time.tv_usec) / 1000;
+ if (diff_time > pConn->pOption->refresh_rate)
{
#ifdef ENABLE_GL_LOG
fflush(f);
#endif
printf("%d frames in %.1f seconds = %.3f FPS\n",
- count_current - count_last_time,
+ pConn->count_current - pConn->count_last_time,
diff_time / 1000.,
- (count_current - count_last_time) * 1000. / diff_time);
- last_time.tv_sec = current_time.tv_sec;
- last_time.tv_usec = current_time.tv_usec;
- count_last_time = count_current;
+ (pConn->count_current - pConn->count_last_time) * 1000. / diff_time);
+ pConn->last_time.tv_sec = pConn->current_time.tv_sec;
+ pConn->last_time.tv_usec = pConn->current_time.tv_usec;
+ pConn->count_last_time = pConn->count_current;
}
}
}
return 0;
}
-int make_socket (uint16_t port)
+static int OGLS_createListenSocket (uint16_t port)
{
int sock;
struct sockaddr_in name;
if (sock < 0)
{
perror ("socket");
- exit (EXIT_FAILURE);
+ //exit (EXIT_FAILURE);
+ return -1;
}
int flag = 1;
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
{
+ fprintf(stderr, "bind: errorno = %d\n", errno);
perror ("bind");
- exit (EXIT_FAILURE);
+ //exit (EXIT_FAILURE);
+ return -1;
}
return sock;
}
-static int x_error_handler(Display *display,
- XErrorEvent *error)
+static OGLS_Conn * OGLS_createConn( OGLS_Opts *pOption )
+{
+ OGLS_Conn *pConn = malloc(sizeof(OGLS_Conn));
+ if( !pConn )
+ {
+ return NULL ;
+ }
+
+ memset( pConn, 0, sizeof(*pConn) );
+ pConn->pOption = pOption;
+ return pConn;
+}
+
+static void OGLS_removeConn( OGLS_Conn *pConn )
+{
+ if( !pConn ) return ;
+
+ if( pConn->sock > 0 )
+ {
+ closesocket(pConn->sock);
+ pConn->sock = 0 ;
+ }
+
+ if( pConn->Display )
+ {
+#ifdef _WIN32
+// ReleaseDC(pConn->Display);
+#else
+ XCloseDisplay( pConn->Display );
+ pConn->Display = NULL;
+#endif // _WIN32
+ }
+
+ remove_process_tab(pConn);
+
+ free( pConn );
+}
+
+static void OGLS_loop( OGLS_Conn *pConn )
+{
+ //fprintf (stderr, "Server: connect from host %s, port %hd.\n",
+ // inet_ntoa (pConn->clientname.sin_addr),
+ // ntohs (pConn->clientname.sin_port));
+
+ gettimeofday(&pConn->last_time, NULL);
+ gettimeofday(&pConn->last_read_time, NULL);
+
+#ifndef _WIN32
+ if (strcmp(inet_ntoa(pConn->clientname.sin_addr), "127.0.0.1") == 0 &&
+ pConn->pOption->different_windows == 0)
+ {
+ pConn->local_connection = 1;
+ }
+#endif // _WIN32
+
+ if( pConn->pOption->timestamp )
+ {
+ gettimeofday(&pConn->time_stamp_start, NULL);
+ }
+
+ while( OGLS_readConn(pConn) >= 0 );
+
+ do_function_call(pConn, _exit_process_func, 1, NULL, NULL);
+
+ //fprintf (stderr, "Server: disconnect from host %s, port %hd.\n",
+ // inet_ntoa (pConn->clientname.sin_addr),
+ // ntohs (pConn->clientname.sin_port));
+
+ OGLS_removeConn( pConn );
+}
+
+#ifndef _WIN32
+int has_x_error = 0;
+static int OGLS_x_error_handler(Display *display, XErrorEvent *error)
{
char buf[64];
XGetErrorText(display, error->error_code, buf, 63);
has_x_error = 1;
return 0;
}
+#endif // _WIN32
+
+static void OGLS_main( OGLS_Opts *pOption )
+{
+ int sock;
+ fd_set active_fd_set, read_fd_set;
+
+ socklen_t size;
+
+#ifndef _WIN32
+ XSetErrorHandler(OGLS_x_error_handler);
+#endif // _WIN32
+
+ /* Create the socket and set it up to accept connections. */
+ sock = OGLS_createListenSocket( pOption->port );
+ if (sock < 0)
+ return;
+
+ if (listen (sock, 1) < 0)
+ {
+ perror ("listen");
+ //exit (EXIT_FAILURE);
+ return;
+ }
+
+ FD_ZERO (&active_fd_set);
+ FD_SET (sock, &active_fd_set);
+
+ while(1)
+ {
+ OGLS_Conn *pConn = NULL;
+ pthread_t taskid;
+
+ read_fd_set = active_fd_set;
+ if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0)
+ {
+#ifndef _WIN32
+ if (errno == EINTR) {
+ continue;
+ }
+#endif
+ perror ("select");
+ //exit (EXIT_FAILURE);
+ break;
+ }
+
+ pConn = OGLS_createConn( pOption );
+ if( !pConn )
+ {
+ perror( "OGLS_createConn" );
+ continue;
+ }
+
+ size = sizeof(pConn->clientname);
+ pConn->sock = accept (sock, (struct sockaddr *) &pConn->clientname, &size);
+ if (pConn->sock < 0)
+ {
+ perror ("accept");
+ OGLS_removeConn( pConn );
+ continue;
+ }
+
+ if( pthread_create( (pthread_t *)&taskid, NULL, (void *(*)(void *))OGLS_loop, (void *)pConn ) )
+ {
+ perror( "pthread_create" );
+ OGLS_removeConn( pConn );
+ continue;
+ }
+ }
+
+ closesocket( sock );
+}
-void usage()
+static void usage(void)
{
printf("Usage : opengl_server [OPTION]\n\n");
printf("The following options are available :\n");
printf("--h or --help : display this help\n");
}
-int main (int argc, char* argv[])
+//int main (int argc, char* argv[])
+void *init_opengl_server(void *arg)
{
- int sock;
- fd_set active_fd_set, read_fd_set;
- int i;
- struct sockaddr_in clientname;
- socklen_t size;
- int port = PORT;
- int different_windows = 0;
+ //int i;
+ OGLS_Opts option;
+
+ memset( &option, 0, sizeof(option) );
+ // set default values
+ option.port = PORT;
+ option.parent_xid = -1;
+ option.refresh_rate = 1000;
+ option.timestamp = 1; /* only valid if must_save == 1. include timestamps in the save file to enable real-time playback */
+
+#if 0
for(i=1;i<argc;i++)
{
if (argv[i][0] == '-' && argv[i][1] == '-')
if (strcmp(argv[i], "-debug") == 0)
{
- display_function_call = 1;
+ option.display_function_call = 1;
}
else if (strcmp(argv[i], "-save") == 0)
{
- must_save = 1;
+ option.must_save = 1;
}
else if (strncmp(argv[i], "-port=",6) == 0)
{
- port = atoi(argv[i] + 6);
+ option.port = atoi(argv[i] + 6);
}
else if (strncmp(argv[i], "-filename=",strlen("-filename=")) == 0)
{
else if (strncmp(argv[i], "-parent-xid=",strlen("-parent-xid=")) == 0)
{
char* c = argv[i] + strlen("-parent-xid=");
- parent_xid = strtol(c, NULL, 0);
- different_windows = 1;
+ option.parent_xid = strtol(c, NULL, 0);
+ option.different_windows = 1;
}
else if (strcmp(argv[i], "-different-windows") == 0)
{
- different_windows = 1;
+ option.different_windows = 1;
}
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0)
{
return -1;
}
}
+#endif /* 0 */
- /* Create the socket and set it up to accept connections. */
- sock = make_socket (port);
-
- if (listen (sock, 1) < 0)
- {
- perror ("listen");
- exit (EXIT_FAILURE);
- }
-
- struct sigaction action;
- action.sa_handler = SIG_IGN;
- action.sa_flags = SA_NOCLDWAIT;
- sigaction(SIGCHLD,&action,NULL);
-
- FD_ZERO (&active_fd_set);
- FD_SET (sock, &active_fd_set);
-
- while(1)
- {
- int new, pid;
-
- read_fd_set = active_fd_set;
- if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0)
- {
- perror ("select");
- exit (EXIT_FAILURE);
- }
-
- size = sizeof (clientname);
- new = accept (sock, (struct sockaddr *) &clientname, &size);
- if (new < 0)
- {
- perror ("accept");
- exit (EXIT_FAILURE);
- }
- pid = fork();
- if (pid == -1)
- {
- perror ("fork");
- exit(EXIT_FAILURE);
- }
- if (pid == 0)
- {
- close(sock);
-
- fprintf (stderr, "Server: connect from host %s, port %hd.\n",
- inet_ntoa (clientname.sin_addr),
- ntohs (clientname.sin_port));
-
- gettimeofday(&last_time, NULL);
- gettimeofday(&last_read_time, NULL);
-
- if (strcmp(inet_ntoa(clientname.sin_addr), "127.0.0.1") == 0 &&
- different_windows == 0)
- {
- opengl_exec_set_local_connection();
- }
-
- if (timestamp)
- {
- gettimeofday(&time_stamp_start, NULL);
- }
-
- XSetErrorHandler(x_error_handler);
-
- while(1)
- {
- if (read_from_client (new) < 0)
- {
- do_function_call(dpy, _exit_process_func, 1, NULL, NULL);
-
- fprintf (stderr, "Server: disconnect from host %s, port %hd.\n",
- inet_ntoa (clientname.sin_addr),
- ntohs (clientname.sin_port));
-
- return 0;
- }
- }
- }
- else
- {
- close(new);
- }
- }
-
+ OGLS_main(&option);
return 0;
}