path: root/src/lib/ecore_con/efl_net_dialer_windows.eo
diff options
authorGustavo Sverzut Barbieri <>2017-03-22 04:29:16 -0300
committerGustavo Sverzut Barbieri <>2017-03-29 12:44:19 -0300
commitfa0e2865a1a53cd05298b8368fa9abdb7c83bff8 (patch)
treeec445601f6df26f124851b56dcde2b6a870f2684 /src/lib/ecore_con/efl_net_dialer_windows.eo
parent17444557deab4f1ecb62e0fd03a7090a3a4bcbfd (diff)
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.
Diffstat (limited to 'src/lib/ecore_con/efl_net_dialer_windows.eo')
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/ecore_con/efl_net_dialer_windows.eo b/src/lib/ecore_con/efl_net_dialer_windows.eo
new file mode 100644
index 0000000000..50a38b89b5
--- /dev/null
+++ b/src/lib/ecore_con/efl_net_dialer_windows.eo
@@ -0,0 +1,20 @@
1class Efl.Net.Dialer.Windows (Efl.Net.Socket.Windows, Efl.Net.Dialer) {
2 [[Connects to a Windows NamedPipe server.
4 The dial address will have "\\\\.\\pipe\\" prepended as required by
5 Windows CreateNamedPipe().
7 \@note Proxies are meaningless, thus are not implemented.
9 @since 1.19
10 ]]
12 implements {
13 Efl.Object.destructor;
14 Efl.Net.Dialer.dial; [[address parameter will have "\\\\.\\pipe\\" prepended]]
15 Efl.Net.Dialer.address_dial { get; set; }
16 Efl.Net.Dialer.connected { get; set; }
17 Efl.Net.Dialer.timeout_dial { get; set; }
18 Efl.Io.Closer.close;
19 }