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-01 16:01:57 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-01 16:37:04 -0200
commitc2630c829f45df5973582a4259d2a0b127cc7cae (patch)
treeabe4cd1f4cd6d4235faf5e731b114ac039d62501 /src/lib/ecore_con/efl_net_server_unix.c
parent3ac1812a1f9915f4a8545e5db529bb8003ffdeaa (diff)
efl_net_server support systemd socket activation.
It includes extensive verifications to avoid mistakes and usage of incorrect sockets.
Diffstat (limited to '')
-rw-r--r--src/lib/ecore_con/efl_net_server_unix.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/lib/ecore_con/efl_net_server_unix.c b/src/lib/ecore_con/efl_net_server_unix.c
index 845df44259..29d83168d7 100644
--- a/src/lib/ecore_con/efl_net_server_unix.c
+++ b/src/lib/ecore_con/efl_net_server_unix.c
@@ -163,6 +163,64 @@ _efl_net_server_unix_bind_job(void *data, const Efl_Event *event EINA_UNUSED)
163} 163}
164 164
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)
167{
168 EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_loop_fd_get(o) != INVALID_SOCKET, EALREADY);
169 EINA_SAFETY_ON_NULL_RETURN_VAL(address, EINVAL);
170
171#ifndef HAVE_SYSTEMD
172 return efl_net_server_fd_socket_activate(efl_super(o, MY_CLASS), address);
173#else
174 {
175 char buf[INET6_ADDRSTRLEN + sizeof("[]:65536")];
176 Eina_Bool listening;
177 Eina_Error err;
178 struct sockaddr_storage *addr;
179 socklen_t addrlen;
180 int fd;
181
182 err = efl_net_ip_socket_activate_check(address, AF_UNIX, SOCK_STREAM, &listening);
183 if (err) return err;
184
185 err = efl_net_server_fd_socket_activate(efl_super(o, MY_CLASS), address);
186 if (err) return err;
187
188 fd = efl_loop_fd_get(o);
189
190 if (!listening)
191 {
192 if (listen(fd, 0) != 0)
193 {
194 err = efl_net_socket_error_get();
195 DBG("listen(%d): %s", fd, eina_error_msg_get(err));
196 goto error;
197 }
198 }
199
200 addrlen = sizeof(addr);
201 if (getsockname(fd, (struct sockaddr *)&addr, &addrlen) != 0)
202 {
203 err = efl_net_socket_error_get();
204 ERR("getsockname(%d): %s", fd, eina_error_msg_get(err));
205 goto error;
206 }
207 else if (efl_net_ip_port_fmt(buf, sizeof(buf), (struct sockaddr *)&addr))
208 efl_net_server_address_set(o, buf);
209
210 DBG("fd=%d serving at %s", fd, address);
211 efl_net_server_serving_set(o, EINA_TRUE);
212 return 0;
213
214 error:
215 efl_net_server_fd_family_set(o, AF_UNSPEC);
216 efl_loop_fd_set(o, INVALID_SOCKET);
217 closesocket(fd);
218 return err;
219 }
220#endif
221}
222
223EOLIAN static Eina_Error
166_efl_net_server_unix_efl_net_server_serve(Eo *o, Efl_Net_Server_Unix_Data *pd, const char *address) 224_efl_net_server_unix_efl_net_server_serve(Eo *o, Efl_Net_Server_Unix_Data *pd, const char *address)
167{ 225{
168 EINA_SAFETY_ON_NULL_RETURN_VAL(address, EINVAL); 226 EINA_SAFETY_ON_NULL_RETURN_VAL(address, EINVAL);