summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-08-24 12:02:17 -0300
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-08-24 12:02:17 -0300
commit164d9ddfde00800ce5d68c22b581ffc5add91bbc (patch)
treee495f5d74807d5b1cecde85273ffca743df06b46 /src
parenta016ab751c4875d66e7c7c8dd5c5272a6f03f084 (diff)
Revert "ecore_con: use F_CLOEXEC instead of SOCK_CLOEXEC"
This reverts commit 99d37838f32ef33b805bcefc7dc0320cfda05a0a. will be fixed in a better way with the following commit.
Diffstat (limited to 'src')
-rw-r--r--src/lib/ecore_con/efl_net_dialer_tcp.c24
-rw-r--r--src/lib/ecore_con/efl_net_server_fd.c19
-rw-r--r--src/lib/ecore_con/efl_net_server_tcp.c24
3 files changed, 25 insertions, 42 deletions
diff --git a/src/lib/ecore_con/efl_net_dialer_tcp.c b/src/lib/ecore_con/efl_net_dialer_tcp.c
index 0866bcb..b835d93 100644
--- a/src/lib/ecore_con/efl_net_dialer_tcp.c
+++ b/src/lib/ecore_con/efl_net_dialer_tcp.c
@@ -11,9 +11,6 @@
11#include "Ecore_Con.h" 11#include "Ecore_Con.h"
12#include "ecore_con_private.h" 12#include "ecore_con_private.h"
13 13
14#ifdef HAVE_FCNTL
15# include <fcntl.h>
16#endif
17#ifdef HAVE_SYS_SOCKET_H 14#ifdef HAVE_SYS_SOCKET_H
18# include <sys/socket.h> 15# include <sys/socket.h>
19#endif 16#endif
@@ -54,7 +51,7 @@ _efl_net_dialer_tcp_efl_net_dialer_dial(Eo *o, Efl_Net_Dialer_Tcp_Data *pd EINA_
54{ 51{
55 struct sockaddr_storage addr = {}; 52 struct sockaddr_storage addr = {};
56 char *str, *host, *port; 53 char *str, *host, *port;
57 int r, fd; 54 int r, fd, extra_flags = 0;
58 socklen_t addrlen; 55 socklen_t addrlen;
59 char buf[INET6_ADDRSTRLEN + sizeof("[]:65536")]; 56 char buf[INET6_ADDRSTRLEN + sizeof("[]:65536")];
60 57
@@ -121,26 +118,17 @@ _efl_net_dialer_tcp_efl_net_dialer_dial(Eo *o, Efl_Net_Dialer_Tcp_Data *pd EINA_
121 efl_event_callback_call(o, EFL_NET_DIALER_EVENT_RESOLVED, NULL); 118 efl_event_callback_call(o, EFL_NET_DIALER_EVENT_RESOLVED, NULL);
122 } 119 }
123 120
124 fd = socket(addr.ss_family, SOCK_STREAM, IPPROTO_TCP); 121 if (efl_net_socket_fd_close_on_exec_get(o))
122 extra_flags |= SOCK_CLOEXEC;
123
124 fd = socket(addr.ss_family, SOCK_STREAM | extra_flags, IPPROTO_TCP);
125 if (fd < 0) 125 if (fd < 0)
126 { 126 {
127 ERR("socket(%d, SOCK_STREAM | %#x, IPPROTO_TCP): %s", 127 ERR("socket(%d, SOCK_STREAM | %#x, IPPROTO_TCP): %s",
128 addr.ss_family, strerror(errno)); 128 addr.ss_family, extra_flags, strerror(errno));
129 return errno; 129 return errno;
130 } 130 }
131 131
132 if (efl_net_socket_fd_close_on_exec_get(o))
133 {
134 r = fcntl(fd, F_SETFD, FD_CLOEXEC);
135 if (EINA_UNLIKELY(r < 0))
136 {
137 const int err = errno;
138 ERR("fcntl(F_SETFD, FD_CLOEXEC): %s", strerror(err));
139 close(fd);
140 return err;
141 }
142 }
143
144 r = connect(fd, (struct sockaddr *)&addr, addrlen); 132 r = connect(fd, (struct sockaddr *)&addr, addrlen);
145 if (r < 0) 133 if (r < 0)
146 { 134 {
diff --git a/src/lib/ecore_con/efl_net_server_fd.c b/src/lib/ecore_con/efl_net_server_fd.c
index fe1e046..06af641 100644
--- a/src/lib/ecore_con/efl_net_server_fd.c
+++ b/src/lib/ecore_con/efl_net_server_fd.c
@@ -39,7 +39,7 @@ _efl_net_server_fd_event_read(void *data EINA_UNUSED, const Eo_Event *event)
39 unsigned int count, limit; 39 unsigned int count, limit;
40 Eina_Bool reject_excess, do_reject = EINA_FALSE; 40 Eina_Bool reject_excess, do_reject = EINA_FALSE;
41 struct sockaddr_storage addr; 41 struct sockaddr_storage addr;
42 int client, fd; 42 int client, fd, flags = 0;
43 socklen_t addrlen; 43 socklen_t addrlen;
44 44
45 count = efl_net_server_clients_count_get(o); 45 count = efl_net_server_clients_count_get(o);
@@ -57,8 +57,15 @@ _efl_net_server_fd_event_read(void *data EINA_UNUSED, const Eo_Event *event)
57 57
58 fd = efl_loop_fd_get(o); 58 fd = efl_loop_fd_get(o);
59 59
60 if (efl_net_server_fd_close_on_exec_get(o))
61 flags |= SOCK_CLOEXEC;
62
60 addrlen = sizeof(addr); 63 addrlen = sizeof(addr);
64#ifdef HAVE_ACCEPT4
65 client = accept4(fd, (struct sockaddr *)&addr, &addrlen, flags);
66#else
61 client = accept(fd, (struct sockaddr *)&addr, &addrlen); 67 client = accept(fd, (struct sockaddr *)&addr, &addrlen);
68#endif
62 if (client < 0) 69 if (client < 0)
63 { 70 {
64 Eina_Error err = errno; 71 Eina_Error err = errno;
@@ -66,11 +73,11 @@ _efl_net_server_fd_event_read(void *data EINA_UNUSED, const Eo_Event *event)
66 efl_event_callback_call(o, EFL_NET_SERVER_EVENT_ERROR, &err); 73 efl_event_callback_call(o, EFL_NET_SERVER_EVENT_ERROR, &err);
67 return; 74 return;
68 } 75 }
69 if (efl_net_server_fd_close_on_exec_get(o)) 76
70 { 77#ifndef HAVE_ACCEPT4
71 if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) 78 if (fcntl(fd, F_SETFD, flags) < 0)
72 ERR("fcntl(%d, F_SETFD, FD_CLOEXEC): %s", fd, strerror(errno)); 79 ERR("fcntl(%d, F_SETFD, %#x): %s", fd, flags, strerror(errno));
73 } 80#endif
74 81
75 if (do_reject) 82 if (do_reject)
76 efl_net_server_fd_client_reject(o, client); 83 efl_net_server_fd_client_reject(o, client);
diff --git a/src/lib/ecore_con/efl_net_server_tcp.c b/src/lib/ecore_con/efl_net_server_tcp.c
index 78e3857..25bfb01 100644
--- a/src/lib/ecore_con/efl_net_server_tcp.c
+++ b/src/lib/ecore_con/efl_net_server_tcp.c
@@ -11,9 +11,6 @@
11#include "Ecore_Con.h" 11#include "Ecore_Con.h"
12#include "ecore_con_private.h" 12#include "ecore_con_private.h"
13 13
14#ifdef HAVE_FCNTL
15# include <fcntl.h>
16#endif
17#ifdef HAVE_SYS_SOCKET_H 14#ifdef HAVE_SYS_SOCKET_H
18# include <sys/socket.h> 15# include <sys/socket.h>
19#endif 16#endif
@@ -37,7 +34,7 @@ _efl_net_server_tcp_efl_net_server_serve(Eo *o, void *pd EINA_UNUSED, const char
37{ 34{
38 struct sockaddr_storage addr = {}; 35 struct sockaddr_storage addr = {};
39 char *str, *host, *port; 36 char *str, *host, *port;
40 int r, fd; 37 int r, fd, extra_flags = 0;
41 socklen_t addrlen; 38 socklen_t addrlen;
42 char buf[INET6_ADDRSTRLEN + sizeof("[]:65536")]; 39 char buf[INET6_ADDRSTRLEN + sizeof("[]:65536")];
43 Eina_Error err = 0; 40 Eina_Error err = 0;
@@ -100,27 +97,18 @@ _efl_net_server_tcp_efl_net_server_serve(Eo *o, void *pd EINA_UNUSED, const char
100 if (efl_net_ip_port_fmt(buf, sizeof(buf), (struct sockaddr *)&addr)) 97 if (efl_net_ip_port_fmt(buf, sizeof(buf), (struct sockaddr *)&addr))
101 efl_net_server_address_set(o, buf); 98 efl_net_server_address_set(o, buf);
102 99
100 if (efl_net_server_fd_close_on_exec_get(o))
101 extra_flags |= SOCK_CLOEXEC;
103 102
104 fd = socket(addr.ss_family, SOCK_STREAM, IPPROTO_TCP); 103 fd = socket(addr.ss_family, SOCK_STREAM | extra_flags, IPPROTO_TCP);
105 if (fd < 0) 104 if (fd < 0)
106 { 105 {
107 err = errno; 106 err = errno;
108 ERR("socket(%d, SOCK_STREAM, IPPROTO_TCP): %s", 107 ERR("socket(%d, SOCK_STREAM | %#x, IPPROTO_TCP): %s",
109 addr.ss_family, strerror(errno)); 108 addr.ss_family, extra_flags, strerror(errno));
110 goto error_socket; 109 goto error_socket;
111 } 110 }
112 111
113 if (efl_net_server_fd_close_on_exec_get(o))
114 {
115 r = fcntl(fd, F_SETFD, FD_CLOEXEC);
116 if (EINA_UNLIKELY(r < 0))
117 {
118 const int err = errno;
119 ERR("fcntl(F_SETFD, FD_CLOEXEC): %s", strerror(err));
120 goto error_listen;
121 }
122 }
123
124 efl_loop_fd_set(o, fd); 112 efl_loop_fd_set(o, fd);
125 113
126 r = bind(fd, (struct sockaddr *)&addr, addrlen); 114 r = bind(fd, (struct sockaddr *)&addr, addrlen);