diff options
author | Lucas <Coquinho@users.noreply.github.com> | 2020-07-09 17:34:54 -0300 |
---|---|---|
committer | Felipe Magno de Almeida <felipe@expertise.dev> | 2020-12-15 16:10:21 -0300 |
commit | c6c7f7153eb118c56e60c1d3d3b9646b753bc4d2 (patch) | |
tree | a6b8e3b3ff669057417e8709433779735d8d0a30 | |
parent | d07296f6189e3ffc5c13c64eb7d03730d74dcdb2 (diff) | |
download | efl-c6c7f7153eb118c56e60c1d3d3b9646b753bc4d2.tar.gz |
eina: Create eina_pipe abstraction for Windows compatibility
-rw-r--r-- | src/lib/ecore/ecore_anim.c | 38 | ||||
-rw-r--r-- | src/lib/ecore/ecore_pipe.c | 41 | ||||
-rw-r--r-- | src/lib/ecore/efl_thread.c | 8 | ||||
-rw-r--r-- | src/lib/efreet/efreet_desktop.c | 11 | ||||
-rw-r--r-- | src/lib/eina/Eina.h | 1 | ||||
-rw-r--r-- | src/lib/eina/eina_debug_timer.c | 17 | ||||
-rw-r--r-- | src/lib/eina/eina_pipe.c | 84 | ||||
-rw-r--r-- | src/lib/eina/eina_pipe.h | 16 | ||||
-rw-r--r-- | src/lib/eina/eina_thread_queue.c | 2 | ||||
-rw-r--r-- | src/lib/eina/meson.build | 4 | ||||
-rw-r--r-- | src/lib/evil/evil_macro_wrapper.h | 14 | ||||
-rw-r--r-- | src/lib/evil/evil_main.c | 5 | ||||
-rw-r--r-- | src/lib/evil/evil_unistd.c | 136 | ||||
-rw-r--r-- | src/lib/evil/evil_unistd.h | 5 | ||||
-rw-r--r-- | src/tests/ecore/ecore_test_ecore.c | 22 | ||||
-rw-r--r-- | src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c | 8 | ||||
-rw-r--r-- | src/tests/ecore/efl_app_test_loop_fd.c | 16 |
17 files changed, 170 insertions, 258 deletions
diff --git a/src/lib/ecore/ecore_anim.c b/src/lib/ecore/ecore_anim.c index 25de52db68..6f3c29a86e 100644 --- a/src/lib/ecore/ecore_anim.c +++ b/src/lib/ecore/ecore_anim.c @@ -15,28 +15,6 @@ # include <sys/timerfd.h> #endif -#ifdef _WIN32 - -# include <winsock2.h> -# include <evil_private.h> /* pipe */ - -# define pipe_write(fd, buffer, size) send((fd), (char *)(buffer), size, 0) -# define pipe_read(fd, buffer, size) recv((fd), (char *)(buffer), size, 0) -# define pipe_close(fd) closesocket(fd) -# define PIPE_FD_ERROR SOCKET_ERROR - -#else - -# include <sys/select.h> -# include <fcntl.h> - -# define pipe_write(fd, buffer, size) write((fd), buffer, size) -# define pipe_read(fd, buffer, size) read((fd), buffer, size) -# define pipe_close(fd) close(fd) -# define PIPE_FD_ERROR -1 - -#endif /* ! _WIN32 */ - #ifdef HAVE_PRCTL # include <sys/prctl.h> #endif @@ -106,7 +84,7 @@ static void _tick_send(signed char val) { DBG("_tick_send(%i)", val); - if (pipe_write(timer_fd_write, &val, 1) != 1) + if (eina_pipe_write(timer_fd_write, &val, 1) != 1) { ERR("Cannot write to animator control fd"); } @@ -259,7 +237,7 @@ _timer_tick_core(void *data EINA_UNUSED, Ecore_Thread *thread) } if (data_control) { - if (pipe_read(timer_fd_read, &tick, sizeof(tick)) != 1) + if (eina_pipe_read(timer_fd_read, &tick, sizeof(tick)) != 1) { ERR("Cannot read from animator control fd"); } @@ -308,7 +286,7 @@ _timer_tick_core(void *data EINA_UNUSED, Ecore_Thread *thread) data_timeout = EINA_TRUE; if (data_control) { - if (pipe_read(timer_fd_read, &tick, sizeof(tick)) != 1) + if (eina_pipe_read(timer_fd_read, &tick, sizeof(tick)) != 1) { ERR("Cannot read from animator control fd"); } @@ -334,9 +312,9 @@ done: timerfd = -1; } #endif - pipe_close(timer_fd_read); + eina_pipe_free(timer_fd_read); timer_fd_read = -1; - pipe_close(timer_fd_write); + eina_pipe_free(timer_fd_write); timer_fd_write = -1; } @@ -378,12 +356,12 @@ _timer_tick_finished(void *data EINA_UNUSED, Ecore_Thread *thread EINA_UNUSED) tick_queue_count = 0; if (timer_fd_read >= 0) { - pipe_close(timer_fd_read); + eina_pipe_free(timer_fd_read); timer_fd_read = -1; } if (timer_fd_write >= 0) { - pipe_close(timer_fd_write); + eina_pipe_free(timer_fd_write); timer_fd_write = -1; } } @@ -395,7 +373,7 @@ _timer_tick_begin(void) { int fds[2]; - if (pipe(fds) != 0) return; + if (eina_pipe_new(fds) != 0) return; eina_file_close_on_exec(fds[0], EINA_TRUE); eina_file_close_on_exec(fds[1], EINA_TRUE); timer_fd_read = fds[0]; diff --git a/src/lib/ecore/ecore_pipe.c b/src/lib/ecore/ecore_pipe.c index 73c7e661c3..269219bdc4 100644 --- a/src/lib/ecore/ecore_pipe.c +++ b/src/lib/ecore/ecore_pipe.c @@ -36,14 +36,11 @@ */ #define PIPE_FD_INVALID -1 +#define PIPE_FD_ERROR -1 #ifdef _WIN32 # include <winsock2.h> # include <evil_private.h> /* pipe fcntl */ -# define pipe_write(fd, buffer, size) send((fd), (char *)(buffer), size, 0) -# define pipe_read(fd, buffer, size) recv((fd), (char *)(buffer), size, 0) -# define pipe_close(fd) closesocket(fd) -# define PIPE_FD_ERROR SOCKET_ERROR #else # ifdef HAVE_SYS_EPOLL_H # include <sys/epoll.h> @@ -53,10 +50,6 @@ # endif # include <unistd.h> # include <fcntl.h> -# define pipe_write(fd, buffer, size) write((fd), buffer, size) -# define pipe_read(fd, buffer, size) read((fd), buffer, size) -# define pipe_close(fd) close(fd) -# define PIPE_FD_ERROR -1 #endif /* ! _WIN32 */ #include "Ecore.h" @@ -120,7 +113,7 @@ ecore_pipe_read_close(Ecore_Pipe *p) } if (p->fd_read != PIPE_FD_INVALID) { - pipe_close(p->fd_read); + eina_pipe_free(p->fd_read); p->fd_read = PIPE_FD_INVALID; } } @@ -182,7 +175,7 @@ ecore_pipe_write_close(Ecore_Pipe *p) } if (p->fd_write != PIPE_FD_INVALID) { - pipe_close(p->fd_write); + eina_pipe_free(p->fd_write); p->fd_write = PIPE_FD_INVALID; } } @@ -218,7 +211,7 @@ ecore_pipe_write(Ecore_Pipe *p, do // First write the len into the pipe { - ret = pipe_write(p->fd_write, &bytes, sizeof(bytes)); + ret = eina_pipe_write(p->fd_write, &bytes, sizeof(bytes)); if (ret == sizeof(nbytes)) { retry = ECORE_PIPE_WRITE_RETRY; @@ -233,7 +226,7 @@ ecore_pipe_write(Ecore_Pipe *p, } else if ((ret == PIPE_FD_ERROR) && (errno == EPIPE)) { - pipe_close(p->fd_write); + eina_pipe_free(p->fd_write); p->fd_write = PIPE_FD_INVALID; goto out; } @@ -253,7 +246,7 @@ ecore_pipe_write(Ecore_Pipe *p, do // and now pass the data to the pipe { - ret = pipe_write(p->fd_write, + ret = eina_pipe_write(p->fd_write, ((unsigned char *)buffer) + already_written, nbytes - already_written); @@ -269,7 +262,7 @@ ecore_pipe_write(Ecore_Pipe *p, } else if ((ret == PIPE_FD_ERROR) && (errno == EPIPE)) { - pipe_close(p->fd_write); + eina_pipe_free(p->fd_write); p->fd_write = PIPE_FD_INVALID; goto out; } @@ -308,7 +301,7 @@ ecore_pipe_full_add(Ecore_Pipe_Cb handler, if ((fd_read == -1) && (fd_write == -1)) { - if (pipe(fds)) + if (eina_pipe_new(fds)) { ecore_pipe_mp_free(p); return NULL; @@ -383,8 +376,8 @@ _ecore_pipe_del(Ecore_Pipe *p) if (p->handling > 0) return (void *)p->data; if (p->fd_handler) _ecore_main_fd_handler_del(ML_OBJ, ML_DAT, p->fd_handler); - if (p->fd_read != PIPE_FD_INVALID) pipe_close(p->fd_read); - if (p->fd_write != PIPE_FD_INVALID) pipe_close(p->fd_write); + if (p->fd_read != PIPE_FD_INVALID) eina_pipe_free(p->fd_read); + if (p->fd_write != PIPE_FD_INVALID) eina_pipe_free(p->fd_write); p->fd_handler = NULL; p->fd_read = PIPE_FD_INVALID; p->fd_write = PIPE_FD_INVALID; @@ -552,7 +545,7 @@ _ecore_pipe_wait(Ecore_Pipe *p, if ((fd_timer_found) && (p->timerfd != PIPE_FD_INVALID)) { - if (pipe_read(p->timerfd, &timerfdbuf, sizeof(timerfdbuf)) < + if (eina_pipe_read(p->timerfd, &timerfdbuf, sizeof(timerfdbuf)) < (int)sizeof(int64_t)) WRN("Could not read timerfd data"); _ecore_pipe_unhandle(p); @@ -612,7 +605,7 @@ _ecore_pipe_read(void *data, if (p->len == 0) { // read the len of the passed data - ret = pipe_read(p->fd_read, &p->len, sizeof(p->len)); + ret = eina_pipe_read(p->fd_read, &p->len, sizeof(p->len)); // catch the non error case first // read amount ok - nothing more to do @@ -634,7 +627,7 @@ _ecore_pipe_read(void *data, { // no data on first try through means an error _ecore_pipe_handler_call(p, NULL, 0); - pipe_close(p->fd_read); + eina_pipe_free(p->fd_read); p->fd_read = PIPE_FD_INVALID; p->fd_handler = NULL; _ecore_pipe_unhandle(p); @@ -668,7 +661,7 @@ _ecore_pipe_read(void *data, if (WSAGetLastError() != WSAEWOULDBLOCK) { _ecore_pipe_handler_call(p, NULL, 0); - pipe_close(p->fd_read); + eina_pipe_free(p->fd_read); p->fd_read = PIPE_FD_INVALID; p->fd_handler = NULL; _ecore_pipe_unhandle(p); @@ -696,7 +689,7 @@ _ecore_pipe_read(void *data, { _ecore_pipe_handler_call(p, NULL, 0); // close the pipe - pipe_close(p->fd_read); + eina_pipe_free(p->fd_read); p->fd_read = PIPE_FD_INVALID; p->fd_handler = NULL; _ecore_pipe_unhandle(p); @@ -705,7 +698,7 @@ _ecore_pipe_read(void *data, } // and read the passed data - ret = pipe_read(p->fd_read, + ret = eina_pipe_read(p->fd_read, ((unsigned char *)p->passed_data) + p->already_read, p->len - p->already_read); @@ -747,7 +740,7 @@ _ecore_pipe_read(void *data, if (WSAGetLastError() != WSAEWOULDBLOCK) { _ecore_pipe_handler_call(p, NULL, 0); - pipe_close(p->fd_read); + eina_pipe_free(p->fd_read); p->fd_read = PIPE_FD_INVALID; p->fd_handler = NULL; _ecore_pipe_unhandle(p); diff --git a/src/lib/ecore/efl_thread.c b/src/lib/ecore/efl_thread.c index 9fc6b8d882..97b7897522 100644 --- a/src/lib/ecore/efl_thread.c +++ b/src/lib/ecore/efl_thread.c @@ -666,7 +666,7 @@ _efl_thread_efl_task_run(Eo *obj, Efl_Thread_Data *pd) // input/output pipes if (td->flags & EFL_TASK_FLAGS_USE_STDIN) { - if (pipe(pipe_from_thread) != 0) + if (eina_pipe_new(pipe_from_thread) != 0) { ERR("Can't create to_thread pipe"); free(thdat); @@ -675,7 +675,7 @@ _efl_thread_efl_task_run(Eo *obj, Efl_Thread_Data *pd) } if (td->flags & EFL_TASK_FLAGS_USE_STDOUT) { - if (pipe(pipe_to_thread) != 0) + if (eina_pipe_new(pipe_to_thread) != 0) { ERR("Can't create from_thread pipe"); if (td->flags & EFL_TASK_FLAGS_USE_STDIN) @@ -723,13 +723,13 @@ _efl_thread_efl_task_run(Eo *obj, Efl_Thread_Data *pd) } // control pipes - if (pipe(pipe_to_thread) != 0) + if (eina_pipe_new(pipe_to_thread) != 0) { ERR("Can't create to_thread control pipe"); _task_run_pipe_fail_clear(thdat, pd); return EINA_FALSE; } - if (pipe(pipe_from_thread) != 0) + if (eina_pipe_new(pipe_from_thread) != 0) { ERR("Can't create from_thread control pipe"); _task_run_pipe_fail_clear(thdat, pd); diff --git a/src/lib/efreet/efreet_desktop.c b/src/lib/efreet/efreet_desktop.c index e8f9f603e3..c8e5e20eea 100644 --- a/src/lib/efreet/efreet_desktop.c +++ b/src/lib/efreet/efreet_desktop.c @@ -92,14 +92,6 @@ efreet_desktop_init(void) return 0; } -#ifdef _WIN32 - if (!evil_sockets_init()) - { - ERR("Could not initialize Winsock system"); - goto error; - } -#endif - if (!eina_lock_new(&_lock)) { ERR("Could not create lock"); @@ -139,9 +131,6 @@ efreet_desktop_shutdown(void) EINA_LIST_FREE(efreet_desktop_types, info) efreet_desktop_type_info_free(info); eina_lock_free(&_lock); -#ifdef _WIN32 - evil_sockets_shutdown(); -#endif eina_log_domain_unregister(_efreet_desktop_log_dom); _efreet_desktop_log_dom = -1; } diff --git a/src/lib/eina/Eina.h b/src/lib/eina/Eina.h index 383696d7d8..cd9dc513f4 100644 --- a/src/lib/eina/Eina.h +++ b/src/lib/eina/Eina.h @@ -261,6 +261,7 @@ extern "C" { #include <eina_value.h> #include <eina_value_util.h> #include <eina_cow.h> +#include <eina_pipe.h> #include <eina_thread_queue.h> #include <eina_matrix.h> #include <eina_vector.h> diff --git a/src/lib/eina/eina_debug_timer.c b/src/lib/eina/eina_debug_timer.c index 07cf6b1ef4..667304d71b 100644 --- a/src/lib/eina/eina_debug_timer.c +++ b/src/lib/eina/eina_debug_timer.c @@ -42,6 +42,7 @@ #include "eina_debug.h" #include "eina_debug_private.h" +#include "eina_pipe.h" static Eina_Spinlock _lock; @@ -77,7 +78,7 @@ end: t->rel_time = t->timeout - prev_time; if (!t2) _timers = eina_list_append(_timers, t); else _timers = eina_list_prepend_relative(_timers, t, t2); - if (write(pipeToThread[1], &c, 1) != 1) + if (eina_pipe_write(pipeToThread[1], &c, 1) != 1) e_debug("EINA DEBUG ERROR: Can't wake up thread for debug timer"); } @@ -121,7 +122,7 @@ _monitor(void *_data EINA_UNUSED) if (ret) { char c; - if (read(pipeToThread[0], &c, 1) != 1) break; + if (eina_pipe_read(pipeToThread[0], &c, 1) != 1) break; } else { @@ -143,8 +144,8 @@ _monitor(void *_data EINA_UNUSED) } #endif _thread_runs = EINA_FALSE; - close(pipeToThread[0]); - close(pipeToThread[1]); + eina_pipe_free(pipeToThread[0]); + eina_pipe_free(pipeToThread[1]); return NULL; } @@ -210,10 +211,8 @@ Eina_Bool _eina_debug_timer_init(void) { eina_spinlock_new(&_lock); -#ifndef _WIN32 - if (pipe(pipeToThread) == -1) + if (eina_pipe_new(pipeToThread) == -1) return EINA_FALSE; -#endif return EINA_TRUE; } @@ -225,8 +224,8 @@ _eina_debug_timer_shutdown(void) eina_spinlock_take(&_lock); EINA_LIST_FREE(_timers, t) free(t); - close(pipeToThread[0]); - close(pipeToThread[1]); + eina_pipe_free(pipeToThread[0]); + eina_pipe_free(pipeToThread[1]); if (_thread_runs) pthread_cancel(_thread); _thread_runs = 0; diff --git a/src/lib/eina/eina_pipe.c b/src/lib/eina/eina_pipe.c new file mode 100644 index 0000000000..888e780b75 --- /dev/null +++ b/src/lib/eina/eina_pipe.c @@ -0,0 +1,84 @@ + +#include <Eina.h> + +#ifdef _WIN32 +#include <fcntl.h> +#include <evil_private.h> + +EINA_API int +eina_pipe_new(int *fds) +{ + HANDLE handles[2]; + if (CreatePipe(&handles[0], &handles[1], NULL, 0)) + { + fds[0] = _open_osfhandle((intptr_t)handles[0], _O_RDONLY); + fds[1] = _open_osfhandle((intptr_t)handles[1], _O_APPEND); + return 0; + } + else + { + fds[0] = fds[1] = -1; + return -1; + } +} + +EINA_API ssize_t +eina_pipe_read(int pipe, void* buffer, size_t count) +{ + DWORD read_bytes = 0; + if (ReadFile((HANDLE)_get_osfhandle(pipe), buffer, count, &read_bytes, NULL)) + { + return read_bytes; + } + else + { + return -1; + } +} + +EINA_API ssize_t +eina_pipe_write(int pipe, void const* buffer, size_t count) +{ + DWORD written_bytes = 0; + if (WriteFile((HANDLE)_get_osfhandle(pipe), buffer, count, &written_bytes, NULL)) + { + return written_bytes; + } + else + { + return -1; + } +} + +EINA_API void +eina_pipe_free(int pipe) +{ + _close(pipe); +} +#else +#include <unistd.h> + +EINA_API int +eina_pipe_new(int *fds) +{ + return pipe(fds); +} + +EINA_API ssize_t +eina_pipe_read(int pipe, void* buffer, size_t count) +{ + return read(pipe, buffer, count); +} + +EINA_API ssize_t +eina_pipe_write(int pipe, void const* buffer, size_t count) +{ + return write(pipe, buffer, count); +} + +EINA_API void +eina_pipe_free(int pipe) +{ + close(pipe); +} +#endif diff --git a/src/lib/eina/eina_pipe.h b/src/lib/eina/eina_pipe.h new file mode 100644 index 0000000000..12b8315550 --- /dev/null +++ b/src/lib/eina/eina_pipe.h @@ -0,0 +1,16 @@ +#ifndef EINA_PIPE_H +#define EINA_PIPE_H + +EINA_API int +eina_pipe_new(int *fds); + +EINA_API ssize_t +eina_pipe_read(int pipe, void* buffer, size_t count); + +EINA_API ssize_t +eina_pipe_write(int pipe, void const* buffer, size_t count); + +EINA_API void +eina_pipe_free(int pipe); + +#endif diff --git a/src/lib/eina/eina_thread_queue.c b/src/lib/eina/eina_thread_queue.c index e0410185f1..cf2b9c8595 100644 --- a/src/lib/eina/eina_thread_queue.c +++ b/src/lib/eina/eina_thread_queue.c @@ -478,7 +478,7 @@ eina_thread_queue_send_done(Eina_Thread_Queue *thq, void *allocref) if (thq->fd >= 0) { char dummy = 0; - if (write(thq->fd, &dummy, 1) != 1) + if (eina_pipe_write(thq->fd, &dummy, 1) != 1) ERR("Eina Threadqueue write to fd %i failed", thq->fd); } } diff --git a/src/lib/eina/meson.build b/src/lib/eina/meson.build index 15c5f1e999..c1bff12561 100644 --- a/src/lib/eina/meson.build +++ b/src/lib/eina/meson.build @@ -113,7 +113,8 @@ public_sub_headers = [ 'eina_freeq.h', 'eina_slstr.h', 'eina_vpath.h', -'eina_abstract_content.h' +'eina_abstract_content.h', +'eina_pipe.h', ] public_headers = [ @@ -160,6 +161,7 @@ eina_src = files([ 'eina_mempool.c', 'eina_mmap.c', 'eina_module.c', +'eina_pipe.c', 'eina_prefix.c', 'eina_promise.c', 'eina_promise_private.h', diff --git a/src/lib/evil/evil_macro_wrapper.h b/src/lib/evil/evil_macro_wrapper.h index 640f5a307e..444c963f7a 100644 --- a/src/lib/evil/evil_macro_wrapper.h +++ b/src/lib/evil/evil_macro_wrapper.h @@ -61,19 +61,5 @@ # define gettimeofday(tv, tz) evil_gettimeofday(tv, tz) #endif -/* - * evil_unistd.h - */ - -/** - * @def pipe(fds) - * - * Wrapper around evil_pipe(). - */ -#ifdef pipe -# undef pipe -#endif -#define pipe(fds) evil_pipe(fds) - #endif diff --git a/src/lib/evil/evil_main.c b/src/lib/evil/evil_main.c index 803e47fc30..ec7f666fc5 100644 --- a/src/lib/evil/evil_main.c +++ b/src/lib/evil/evil_main.c @@ -31,9 +31,6 @@ evil_init(void) _evil_time_count = count.QuadPart; - if (!evil_sockets_init()) - return --_evil_init_count; - return _evil_init_count; } @@ -50,8 +47,6 @@ evil_shutdown(void) if (--_evil_init_count != 0) return _evil_init_count; - evil_sockets_shutdown(); - return _evil_init_count; } diff --git a/src/lib/evil/evil_unistd.c b/src/lib/evil/evil_unistd.c index 02f01baaef..5c02c69e91 100644 --- a/src/lib/evil/evil_unistd.c +++ b/src/lib/evil/evil_unistd.c @@ -33,139 +33,3 @@ evil_time_get(void) return (double)(count.QuadPart - _evil_time_count)/ (double)_evil_time_freq; } - -/* - * Sockets and pipe related functions - * - */ - -EVIL_API int -evil_sockets_init(void) -{ - WSADATA wsa_data; - WORD version; - - version = MAKEWORD(2, 2); - if (WSAStartup(version, &wsa_data) == 0) - { - if ((LOBYTE(wsa_data.wVersion) == 2) && - (HIBYTE(wsa_data.wVersion) == 2)) - return 1; - else - { - WSACleanup(); - return 0; - } - } - - return 0; -} - -EVIL_API void -evil_sockets_shutdown(void) -{ - WSACleanup(); -} - -/* - * The code of the following functions has been kindly offered - * by Tor Lillqvist. - */ -EVIL_API int -evil_pipe(int *fds) -{ - struct sockaddr_in saddr; - SOCKET temp; - SOCKET socket1 = INVALID_SOCKET; - SOCKET socket2 = INVALID_SOCKET; - u_long arg; - fd_set read_set; - fd_set write_set; - int len; - - temp = socket (AF_INET, SOCK_STREAM, 0); - - if (temp == INVALID_SOCKET) - goto out0; - - arg = 1; - if (ioctlsocket (temp, FIONBIO, &arg) == SOCKET_ERROR) - goto out0; - - memset (&saddr, 0, sizeof (saddr)); - saddr.sin_family = AF_INET; - saddr.sin_port = 0; - saddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); - - if (bind (temp, (struct sockaddr *)&saddr, sizeof (saddr))) - goto out0; - - if (listen (temp, 1) == SOCKET_ERROR) - goto out0; - - len = sizeof (saddr); - if (getsockname (temp, (struct sockaddr *)&saddr, &len)) - goto out0; - - socket1 = socket (AF_INET, SOCK_STREAM, 0); - - if (socket1 == INVALID_SOCKET) - goto out0; - - arg = 1; - if (ioctlsocket (socket1, FIONBIO, &arg) == SOCKET_ERROR) - goto out1; - - if ((connect (socket1, (struct sockaddr *)&saddr, len) == SOCKET_ERROR) && - (WSAGetLastError () != WSAEWOULDBLOCK)) - goto out1; - - FD_ZERO (&read_set); - FD_SET (temp, &read_set); - - if (select (0, &read_set, NULL, NULL, NULL) == SOCKET_ERROR) - goto out1; - - if (!FD_ISSET (temp, &read_set)) - goto out1; - - socket2 = accept (temp, (struct sockaddr *) &saddr, &len); - if (socket2 == INVALID_SOCKET) - goto out1; - - FD_ZERO (&write_set); - FD_SET (socket1, &write_set); - - if (select (0, NULL, &write_set, NULL, NULL) == SOCKET_ERROR) - goto out2; - - if (!FD_ISSET (socket1, &write_set)) - goto out2; - - arg = 0; - if (ioctlsocket (socket1, FIONBIO, &arg) == SOCKET_ERROR) - goto out2; - - arg = 0; - if (ioctlsocket (socket2, FIONBIO, &arg) == SOCKET_ERROR) - goto out2; - - fds[0] = socket1; - fds[1] = socket2; - - closesocket (temp); - - return 0; - - out2: - closesocket (socket2); - out1: - closesocket (socket1); - out0: - closesocket (temp); - - fds[0] = -1; - fds[1] = -1; - - return -1; -} diff --git a/src/lib/evil/evil_unistd.h b/src/lib/evil/evil_unistd.h index 5f8f006f87..9d3e0de048 100644 --- a/src/lib/evil/evil_unistd.h +++ b/src/lib/evil/evil_unistd.h @@ -14,6 +14,11 @@ * @{ */ +#ifdef _MSC_VER + +#include <io.h> // for read, write, access, close + +#endif // _MSC_VER /* * Time related functions diff --git a/src/tests/ecore/ecore_test_ecore.c b/src/tests/ecore/ecore_test_ecore.c index 66544d0f98..72638628bf 100644 --- a/src/tests/ecore/ecore_test_ecore.c +++ b/src/tests/ecore/ecore_test_ecore.c @@ -113,20 +113,20 @@ EFL_START_TEST(ecore_test_ecore_main_loop_fd_handler) int comm[2]; int ret; - ret = pipe(comm); + ret = eina_pipe_new(comm); fail_if(ret != 0); fd_handler = ecore_main_fd_handler_add (comm[0], ECORE_FD_READ, _fd_handler_cb, &did, NULL, NULL); fail_if(fd_handler == NULL); - ret = write(comm[1], &did, 1); + ret = eina_pipe_write(comm[1], &did, 1); fail_if(ret != 1); ecore_main_loop_begin(); - close(comm[0]); - close(comm[1]); + eina_pipe_free(comm[0]); + eina_pipe_free(comm[1]); fail_if(did == EINA_FALSE); @@ -139,7 +139,7 @@ EFL_START_TEST(ecore_test_ecore_main_loop_fd_handler_valid_flags) int comm[2]; int ret; - ret = pipe(comm); + ret = eina_pipe_new(comm); fail_if(ret != 0); fd_handler = ecore_main_fd_handler_add @@ -149,8 +149,8 @@ EFL_START_TEST(ecore_test_ecore_main_loop_fd_handler_valid_flags) if (fd_handler) ecore_main_fd_handler_del(fd_handler); - close(comm[0]); - close(comm[1]); + eina_pipe_free(comm[0]); + eina_pipe_free(comm[1]); } EFL_END_TEST @@ -161,7 +161,7 @@ EFL_START_TEST(ecore_test_ecore_main_loop_fd_handler_activate_modify) int comm[2]; int ret; - ret = pipe(comm); + ret = eina_pipe_new(comm); fail_if(ret != 0); fd_handler = ecore_main_fd_handler_add @@ -170,13 +170,13 @@ EFL_START_TEST(ecore_test_ecore_main_loop_fd_handler_activate_modify) ecore_main_fd_handler_active_set(fd_handler, ECORE_FD_READ); - ret = write(comm[1], "e", 1); + ret = eina_pipe_write(comm[1], "e", 1); fail_if(ret != 1); ecore_main_loop_begin(); - close(comm[0]); - close(comm[1]); + eina_pipe_free(comm[0]); + eina_pipe_free(comm[1]); fail_if(did != EINA_TRUE); diff --git a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c index a2dfe55993..30ea06c334 100644 --- a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c +++ b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c @@ -647,7 +647,7 @@ EFL_START_TEST(ecore_test_ecore_thread_eina_thread_queue_t7) thq1 = eina_thread_queue_new(); if (!thq1) fail(); - if (pipe(p) != 0) + if (eina_pipe_new(p) != 0) { ck_abort_msg("ERR: pipe create fail\n"); } @@ -661,7 +661,7 @@ EFL_START_TEST(ecore_test_ecore_thread_eina_thread_queue_t7) { char buf; - if (read(p[0], &buf, 1) != 1) + if (eina_pipe_read(p[0], &buf, 1) != 1) if (DEBUG) printf("Error reading from pipe\n"); msg = eina_thread_queue_wait(thq1, &ref); if (msg) @@ -675,8 +675,8 @@ EFL_START_TEST(ecore_test_ecore_thread_eina_thread_queue_t7) if (DEBUG) printf("msg fd ok\n"); ecore_thread_wait(eth1, 0.1); eina_thread_queue_free(thq1); - close(p[0]); - close(p[1]); + eina_pipe_free(p[0]); + eina_pipe_free(p[1]); } EFL_END_TEST diff --git a/src/tests/ecore/efl_app_test_loop_fd.c b/src/tests/ecore/efl_app_test_loop_fd.c index 26bd318cd1..b97dec6d20 100644 --- a/src/tests/ecore/efl_app_test_loop_fd.c +++ b/src/tests/ecore/efl_app_test_loop_fd.c @@ -31,7 +31,7 @@ EFL_START_TEST(ecore_test_efl_loop_fd) int comm[2]; int ret; - ret = pipe(comm); + ret = eina_pipe_new(comm); fail_if(ret != 0); fd = efl_add(EFL_LOOP_FD_CLASS, efl_main_loop_get(), @@ -39,13 +39,13 @@ EFL_START_TEST(ecore_test_efl_loop_fd) efl_event_callback_add(efl_added, EFL_LOOP_FD_EVENT_READ, _eo_read_cb, &did)); fail_if(fd == NULL); - ret = write(comm[1], &did, 1); + ret = eina_pipe_write(comm[1], &did, 1); fail_if(ret != 1); efl_loop_begin(efl_main_loop_get()); - close(comm[0]); - close(comm[1]); + eina_pipe_free(comm[0]); + eina_pipe_free(comm[1]); fail_if(did == EINA_FALSE); @@ -68,7 +68,7 @@ EFL_START_TEST(ecore_test_efl_loop_fd_lifecycle) int comm[2]; int ret; - ret = pipe(comm); + ret = eina_pipe_new(comm); fail_if(ret != 0); fd = efl_add(EFL_LOOP_FD_CLASS, efl_main_loop_get(), @@ -77,13 +77,13 @@ EFL_START_TEST(ecore_test_efl_loop_fd_lifecycle) efl_event_callback_add(efl_added, EFL_EVENT_DEL, _efl_del_cb, &dead)); fail_if(fd == NULL); - ret = write(comm[1], &did, 1); + ret = eina_pipe_write(comm[1], &did, 1); fail_if(ret != 1); efl_loop_begin(efl_main_loop_get()); - close(comm[0]); - close(comm[1]); + eina_pipe_free(comm[0]); + eina_pipe_free(comm[1]); fail_if(did == EINA_FALSE); fail_if(dead == EINA_TRUE); |