summaryrefslogtreecommitdiff
path: root/src/lib/ecore_con/efl_net_server_unix.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-18 12:17:08 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-18 12:53:32 -0200
commit5818dc71da2b058e6f38f218785b08660e8b92e6 (patch)
treeb9285c1a753e8d1e075d491d6894c7172b422cf0 /src/lib/ecore_con/efl_net_server_unix.c
parent0f1e7bad92cea4c17b87987d4be9aba107fc3018 (diff)
efl_net: use SOCKET_FMT to format SOCKET so it works on UNIX and Windows.
On Windows SOCKET is unsigned, thus will cause sign errors when formatting with "%d" or comparing with signed values. On UNIX it was quiet and easy to miss, thus a new #define can be used to check for those. It will use 'unsigned long' as SOCKET, thus will complain out loud and not even work correctly when using pointers on 64bits UNIX on mistakes -- which should improve the situation. This helped to fix lots of missing conversions, all fixed. This partially addresses D4357.
Diffstat (limited to '')
-rw-r--r--src/lib/ecore_con/efl_net_server_unix.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/lib/ecore_con/efl_net_server_unix.c b/src/lib/ecore_con/efl_net_server_unix.c
index 70ca83aeb7..7e90bb8cd8 100644
--- a/src/lib/ecore_con/efl_net_server_unix.c
+++ b/src/lib/ecore_con/efl_net_server_unix.c
@@ -112,7 +112,7 @@ _efl_net_server_unix_bind_job(void *data, const Efl_Event *event EINA_UNUSED)
112 err = 0; 112 err = 0;
113 continue; 113 continue;
114 } 114 }
115 DBG("bind(%d, %s): %s", fd, address, eina_error_msg_get(err)); 115 DBG("bind(" SOCKET_FMT ", %s): %s", fd, address, eina_error_msg_get(err));
116 goto error; 116 goto error;
117 } 117 }
118 break; 118 break;
@@ -125,7 +125,7 @@ _efl_net_server_unix_bind_job(void *data, const Efl_Event *event EINA_UNUSED)
125 if (r != 0) 125 if (r != 0)
126 { 126 {
127 err = efl_net_socket_error_get(); 127 err = efl_net_socket_error_get();
128 DBG("listen(%d): %s", fd, eina_error_msg_get(err)); 128 DBG("listen(" SOCKET_FMT "): %s", fd, eina_error_msg_get(err));
129 goto error; 129 goto error;
130 } 130 }
131 131
@@ -133,7 +133,7 @@ _efl_net_server_unix_bind_job(void *data, const Efl_Event *event EINA_UNUSED)
133 if (getsockname(fd, (struct sockaddr *)&addr, &addrlen) != 0) 133 if (getsockname(fd, (struct sockaddr *)&addr, &addrlen) != 0)
134 { 134 {
135 err = efl_net_socket_error_get(); 135 err = efl_net_socket_error_get();
136 ERR("getsockname(%d): %s", fd, eina_error_msg_get(err)); 136 ERR("getsockname(" SOCKET_FMT "): %s", fd, eina_error_msg_get(err));
137 goto error; 137 goto error;
138 } 138 }
139 else 139 else
@@ -148,7 +148,7 @@ _efl_net_server_unix_bind_job(void *data, const Efl_Event *event EINA_UNUSED)
148 } 148 }
149 } 149 }
150 150
151 DBG("fd=%d serving at %s", fd, address); 151 DBG("fd=" SOCKET_FMT " serving at %s", fd, address);
152 efl_net_server_serving_set(o, EINA_TRUE); 152 efl_net_server_serving_set(o, EINA_TRUE);
153 153
154 error: 154 error:
@@ -156,7 +156,7 @@ _efl_net_server_unix_bind_job(void *data, const Efl_Event *event EINA_UNUSED)
156 { 156 {
157 efl_event_callback_call(o, EFL_NET_SERVER_EVENT_ERROR, &err); 157 efl_event_callback_call(o, EFL_NET_SERVER_EVENT_ERROR, &err);
158 if (fd != INVALID_SOCKET) closesocket(fd); 158 if (fd != INVALID_SOCKET) closesocket(fd);
159 efl_loop_fd_set(o, INVALID_SOCKET); 159 efl_loop_fd_set(o, SOCKET_TO_LOOP_FD(INVALID_SOCKET));
160 } 160 }
161 161
162 efl_unref(o); 162 efl_unref(o);
@@ -165,7 +165,7 @@ _efl_net_server_unix_bind_job(void *data, const Efl_Event *event EINA_UNUSED)
165EOLIAN static Eina_Error 165EOLIAN static Eina_Error
166_efl_net_server_unix_efl_net_server_fd_socket_activate(Eo *o, Efl_Net_Server_Unix_Data *pd EINA_UNUSED, const char *address) 166_efl_net_server_unix_efl_net_server_fd_socket_activate(Eo *o, Efl_Net_Server_Unix_Data *pd EINA_UNUSED, const char *address)
167{ 167{
168 EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_loop_fd_get(o) != INVALID_SOCKET, EALREADY); 168 EINA_SAFETY_ON_TRUE_RETURN_VAL((SOCKET)efl_loop_fd_get(o) != INVALID_SOCKET, EALREADY);
169 EINA_SAFETY_ON_NULL_RETURN_VAL(address, EINVAL); 169 EINA_SAFETY_ON_NULL_RETURN_VAL(address, EINVAL);
170 170
171#ifndef HAVE_SYSTEMD 171#ifndef HAVE_SYSTEMD
@@ -177,7 +177,7 @@ _efl_net_server_unix_efl_net_server_fd_socket_activate(Eo *o, Efl_Net_Server_Uni
177 Eina_Error err; 177 Eina_Error err;
178 struct sockaddr_storage *addr; 178 struct sockaddr_storage *addr;
179 socklen_t addrlen; 179 socklen_t addrlen;
180 int fd; 180 SOCKET fd;
181 181
182 err = efl_net_ip_socket_activate_check(address, AF_UNIX, SOCK_STREAM, &listening); 182 err = efl_net_ip_socket_activate_check(address, AF_UNIX, SOCK_STREAM, &listening);
183 if (err) return err; 183 if (err) return err;
@@ -192,7 +192,7 @@ _efl_net_server_unix_efl_net_server_fd_socket_activate(Eo *o, Efl_Net_Server_Uni
192 if (listen(fd, 0) != 0) 192 if (listen(fd, 0) != 0)
193 { 193 {
194 err = efl_net_socket_error_get(); 194 err = efl_net_socket_error_get();
195 DBG("listen(%d): %s", fd, eina_error_msg_get(err)); 195 DBG("listen(" SOCKET_FMT "): %s", fd, eina_error_msg_get(err));
196 goto error; 196 goto error;
197 } 197 }
198 } 198 }
@@ -201,19 +201,19 @@ _efl_net_server_unix_efl_net_server_fd_socket_activate(Eo *o, Efl_Net_Server_Uni
201 if (getsockname(fd, (struct sockaddr *)&addr, &addrlen) != 0) 201 if (getsockname(fd, (struct sockaddr *)&addr, &addrlen) != 0)
202 { 202 {
203 err = efl_net_socket_error_get(); 203 err = efl_net_socket_error_get();
204 ERR("getsockname(%d): %s", fd, eina_error_msg_get(err)); 204 ERR("getsockname(" SOCKET_FMT "): %s", fd, eina_error_msg_get(err));
205 goto error; 205 goto error;
206 } 206 }
207 else if (efl_net_ip_port_fmt(buf, sizeof(buf), (struct sockaddr *)&addr)) 207 else if (efl_net_ip_port_fmt(buf, sizeof(buf), (struct sockaddr *)&addr))
208 efl_net_server_address_set(o, buf); 208 efl_net_server_address_set(o, buf);
209 209
210 DBG("fd=%d serving at %s", fd, address); 210 DBG("fd=" SOCKET_FMT " serving at %s", fd, address);
211 efl_net_server_serving_set(o, EINA_TRUE); 211 efl_net_server_serving_set(o, EINA_TRUE);
212 return 0; 212 return 0;
213 213
214 error: 214 error:
215 efl_net_server_fd_family_set(o, AF_UNSPEC); 215 efl_net_server_fd_family_set(o, AF_UNSPEC);
216 efl_loop_fd_set(o, INVALID_SOCKET); 216 efl_loop_fd_set(o, SOCKET_TO_LOOP_FD(INVALID_SOCKET));
217 closesocket(fd); 217 closesocket(fd);
218 return err; 218 return err;
219 } 219 }
@@ -266,7 +266,7 @@ _efl_net_server_unix_efl_net_server_fd_client_add(Eo *o, Efl_Net_Server_Unix_Dat
266 efl_loop_fd_set(efl_added, client_fd)); 266 efl_loop_fd_set(efl_added, client_fd));
267 if (!client) 267 if (!client)
268 { 268 {
269 ERR("could not create client object fd=%d", client_fd); 269 ERR("could not create client object fd=" SOCKET_FMT, (SOCKET)client_fd);
270 closesocket(client_fd); 270 closesocket(client_fd);
271 return; 271 return;
272 } 272 }
@@ -295,7 +295,7 @@ _efl_net_server_unix_efl_net_server_fd_client_reject(Eo *o, Efl_Net_Server_Unix_
295 else 295 else
296 { 296 {
297 if (!efl_net_unix_fmt(str, sizeof(str), client_fd, &addr, addrlen)) 297 if (!efl_net_unix_fmt(str, sizeof(str), client_fd, &addr, addrlen))
298 ERR("could not format rejected client unix address fd=%d", client_fd); 298 ERR("could not format rejected client unix address fd=" SOCKET_FMT, (SOCKET)client_fd);
299 } 299 }
300 300
301 closesocket(client_fd); 301 closesocket(client_fd);