From 11c5d72c559a2e27885dbb804addef3102af35ed Mon Sep 17 00:00:00 2001 From: jsorg71 Date: Fri, 4 Apr 2008 06:50:39 +0000 Subject: [PATCH] wait objs function changes --- common/os_calls.c | 38 ++++++++++++++++++++++++++++++++++---- common/os_calls.h | 4 +++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index 9d359039..251e1f37 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -619,15 +619,17 @@ g_tcp_select(int sck1, int sck2) tbus APP_CC g_create_wait_obj(char* name) { +#ifdef _WIN32 tbus obj; -#ifdef _WIN32 obj = (tbus)CreateEvent(0, 1, 0, name); return obj; #else + tbus obj; struct sockaddr_un sa; int len; int sck; + int i; sck = socket(PF_UNIX, SOCK_DGRAM, 0); if (sck < 0) @@ -636,7 +638,20 @@ g_create_wait_obj(char* name) } memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; - sprintf(sa.sun_path, "/tmp/%s", name); + if ((name == 0) || (strlen(name) == 0)) + { + g_random((char*)&i, sizeof(i)); + sprintf(sa.sun_path, "/tmp/auto%8.8x", i); + while (g_file_exist(sa.sun_path)) + { + g_random((char*)&i, sizeof(i)); + sprintf(sa.sun_path, "/tmp/auto%8.8x", i); + } + } + else + { + sprintf(sa.sun_path, "/tmp/%s", name); + } unlink(sa.sun_path); len = sizeof(sa); if (bind(sck, (struct sockaddr*)&sa, len) < 0) @@ -650,6 +665,7 @@ g_create_wait_obj(char* name) } /*****************************************************************************/ +/* returns 0 on error */ tbus APP_CC g_create_wait_obj_from_socket(tbus socket, int write) { @@ -673,6 +689,20 @@ g_create_wait_obj_from_socket(tbus socket, int write) #endif } +/*****************************************************************************/ +void APP_CC +g_delete_wait_obj_from_socket(tbus wait_obj) +{ +#ifdef _WIN32 + if (wait_obj == 0) + { + return; + } + WSACloseEvent((HANDLE)wait_obj); +#else +#endif +} + /*****************************************************************************/ /* returns error */ int APP_CC @@ -769,7 +799,7 @@ g_is_wait_obj_set(tbus obj) /*****************************************************************************/ /* returns error */ int APP_CC -g_destroy_wait_obj(tbus obj) +g_delete_wait_obj(tbus obj) { #ifdef _WIN32 if (obj == 0) @@ -777,7 +807,7 @@ g_destroy_wait_obj(tbus obj) return 0; } /* Close event handle */ - WSACloseEvent((HANDLE)obj); + CloseHandle((HANDLE)obj); return 0; #else socklen_t sa_size; diff --git a/common/os_calls.h b/common/os_calls.h index e46ffa36..73dde4b2 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -97,6 +97,8 @@ tbus APP_CC g_create_wait_obj(char* name); tbus APP_CC g_create_wait_obj_from_socket(tbus socket, int write); +void APP_CC +g_delete_wait_obj_from_socket(tbus wait_obj); int APP_CC g_set_wait_obj(tbus obj); int APP_CC @@ -104,7 +106,7 @@ g_reset_wait_obj(tbus obj); int APP_CC g_is_wait_obj_set(tbus obj); int APP_CC -g_destroy_wait_obj(tbus obj); +g_delete_wait_obj(tbus obj); int APP_CC g_obj_wait(tbus* read_objs, int rcount, tbus* write_objs, int wcount, int mstimeout);