ecore_con: fix compiling on OSX and BSD

TCP_CORK is Linux only. TCP_NOPUSH is supposed to
do the same thing than TCP_CORK, but on BSD (including
Mac OS X).

We now check for the existance of TCP_CORK or TCP_NOPUSH,
and use the right option. If none exist, cork_{set,get}
will just fail.
This commit is contained in:
Jean Guyomarc'h 2016-08-23 11:32:21 +02:00 committed by Jean Guyomarc'h
parent 6de774455b
commit 0ced470e39
2 changed files with 39 additions and 7 deletions

View File

@ -452,6 +452,11 @@ netinet/in.h \
EFL_CHECK_PATH_MAX
#### Checks for defines in headers
EFL_CHECK_DEFINE(TCP_CORK, netinet/tcp.h)
EFL_CHECK_DEFINE(TCP_NOPUSH, netinet/tcp.h)
#### Checks for types
# wchar_t

View File

@ -177,22 +177,41 @@ _efl_net_socket_tcp_no_delay_get(Eo *o, Efl_Net_Socket_Tcp_Data *pd)
return pd->no_delay;
}
static inline int
_cork_option_get(void)
{
#if defined(HAVE_TCP_CORK)
return TCP_CORK;
#elif defined(HAVE_TCP_NOPUSH)
return TCP_NOPUSH;
#else
return -1;
#endif
}
EOLIAN static Eina_Bool
_efl_net_socket_tcp_cork_set(Eo *o, Efl_Net_Socket_Tcp_Data *pd, Eina_Bool cork)
{
int value, fd;
int value, fd, option;
Eina_Bool old = pd->cork;
option = _cork_option_get();
if (EINA_UNLIKELY(option < 0))
{
ERR("Could not find a TCP_CORK equivalent on your system");
return EINA_FALSE;
}
pd->cork = cork;
fd = efl_loop_fd_get(o);
if (fd < 0) return EINA_TRUE; /* postpone until fd_set() */
value = cork;
if (setsockopt(fd, IPPROTO_TCP, TCP_CORK, &value, sizeof(value)) < 0)
if (setsockopt(fd, IPPROTO_TCP, option, &value, sizeof(value)) < 0)
{
ERR("setsockopt(%d, IPPROTO_TCP, TCP_CORK, %d): %s",
fd, value, strerror(errno));
ERR("setsockopt(%d, IPPROTO_TCP, 0x%x, %d): %s",
fd, option, value, strerror(errno));
pd->cork = old;
return EINA_FALSE;
}
@ -205,6 +224,14 @@ _efl_net_socket_tcp_cork_get(Eo *o, Efl_Net_Socket_Tcp_Data *pd)
{
int value = 0, fd;
socklen_t valuelen;
int option;
option = _cork_option_get();
if (EINA_UNLIKELY(option < 0))
{
ERR("Could not find a TCP_CORK equivalent on your system");
return EINA_FALSE;
}
fd = efl_loop_fd_get(o);
if (fd < 0) return pd->cork;
@ -213,10 +240,10 @@ _efl_net_socket_tcp_cork_get(Eo *o, Efl_Net_Socket_Tcp_Data *pd)
* elsewhere by nasty users.
*/
valuelen = sizeof(value);
if (getsockopt(fd, IPPROTO_TCP, TCP_CORK, &value, &valuelen) < 0)
if (getsockopt(fd, IPPROTO_TCP, option, &value, &valuelen) < 0)
{
ERR("getsockopt(%d, IPPROTO_TCP, TCP_CORK): %s",
fd, strerror(errno));
ERR("getsockopt(%d, IPPROTO_TCP, 0x%x): %s",
fd, option, strerror(errno));
return EINA_FALSE;
}