2008-10-29 01:04:52 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
|
|
|
#include <errno.h>
|
2015-12-07 20:53:23 -08:00
|
|
|
#include <direct.h>
|
2015-11-11 06:04:37 -08:00
|
|
|
# include <sys/time.h>
|
2008-10-29 01:04:52 -07:00
|
|
|
|
2012-02-17 12:48:11 -08:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
2008-10-29 01:04:52 -07:00
|
|
|
#include <winsock2.h>
|
|
|
|
#undef WIN32_LEAN_AND_MEAN
|
|
|
|
|
2019-05-15 04:27:37 -07:00
|
|
|
#include "evil_private.h"
|
2008-10-29 01:04:52 -07:00
|
|
|
|
2008-11-21 14:57:45 -08:00
|
|
|
|
2009-02-22 11:20:23 -08:00
|
|
|
LONGLONG _evil_time_freq;
|
|
|
|
LONGLONG _evil_time_count;
|
2008-11-21 14:57:45 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Time related functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
evil: Rename EAPI macro to EVIL_API in Evil library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
```__attribute__ ((visibility ("default")))``` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
```
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
```__atttribute__((visibility("default")))```
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: raster, vtorri, jptiz, lucas, woohyun
Reviewed By: vtorri, jptiz
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12182
2020-11-12 08:47:38 -08:00
|
|
|
EVIL_API double
|
2010-04-01 13:13:40 -07:00
|
|
|
evil_time_get(void)
|
2009-02-22 11:20:23 -08:00
|
|
|
{
|
|
|
|
LARGE_INTEGER count;
|
|
|
|
|
|
|
|
QueryPerformanceCounter(&count);
|
|
|
|
|
2020-07-28 13:26:35 -07:00
|
|
|
return (double)(count.QuadPart - _evil_time_count)/ (double)_evil_time_freq;
|
2009-02-22 11:20:23 -08:00
|
|
|
}
|
2008-11-21 14:57:45 -08:00
|
|
|
|
2008-10-29 01:04:52 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sockets and pipe related functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
evil: Rename EAPI macro to EVIL_API in Evil library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
```__attribute__ ((visibility ("default")))``` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
```
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
```__atttribute__((visibility("default")))```
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: raster, vtorri, jptiz, lucas, woohyun
Reviewed By: vtorri, jptiz
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12182
2020-11-12 08:47:38 -08:00
|
|
|
EVIL_API int
|
2008-10-29 01:04:52 -07:00
|
|
|
evil_sockets_init(void)
|
|
|
|
{
|
|
|
|
WSADATA wsa_data;
|
2015-01-28 06:39:44 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2008-10-29 01:04:52 -07:00
|
|
|
|
2015-01-28 06:39:44 -08:00
|
|
|
return 0;
|
2008-10-29 01:04:52 -07:00
|
|
|
}
|
|
|
|
|
evil: Rename EAPI macro to EVIL_API in Evil library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
```__attribute__ ((visibility ("default")))``` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
```
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
```__atttribute__((visibility("default")))```
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: raster, vtorri, jptiz, lucas, woohyun
Reviewed By: vtorri, jptiz
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12182
2020-11-12 08:47:38 -08:00
|
|
|
EVIL_API void
|
2008-10-29 01:04:52 -07:00
|
|
|
evil_sockets_shutdown(void)
|
|
|
|
{
|
|
|
|
WSACleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The code of the following functions has been kindly offered
|
|
|
|
* by Tor Lillqvist.
|
|
|
|
*/
|
evil: Rename EAPI macro to EVIL_API in Evil library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
```__attribute__ ((visibility ("default")))``` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
```
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
```__atttribute__((visibility("default")))```
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: raster, vtorri, jptiz, lucas, woohyun
Reviewed By: vtorri, jptiz
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12182
2020-11-12 08:47:38 -08:00
|
|
|
EVIL_API int
|
2008-10-29 01:04:52 -07:00
|
|
|
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;
|
|
|
|
|
2010-01-29 01:34:26 -08:00
|
|
|
arg = 0;
|
2008-10-29 01:04:52 -07:00
|
|
|
if (ioctlsocket (socket1, FIONBIO, &arg) == SOCKET_ERROR)
|
|
|
|
goto out2;
|
|
|
|
|
2010-01-29 01:34:26 -08:00
|
|
|
arg = 0;
|
2008-10-29 01:04:52 -07:00
|
|
|
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);
|
|
|
|
|
2013-03-10 03:41:20 -07:00
|
|
|
fds[0] = -1;
|
|
|
|
fds[1] = -1;
|
2008-10-29 01:04:52 -07:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|