cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=662f7d33105029b664b57848cc7afec7bf7a6387

commit 662f7d33105029b664b57848cc7afec7bf7a6387
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Tue Apr 18 16:56:01 2017 -0700

    ecore_con: use new API eina_file_close_on_exec.
---
 src/lib/ecore_con/ecore_con.c           | 33 +++------------------------------
 src/lib/ecore_con/efl_net_dialer_http.c | 13 +------------
 src/lib/ecore_con/efl_net_server_fd.c   | 15 ++-------------
 3 files changed, 6 insertions(+), 55 deletions(-)

diff --git a/src/lib/ecore_con/ecore_con.c b/src/lib/ecore_con/ecore_con.c
index 64ac60f..ce881fa 100644
--- a/src/lib/ecore_con/ecore_con.c
+++ b/src/lib/ecore_con/ecore_con.c
@@ -587,10 +587,9 @@ efl_net_socket4(int domain, int type, int protocol, 
Eina_Bool close_on_exec)
      {
         if (close_on_exec)
           {
-             if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+             if (!eina_file_close_on_exec(fd, EINA_TRUE))
                {
                   int errno_bkp = errno;
-                  ERR("fcntl(" SOCKET_FMT ", F_SETFD, FD_CLOEXEC): %s", fd, 
strerror(errno));
                   closesocket(fd);
                   fd = INVALID_SOCKET;
                   errno = errno_bkp;
@@ -815,25 +814,12 @@ _efl_net_connect_async_end(void *data, Ecore_Thread 
*thread EINA_UNUSED)
    /* if it wasn't a close on exec, release the socket to be passed to child */
    if ((!d->close_on_exec) && (d->sockfd != INVALID_SOCKET))
      {
-        int flags = fcntl(d->sockfd, F_GETFD);
-        if (flags < 0)
+        if (!eina_file_close_on_exec(d->sockfd, EINA_FALSE))
           {
              d->error = errno;
-             ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", d->sockfd, 
eina_error_msg_get(d->error));
              closesocket(d->sockfd);
              d->sockfd = INVALID_SOCKET;
           }
-        else
-          {
-             flags &= (~FD_CLOEXEC);
-             if (fcntl(d->sockfd, F_SETFD, flags) < 0)
-               {
-                  d->error = errno;
-                  ERR("fcntl(" SOCKET_FMT ", F_SETFD, %#x): %s", d->sockfd, 
flags, eina_error_msg_get(d->error));
-                  closesocket(d->sockfd);
-                  d->sockfd = INVALID_SOCKET;
-               }
-          }
      }
 #endif
    d->cb((void *)d->data, d->addr, d->addrlen, d->sockfd, d->error);
@@ -2222,25 +2208,12 @@ _efl_net_ip_connect_async_end(void *data, Ecore_Thread 
*thread EINA_UNUSED)
    /* if it wasn't a close on exec, release the socket to be passed to child */
    if ((!d->close_on_exec) && (d->sockfd != INVALID_SOCKET))
      {
-        int flags = fcntl(d->sockfd, F_GETFD);
-        if (flags < 0)
+        if (!eina_file_close_on_exec(d->sockfd, EINA_FALSE))
           {
              d->error = errno;
-             ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", d->sockfd, 
strerror(errno));
              closesocket(d->sockfd);
              d->sockfd = INVALID_SOCKET;
           }
-        else
-          {
-             flags &= (~FD_CLOEXEC);
-             if (fcntl(d->sockfd, F_SETFD, flags) < 0)
-               {
-                  d->error = errno;
-                  ERR("fcntl(" SOCKET_FMT ", F_SETFD, %#x): %s", d->sockfd, 
flags, strerror(errno));
-                  closesocket(d->sockfd);
-                  d->sockfd = INVALID_SOCKET;
-               }
-          }
      }
 #endif
 
diff --git a/src/lib/ecore_con/efl_net_dialer_http.c 
b/src/lib/ecore_con/efl_net_dialer_http.c
index 6c4a463..8bc273a 100644
--- a/src/lib/ecore_con/efl_net_dialer_http.c
+++ b/src/lib/ecore_con/efl_net_dialer_http.c
@@ -1780,18 +1780,7 @@ _efl_net_dialer_http_efl_io_closer_close_on_exec_set(Eo 
*o EINA_UNUSED, Efl_Net_
 
    if (pd->fd == INVALID_SOCKET) return EINA_TRUE; /* postpone until 
_efl_net_dialer_http_socket_open */
 
-   flags = fcntl(pd->fd, F_GETFD);
-   if (flags < 0)
-     {
-        ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", pd->fd, strerror(errno));
-        pd->close_on_exec = old;
-        return EINA_FALSE;
-     }
-   if (close_on_exec)
-     flags |= FD_CLOEXEC;
-   else
-     flags &= (~FD_CLOEXEC);
-   if (fcntl(pd->fd, F_SETFD, flags) < 0)
+   if (!eina_file_close_on_exec(pd->fd, close_on_exec))
      {
         ERR("fcntl(" SOCKET_FMT ", F_SETFD, %#x): %s", pd->fd, flags, 
strerror(errno));
         pd->close_on_exec = old;
diff --git a/src/lib/ecore_con/efl_net_server_fd.c 
b/src/lib/ecore_con/efl_net_server_fd.c
index 0c76af2..de699b2 100644
--- a/src/lib/ecore_con/efl_net_server_fd.c
+++ b/src/lib/ecore_con/efl_net_server_fd.c
@@ -51,7 +51,7 @@ efl_net_accept4(SOCKET fd, struct sockaddr *addr, socklen_t 
*addrlen, Eina_Bool
 #ifdef FD_CLOEXEC
    if (close_on_exec)
      {
-        if (fcntl(client, F_SETFD, FD_CLOEXEC) < 0)
+        if (!eina_file_close_on_exec(client, EINA_TRUE))
           {
              int errno_bkp = errno;
              ERR("fcntl(" SOCKET_FMT ", F_SETFD, FD_CLOEXEC): %s", client, 
strerror(errno));
@@ -280,18 +280,7 @@ _efl_net_server_fd_close_on_exec_set(Eo *o, 
Efl_Net_Server_Fd_Data *pd, Eina_Boo
    fd = efl_loop_fd_get(o);
    if (fd == INVALID_SOCKET) return EINA_TRUE; /* postpone until fd_set() */
 
-   flags = fcntl(fd, F_GETFD);
-   if (flags < 0)
-     {
-        ERR("fcntl(" SOCKET_FMT ", F_GETFD): %s", fd, strerror(errno));
-        pd->close_on_exec = old;
-        return EINA_FALSE;
-     }
-   if (close_on_exec)
-     flags |= FD_CLOEXEC;
-   else
-     flags &= (~FD_CLOEXEC);
-   if (fcntl(fd, F_SETFD, flags) < 0)
+   if (!eina_file_close_on_exec(fd, close_on_exec))
      {
         ERR("fcntl(" SOCKET_FMT ", F_SETFD, %#x): %s", fd, flags, 
strerror(errno));
         pd->close_on_exec = old;

-- 


Reply via email to