Commit Graph

25 Commits

Author SHA1 Message Date
Xavi Artigas 679c89d98d Adapt to latest event names 2019-03-09 15:54:38 +01:00
Mike Blumenkrantz fabab68024 merge all files from efl.git/src/examples 2018-08-09 17:39:17 -04:00
Mike Blumenkrantz d9bc92888a examples 2018-08-09 16:21:58 -04:00
Cedric BAIL 73876dcbc9 Revert "efl_add_ref - fis to use efl_add properly with a parent."
This reverts commit 2fb5cc3ad09f6aaf82b5d1131ac5ed22ed848bd4.

Most of this change where wrong as they didn't affect the destruction
of the object. efl_add_ref allow for manual handling of the lifecycle
of the object and make sure it is still alive during destructor. efl_add
will not allow you to access an object after invalidate also efl.parent.get
will always return NULL once the object is invalidated.

Differential Revision: https://phab.enlightenment.org/D6062
2018-05-24 16:02:17 -07:00
Carsten Haitzler 29dda8d2b5 efl_add_ref - fis to use efl_add properly with a parent.
fixes bc18b7e7ad1f8c5d587400b27fabab0865017011 and
168849e8a08966ecc284e28f64126a3a85965965
2018-03-29 13:30:55 +09:00
Cedric BAIL 2ded43d89a efl: use efl_add_ref to create objects which have no parent
Signed-off-by: Mike Blumenkrantz <zmike@osg.samsung.com>
2018-03-20 17:20:56 -07:00
Cedric BAIL a0185cd8fa ecore: remove more use of main loop reference from unified API example. 2018-01-08 13:19:48 -08:00
Carsten Haitzler ddf7587449 efl loop - rename ecore_main_loop_get to efl_main_loop_get
ecore_main_loop_get() is really a new "eo api" but it's using our old
ecore_* namespace, so move to the new efl namespace.
2018-01-02 16:13:54 +09:00
Gustavo Sverzut Barbieri 5136fa380f implement efl_net_{socket,dialer,server}_windows
This is the local socket for windows, analogous to AF_UNIX.

`Efl_Net_Socket_Windows` is the base class doing `ReadFile()` and
`WriteFile()` using overlapped I/O, as well as the close procedure
(`FlushFileBuffers()`, `DisconnectNamedPipe()` and
`CloseHandle()`). These are done on top of an existing HANDLE that is
set by `Efl_Net_Dialer_Windows` (from `CreateFile()`) or
`Efl_Net_Server_Windows` (from `CreateNamedPipe()`).

The overlapped I/O will return immediately, either with operation
completed or `ERROR_IO_PENDING`, which means the kernel will execute
that asynchronously and will later `SetEvent(overlapped.hEvent)` which
is an event we wait on our main loop. That `overlapped` handle must
exist during the call lifetime, thus cannot be bound to `pd`, as we
may call `CancelIo()` but there is no guarantee the memory won't be
touched, in that case we keep the overlapped around, but without an
associated object.

Windows provides no notification "can read without blocking" or
non-blocking calls that returns partial data. The way to go is to use
these overlapped I/O, with an initial `ReadFile()` to an internal
buffer, once that operation finishes, we callback the user to says
there is something to read (`efl_io_reader_can_read_set()`) and wait
until `efl_io_reader_read()` is called to consume the available data,
then `ReadFile()` is called again to read more data to the same
internal buffer.

Likewise, there is no "can write without blocking" or non-blocking
calls that sends only partial data. The way to go is to get user bytes
in `efl_io_writer_write()` and copy them in an internal buffer, then
call `WriteFile()` on that and inform the user nothing else can be
written until that operation completes
(`efl_io_writer_can_write_set()`).

This is cumbersome since we say we "sent" stuff when we actually
didn't, it's still in our internal buffer (`pd->send.bytes`), but
nonetheless the kernel and the other peer may be adding even more
buffers, in this case we need to do a best effort to get it
delivery. A particular case is troublesome: `write() -> close()`, this
may result in `WriteFile()` pending, in this case we wait using
`GetOverlappedResult()`, *this is nasty and may block*, but it's the
only way I see to cope with such common use case.

Other operations, like ongoing `ReadFile()` or `ConnectNamedPipe()`
will be canceled using `CancelIo()`.

Q: Why no I/O Completion Port (IOCP) was used? Why no
   CreateThreadpoolIo()? These perform much better!

A: These will call back from secondary threads, but in EFL we must
   report back to the user in order to process incoming data or get
   more data to send. That is, we serialize everything to the main
   thread, making it impossible to use the benefits of IOCP and
   similar such as CreateThreadpoolIo(). Since we'd need to wakeup the
   main thread anyways, using `OVERLAPPED.hEvent` with
   `ecore_main_win32_handler_add()` does the job as we expect.

Thanks to Vincent Torri (vtorri) for his help getting this code done
with an example on how to do the NamedPipe handling on Windows.
2017-03-29 12:44:19 -03:00
Gustavo Sverzut Barbieri 1d86cbfab4 more eo simplified to use Eina_Slice instead of pointer to.
Working directly with Eina_Slice is easier than a pointer to it,
requires no validation of the pointers and is cheap since it's just
putting together size_t + void*.

However we can't hint the user of 'const(Eina.Slice)' properties as
Eolian is incorrectly generating getters as:

   const Eina_Slice class_property_get(...)

which is makes compilers complain about ignored qualifiers:

   ../src/lib/ecore/efl_io_copier.eo.h:329:7: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]

Leave some TODO so @q66 can fix those.
2016-12-19 15:30:56 -02:00
Gustavo Sverzut Barbieri 8c2013d090 Efl.Io.{Queue,Buffer,Buffered_Stream}: slice_get is now a property.
Previously we couldn't return a slice, instead required the user to
pass a slice and we'd fill it since Eolian couldn't generate fallbacks
for structures.

Since @q66 fixed eolian, we can now return the structure itself as
initially wanted, ditching some TODO from the code.
2016-12-19 15:30:56 -02:00
Gustavo Sverzut Barbieri 128fe49e8e yoda-style inactivity timeout.
s/inactivity_timeout/timeout_inactivity/g so it matches the EFL names
with scope first, like timeout_connect, etc.
2016-12-12 02:30:33 -02:00
Gustavo Sverzut Barbieri 1ee201e078 efl_net_{server,dialer}_ssl: TCP + SSL easy to use.
in the previous commit we're manually upgrading an existing TCP socket
to SSL. It is desired since some protocols need to negotiate, like
STARTTLS and the likes

Now we offer 2 classes that does autostart SSL once the socket is
ready.
2016-11-01 01:31:56 -02:00
Gustavo Sverzut Barbieri 9daddebf09 efl_io_copier_example: add AF_UNIX support. 2016-10-26 19:16:29 -02:00
Gustavo Sverzut Barbieri 8e47bb8e0e efl_io_copier_example: allow udp as input/source.
now that we have a 'bind', let's use the given address as bind and
dial to `0.0.0.0` or `::`. This allows the dialer to receive data at
the given address and make the example useful.
2016-10-26 12:46:09 -02:00
Gustavo Sverzut Barbieri c7fc1dce01 efl_io_copier: add inactivity_timeout.
This is handful to error the copier with ETIMEDOUT if there are no
reads or writes in the given amount of time.

Since copiers are usable to download data or handle network clients,
it's easy to set a timeout and disconnect, let's say UDP clients that
are gone.
2016-10-22 10:52:22 -02:00
Gustavo Sverzut Barbieri b36e2c65f6 efl_net_dialer_udp: "connect" to an UDP server to send and receive data.
Like existing ecore_con code, this does not use SOCKSv5 UDP
proxy. It's kinda cumbersome to add since requires a keep alive TCP
connection to the server, a second UDP channel and framing around the
original UDP frame.

Added UDP_CORK (if present) to match TCP_UDP present in TCP sockets,
this allows one to execute multiple write() calls that will result in
a single datagram, generated when CORK becomes FALSE again.

The efl_io_copier_example.c now accepts this as output. There is no
input UDP as there is no way to notify the server of a connection
(since such thing doesn't exit), usually servers react after a
datagram is received, replying to the source.
2016-10-18 19:04:00 -02:00
Gustavo Sverzut Barbieri 388ec0fb62 efl_io and efl_net examples: fix O_CLOEXEC on windows.
use the efl_io_closer_close_on_exec_set() to use a simple boolean
instead of a flag that may be undefined on some platforms, such as
windows.
2016-09-16 07:42:24 -03:00
Tom Hacohen b00564d698 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
Gustavo Sverzut Barbieri 394b9411ce efl_net_dialer_websocket: EFL now does WebSocket!
The Efl.Net.Dialer.Websocket is just like other Efl.Net.Dialers: you
can dial, you can close, monitor connected/address resolved and so
on. And you can use WebSocket primitives and events such as
text_send(), binary_send(), ping() and close_request() (since
WebSockets use a close process where you should state a close
reason). See efl_net_dialer_websocket_example.c

Even if WebSocket is a message-based protocol (like "packets" from
UDP), you can use efl_net_dialer_websocket_streaming_mode_set() to
tell it to handle text or binary messages as a stream. Then all the
Efl.Io.Reader and Efl.Io.Writer APIs work as expected, see
efl_io_copier_example.c updates.
2016-09-02 00:08:50 -03:00
Tom Hacohen d0bc249ead Efl object: Rename Eo_Event -> Efl_Event.
This is the last step of the Eo renaming efforts.
2016-08-30 13:34:10 +01:00
Gustavo Sverzut Barbieri 06983d8673 efl_io_copier_example: set loop as parent for Efl.Net.Dialer.Tcp
although it was working, the correct way is to set a loop provider as
Efl.Net.Dialer.Tcp object.
2016-08-23 20:17:13 -03:00
Gustavo Sverzut Barbieri fe07b8cdab WIP: efl.net: Introduce Efl.Net.Dialer.Http
This class implements the Efl.Net.Dialer interface using libcurl to
perform HTTP requests. That means it's an Efl.Net.Dialer,
Efl.Net.Socket, Efl.Io.Reader, Efl.Io.Writer and Efl.Io.Closer, thus
being usable with Efl.Io.Copier as demonstrated in the
efl_io_copier_example.c
2016-08-22 18:25:15 -03:00
Gustavo Sverzut Barbieri b0b6757bc5 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
Gustavo Sverzut Barbieri d0f0bd20a0 efl.io: introduce basic interfaces and classes.
These interfaces allows generic operations on objects that can store
or provide data, such as a file or a buffer.

With well defined interfaces and events we can create code such as
Efl.Io.Copier, that will link a source with a destination and
progressively copy data as they appear.
2016-08-22 18:25:14 -03:00