Commit Graph

141 Commits

Author SHA1 Message Date
Vincent Torri f7c560c311 replace hton and ntoh family functions with ones defined in eina
Summary: This fixes especially the execution of edje_cc on Windows

Test Plan: execution of edje_cc

Reviewers: cedric, raster

Subscribers: #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D7834
2019-02-01 14:25:35 +00:00
Mike Blumenkrantz 0e40fad446 ecore_con: make dns resolver thread stop blocking when canceled
Summary:
if the user or system attempts to cancel this thread then it should
stop blocking and exit in order to avoid potentially exiting after
efl has expected ecore-con to stop being active

@fix
fix T7041
Depends on D6354

Reviewers: ManMower, devilhorns

Reviewed By: ManMower

Subscribers: cedric, #committers

Tags: #efl

Maniphest Tasks: T7041

Differential Revision: https://phab.enlightenment.org/D6355
2018-06-25 15:14:31 -04:00
Cedric BAIL 67cbc0d8af ecore_con: make the ecore_con log domain available during ecore_shutdown. 2018-05-01 10:39:01 -07:00
Jean-Philippe Andre c0c5e72408 ecore_con: Properly shutdown and unregister log domain
I believe the comment saying we should not unregister the log domain is
invalid as we try to flush the pending ecore events.
2017-12-18 19:54:31 +09:00
Pawel Aksiutowicz 03152b8958 ecore_con: quiet 2 "clobbered" warnings in ecore_con
Reviewers: stanluk, lukasz.stanislawski

Subscribers: cedric, jpeg

Differential Revision: https://phab.enlightenment.org/D5514

Signed-off-by: Cedric Bail <cedric@osg.samsung.com>
2017-11-23 15:38:52 -08:00
Vincent Torri 0cdd501246 EFL For WIN32: Replace HAVE_EVIL define with _WIN32 2017-09-22 05:06:10 -05:00
Cedric BAIL 662f7d3310 ecore_con: use new API eina_file_close_on_exec. 2017-04-18 16:56:01 -07:00
Gustavo Sverzut Barbieri 9486225744 ecore_con: remove warnings if FD_CLOEXEC is undefined.
currently it's being defined in evil_fcntl.h, but the actual
implementation of fcntl() in evil_fcntl.c is causing problems with
sockets. So one possibility is to remove the ifdef, another is to
change the implementation.
2017-03-29 12:44:19 -03:00
Vincent Torri 02b6ee3ed8 Ecore_Con: Fix compilation on Solaris
FIONREAD is defined in sys/filio.h
2017-03-26 23:50:02 +09:00
Carsten Haitzler eab798c753 ecore_con/efl_net - dedicated threads for network i/o not from the pool
so ecore_con/efl_net were using the standard ecore_thread thread pool
for doing things like dns lookups (that can take multiple minutes
until timeouts) and actual http transactions. similarly they can block
thread workers for long periods or indefinitely thus basically
blocking the whole eocre_thread pool and stopping others from sharing
it. the best solution we have right now is to bypass the thread pool
queue and have dedicated threads for these actions. what we should
have is a dedicated thread pool with each thread taking on N
connections (via select etc.) and the ability to create and destroy
thread pools for specific tasks so you can separate the work out from
other work.  but that is basically a redesign of our thread pool infra
so let's do the quick solution here until that day comes.

this partially addresses D4640

a dedicated thread per image load though is going to be a lot nastier...
2017-02-03 14:57:49 +09:00
Carsten Haitzler bd2f189d4c ecore_con - move libproxy to a slave binary with stdin/out msging
so here's the ugly problem. libproxy. yes. we've discussed memory
usage (e.g. it may have to execute javascript and pull in lots of deps
etc.) but we dlopene'd on the fly. ok... but this didn't solve another
issue i hit:

libproxy was causing enlightenment to abort(). some internal bit of
libproxy was raising a c++ exception. this wasn't caught. this causes
an abort(). takes down your entire desktop. FANTASTIC. this is bad. i
wouldnt' expect a library we depend on to be THIS anti-social but
libproxy seemingly is. it SHOULd catch its error sand just propagate
back to us so we can handle gracefully.

there reall is no way around this - isolate libproxy. it's even worse
that libproxy can load arbitrary modules that come from anywhere sho
who knows what issues this can cause. isolation is the best solution i
can think of.

so this makes an elf+net_proxy_helper we spawn the first time we need
a proxy lookup. we re-use that binary again and again until it exits
(it should exit after 10 seconds of being idle with no requests coming
in/pending). it'll respawn again later if needed. this involves now
the efl net threads having to marshall back to mainloop to do the
spawn and to write to the proxy process (reading is done by async exe
data events and the data is passed down a thread queue to the waitng
efl net thread). if the exe dies with pending requests unanswered then
it's respawned again and the req's are re-sent to it... just in case.
it has a limit on how often it'll respawn quickly.

this seems to work in my limited testing. this ALSO now isolates
memory usage of libproxy to another slave process AND this process
will die taking its memory with it once it's been idle for long
enough. that;s also another good solution to keeping libproxy impact
at bay.
2017-01-09 15:29:33 +09:00
Gustavo Sverzut Barbieri 482437ee14 ecore_con/ecore_ipc: keep log domain alive after shutdown.
These legacy API had the nasty behavior of keeping handles alive until
the pending events were dispatched, this could happen after the module
itself was shutdown, resulting in log to unregistered domains.

Then do not unregister the domain -- eina_shutdown will avoid leaks
anyway.
2016-12-19 13:03:33 -02:00
Gustavo Sverzut Barbieri 7de5146a3b efl_net: fix CID 1367489 due copy & paste.
we're looking at "x" since it's the return of getaddrinfo(), not "r"
which is used for something else.
2016-12-19 10:37:21 -02:00
Cedric BAIL 32da71d65d ecore_con: reduce amount of warning related to clobbered variable. 2016-12-15 10:31:56 -08:00
Gustavo Sverzut Barbieri 96eccc2753 efl_net: move error COULDNT_RESOLVE_HOST to broader scope.
This error is shared by Dialer and Server, will also be used by IP
resolution.
2016-12-12 02:30:33 -02:00
Gustavo Sverzut Barbieri f4306d654d ecore_con: Ecore_Con_Server now on top of Efl_Net!
This is a major work and unfortunately couldn't be split into smaller
pieces as old code was highly coupled.

Ecore_Con_Server is now a wrapper around Efl_Net_Dialer_Simple
(ecore_con_server_connect()) and Efl_Net_Server_Simple
(ecore_con_server_add()), doing all that the original version did with
some fixes so ecore_con_ssl_server_upgrade() and
ecore_con_ssl_client_upgrade() are more usable -- see the examples and
-t/--type=tcp+ssl.

I tried to be bug-compatible, with code annotations where things
doesn't make sense. This was based on ecore_con_suite tests and some
manual experimenting with the examples, these can be helpful if you
find regressions (report/assign to me).
2016-12-10 08:44:06 -02:00
Gustavo Sverzut Barbieri 5939f0d9c2 efl_net_dialer: emit 'resolved' even if connection failed.
If we resolved the address but couldn't connect, use
efl_net_socket_address_remote_set() and emit
EFL_NET_DIALER_EVENT_RESOLVED.
2016-12-09 13:47:04 -02:00
Gustavo Sverzut Barbieri afdbe897a0 efl_net: optimize serving of IP addresses.
If we can parse the IP using inet_pton() and the port, there is no
reason to call getaddrinfo() in a thread.

This is required since ecore_con_suite (for ecore_con-over-efl_net) will
assume the server is running as soon as it's created.
2016-12-09 13:47:04 -02:00
Gustavo Sverzut Barbieri d6584673ea ecore_con (legacy) fix close()->closesocket() and valid fd check.
use the windows version and it will also work on UNIX due macros.
2016-11-18 14:21:21 -02:00
Gustavo Sverzut Barbieri c0f84d190f efl_net: fix missing SOCKET_FMT. 2016-11-18 14:21:21 -02:00
Gustavo Sverzut Barbieri 371a3332ef efl_net: remove getsockopt()/setsockopt() warning on windows.
windows is nasty and defines the value to be set or retrieved as
'char *', which triggers a warning when we use another kind of
pointer.

Partially addresses D4357.
2016-11-18 12:53:32 -02:00
Gustavo Sverzut Barbieri 8d24622f57 efl_net: remove send()/recv() warning on windows.
windows is nasty and defines the payload to be sent or received as
'char *', which triggers a warning when we use another kind of
pointer.

Partially addresses D4357.
2016-11-18 12:53:32 -02:00
Gustavo Sverzut Barbieri c3ddc8f09e efl_net: do not use sockaddr_un on Windows.
struct sockaddr_un doesn't exist on windows, so do not use it.

Partially addresses D4357.
2016-11-18 12:53:32 -02:00
Gustavo Sverzut Barbieri 5818dc71da 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.
2016-11-18 12:53:32 -02:00
Vincent Torri c0d8f1cc37 ecore_con: correctly include sys/ioctl.h
I had to make distclean for this patch to work.

Differential Revision: https://phab.enlightenment.org/D4402
2016-11-16 19:50:24 +09:00
Gustavo Sverzut Barbieri c2630c829f efl_net_server support systemd socket activation.
It includes extensive verifications to avoid mistakes and usage of
incorrect sockets.
2016-11-01 16:37:04 -02:00
Gustavo Sverzut Barbieri f4198f022a efl_net_socket_ssl: initial SSL wrapper.
This is the first step towards SSL connections on top of sockets, with
an example on how to upgrade a dialer and a server client using TCP.
2016-10-31 19:39:33 -02:00
Jean Guyomarc'h d27b1df4e8 ecore_con: fix structure declaration
Clang raised a massive amount of warnings due to the struct sockaddr_un
not being declared before using it. So, include the header that declares
this structure first.
2016-10-30 18:40:54 +01:00
Gustavo Sverzut Barbieri 48fb9e72df UNIX socket doesn't exist on Windows.
thanks to vtorri & Kuri to spot that one.
2016-10-27 09:01:56 -02:00
Gustavo Sverzut Barbieri 651ff13616 addded efl_net_{socket,dialer,server}_unix
This introduces AF_UNIX server and dialer, these are not available on
Windows as in that platform we'll create a custom class for native
'local' communication.

In the future we can add a wrapper class Efl.Net.Local that will use
the class for each platform, but won't expose its details.

For instance, if we ever expose 'credentials' (which I didn't because
they are not portable), then it doesn't make sense to try to match
that on Windows. The 'Efl.Net.Local' would just stick to the basics:
Reader, Writer and Closer APIs.
2016-10-26 19:01:03 -02:00
Gustavo Sverzut Barbieri 9a62932d07 use more standard IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
The IPV6_ADD_MEMBERSHIP and IPV6_DROP_MEMBERSHIP are deprecated alias,
use the correct defines so it compiles everywhere.

Fixes T4764

Thanks netstar!
2016-10-25 19:32:07 -02:00
Gustavo Sverzut Barbieri cd53f9bad2 efl_net_*_udp: make UDP usable, including multicast.
This was a huge work, but now UDP is usable as seen in the examples.

Instead of relying on 'connect()', just do 'sendto()' and 'recvfrom()'
as they are universal. Multicast address can only be connected in
IPv4, IPv6 wasn't working and I'm not sure the IPv4 is portable to
other platforms.

Dialer will auto-join multicast groups is the dialed address is
one. Multicast properties such as time to live (hops) and loopback can
be configured. When joining multicast groups, the local
address/interface can be configured by 'IP@IFACE' format, with
'@IFACE' being optional.

Dialers will now auto-bind, so it can receive data as dialers are
expected to be bi-directional. One can manually specify the binding
address if there is such need.

Since datagrams must be read in their full size, otherwise the
remaining bits are dropped, expose next_datagram_size_query() in both
Efl.Net.Socket.Udp and Efl.Net.Server.Udp.Client.

To finalize UDP for real we need to introduce an 'Efl_Net_Ip_Address'
structure to serve as both IPv4 and IPv6 and expose 'sendto()' and
'recvfrom()'. These will come later as this commit is already too big.
2016-10-25 10:11:48 -02:00
Gustavo Sverzut Barbieri cddbce8900 efl_net_*: improve WIN32.
Thanks to vtorri for poiting out about close() is not the correct
socket function, we should use closesocket() instead.

Also defined SOCKET to int on Linux so we can use the same 'type' and
avoid lots of ifdef in our code. On Windows it's unsigned, thus would
cause some warnings about incorrect signed comparison.
2016-10-22 21:49:01 -02:00
Gustavo Sverzut Barbieri e6a78bd02a efl_net: play better with WIN32.
Defined INVALID_SOCKET=-1 and SOCKET_ERROR=-1 on non-Windows platforms
so we can keep the same construct 'function() == error' and it should
work on POSIX and windows.

I cannot test these on Windows, but the situation should be improved
with this commit.
2016-10-22 13:15:16 -02:00
Gustavo Sverzut Barbieri 9ab8f6636a getaddrinfo(): when providing hints, make sure we use addrconfig/v4mapped.
if no hints were specified, getaddrinfo() will assume ai_flags as
AI_ADDRCONFIG | AI_V4MAPPED, which only reports useful results based
on what system supports. For instance AI_ADDRCONFIG will only return
IPv4 if IPv4 address exists, likewise IPv6 will only be returned if
IPv6 address is configured, avoiding these to be tried and error for
most local networks where such address could not be used. AI_V4MAPPED
will map IPv4 address over IPv6 if no IPv4 was found.
2016-10-22 09:46:43 -02:00
Gustavo Sverzut Barbieri 094c9091b4 efl_net_server_tcp: use async getaddrinfo() to resolve server name.
this allows nicer usage such as 'localhost:http' as the address, which
will resolve to [::1]:80 (if IPv6 is enabled) or 127.0.0.1:80 if only
IPv4 exists.
2016-10-21 00:16:37 -02:00
Daniel Kolesa 5db3f14f85 eolian gen: use EWAPI for all generated variables 2016-10-20 16:44:20 +02:00
Gustavo Sverzut Barbieri 69e330e781 efl_net_dialer_udp: enable SO_BROADCAST before sending to 255.255.255.255
Like other toolkits, let's enable this automatically for users before
connecting to 255.255.255.255 IPv4 (IPADDR_BROADCAST), otherwise most
systems will just fail to connect and send packets.
2016-10-18 20:00:52 -02:00
Bruno Dilly a3fba57b26 ecore_con,elput: fix warnings
Summary:
elput: fix warning for unused write result
         ecore_con: fix warning for unused asprintf result

Reviewers: iscaro, devilhorns, cedric

Reviewed By: cedric

Subscribers: cedric, seoz, jpeg

Differential Revision: https://phab.enlightenment.org/D4308

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
2016-09-20 16:13:28 -07:00
Gustavo Sverzut Barbieri f0f9c5d24a libproxy: dlopen() and make it runtime optional. 2016-09-20 15:00:48 -03:00
Gustavo Sverzut Barbieri 0d478c301f efl_net_dialer_tcp: use libproxy settings.
libproxy allows various means to configure a proxy, will load from
gnome and kde configuration settings, envvars, macos and even windows
registry.

curl still doesn't use it, but we can make that later.
2016-09-19 10:01:51 -03:00
Gustavo Sverzut Barbieri a975bfe1e6 efl_net_dialer_tcp: add SOCKS proxy support.
SOCKS is implemented in its own thread using synchronous/blocking
primitives, which simplifies the code a lot -- as well as simulate the
usage of Ecore_Thread as our users will likely do.

Since SOCKSv4a and SOCKSv5 allow name resolution, the whole
getaddrinfo() is done in the same thread, when needed, instead of a
separate thread to do that, which should also save some resources.

Instead of the legacy ECORE_CON_SOCKS_V4 and ECORE_CON_SOCKS_V5, now
we use socks_proxy, all_proxy and no_proxy. This matches our other
dialers http/websocket (which will use http_proxy, all_proxy and
no_proxy). If desired it's easy to add back support for those
variables, but I think we should just deprecate them. (The legacy code
will keep unchanged, thus direct users of ecore_con_server will still
use those -- just the previous users of ecore_con_server will be
converted to use the new API).
2016-09-19 01:18:14 -03:00
Gustavo Sverzut Barbieri 960e1a1d16 eina/ecore: allow threads to be canceled, use in ecore_con.
As discussed in the mailing list, many people will use worker threads
to execute blocking syscalls and mandating ecore_thread_check() for
voluntary preemption reduces the ecore_thread usefulness a lot.

A clear example is ecore_con usage of connect() and getaddrinfo() in
threads. If the connect timeout expires, the thread will be cancelled,
but it was blocked on syscalls and they will hang around for long
time. If the application exits, ecore will print an error saying it
can SEGV.

Then enable access to pthread_setcancelstate(PTHREAD_CANCEL_ENABLE)
via eina_thread_cancellable_set(EINA_TRUE), to pthread_cancel() via
eina_thread_cancel(), to pthread_cleanup_push()/pthread_cleanup_pop()
via EINA_THREAD_CLEANUP_PUSH()/EINA_THREAD_CLEANUP_POP() and so on.

Ecore threads will enforce non-cancellable threads on its own code,
but the user may decide to enable that and allow cancellation, that's
not an issue since ecore_thread now plays well and use cleanup
functions.

Ecore con connect/resolve make use of that and enable cancellable
state, efl_net_dialer_tcp benefits a lot from that.

A good comparison of the benefit is to run:

   ./src/examples/ecore/efl_io_copier_example tcp://google.com:1234 :stdout:

before and after. It will timeout after 30s and with this patch the
thread is gone, no ecore error is printed about possible SEGV.
2016-09-14 01:47:23 -03:00
Gustavo Sverzut Barbieri cb8695e9d6 efl_net_dialer_tcp: make asynchronous resolve and connect.
both resolve (getaddrinfo()) and connect() are now done in
Ecore_Thread, avoid to block the main loop.

My plan is to always use the threaded connect() using a blocking
socket, only set it to non-blocking after the socket is returned to
the main thread and before it's accessible to the user. It will make
the connect behavior more uniform.

Some errors were moved from HTTP to Dialer as they are more generic.
2016-09-09 20:14:01 -03:00
Tom Hacohen 9c779dca90 Rename efl_self to efl_added
It has been discussed on the ML (thread: "[RFC] rename efl_self") and
IRC, and has been decided we should rename it to this in order to avoid
confusion with the already established meaning of self which is very
similar to what we were using it for, but didn't have complete overlap.

Kudos to Marcel Hollerbach for initiating the discussion and
fighting for it until he convinced a significant mass. :)

This commit breaks API, and depending on compiler potentially ABI.

@feature
2016-09-05 16:59:56 +01:00
Vitor Sousa f02ff462e7 efl callbacks: update some events calls to no longer trigger legacy callbacks 2016-08-30 13:59:59 -03:00
Vitor Sousa 8356b16a49 Efl Object: remove legacy callback calls from event_callback_call
Efl.Object.event_callback_call no longer calls legacy smart callbacks;
calling only event callbacks registered with the given event description
pointer.

Create the method Efl.Object.event_callback_legacy_call to inherit the old
behavior from Efl.Object.event_callback_call, calling both Efl.Object events
and legacy smart callbacks.

Update all other files accordingly in order to still supply legacy
callbacks while they are necessary.
2016-08-26 15:45:07 -03:00
Gustavo Sverzut Barbieri e3ee477140 efl_net: better handling for SOCK_CLOEXEC.
On systems where SOCK_CLOEXEC is supported, give it to socket() and if
accept4() is supported, then use it as well.

Otherwise revert to fcntl().
2016-08-24 12:34:59 -03:00
Gustavo Sverzut Barbieri e7df1a7483 efl.net: socket, server and dialer for TCP.
Efl.Net.Server defines how to accept new connections, doing the
bind(), listen() and accept() for protocols such as TCP.

Efl.Net.Dialer defines to to reach a server.

Both are based on Efl.Net.Socket as communication interface that is
based on Efl.Io.Reader, Efl.Io.Writer and Efl.Io.Closer, thus being
usable with code such as Efl.Io.Copier.

The Server will emit an event "client,add" with the established
Socket, which is a child and can be closed by both the server or the
user.

The Dialer extends the Socket and allows for creating one given an
address, that will be resolved and connected.

TCP is the initial implementation so we an validate the
interfaces. UDP, Unix-Local and SSL will come later as derivate
classes.

The examples are documented and should cover the basic principles:

 - efl_io_copier_example can accept "tcp://IP:PORT" and will work as a
   "netcat", can send data from socket, file or stdin to a socket,
   file, stdout or stderr.

 - efl_net_server_example listens for connections and can either reply
   "Hello World!" and take some data or work as an echo-server,
   looping back all received data to the user.

More complex interactions that require a "chat" between client and
server will be covered with new classes later, such as a queue that
empties itself once data is read.
2016-08-22 18:25:14 -03:00
Tom Hacohen e65aae994e Eo: Finish the renaming of Eo to the EFL.
This renames all the rest of the API to the EFL namespace except for
Eo_Event that will follow soon.

Obviously breaks both API and ABI.
2016-08-15 15:07:42 +01:00