Commit graph

344 commits

Author SHA1 Message Date
Benjamin Schaaf 1afc5ca1c0 Fix waiterCount not including waiting processes 2019-02-21 22:13:05 +11:00
Radu Racariu 07b09e8692
fix @safe 2019-02-12 19:55:32 +02:00
Radu Racariu 6286c7980d
[PosixEventDriverEvents] Use Linux definitions from druntime
This doesn't duplicate the definitions form `core.sys.linux.sys.eventfd` and will pickup any platform specifics for better portability.
Fixes https://github.com/vibe-d/eventcore/issues/102
2019-02-12 19:47:37 +02:00
Radu Racariu cb06ecfbcf
don't try to set the SO_REUSEPORT flag
On Linux this option was always set, regardless if the `StreamListenOptions` specifies it.

On some systems setting that option will result in a failure.
2019-02-11 15:42:42 +02:00
Benjamin Schaaf 7ef5c6686e Fix more Windows compiler errors 2019-01-16 10:23:25 +11:00
Benjamin Schaaf dd915e74b1 Fix Windows compiler errors 2019-01-16 10:09:49 +11:00
Benjamin Schaaf 6108a64973 Fix OSX compiler errors 2019-01-15 21:32:36 +11:00
Benjamin Schaaf 7d091ed504 Add APIs for working with Subprocesses and Pipes with an implementation for Posix 2019-01-15 19:58:01 +11:00
The Dlang Bot 36f43690c6
Merge pull request #98 from vibe-d/file_truncation
Add EventDriverFiles.truncate.
merged-on-behalf-of: Sönke Ludwig <s-ludwig@users.noreply.github.com>
2018-12-28 10:27:38 +01:00
Sönke Ludwig 8205258ee9 Define handles as properly named structs.
Greatly enhances the readability of compiler error messages, as well as sometimes considerably reducing the size of symbol bloat.
2018-12-28 00:43:11 +01:00
Sönke Ludwig 3e81cefcda Add EventDriverFiles.truncate. 2018-12-28 00:34:30 +01:00
Hiroki Noda 3b6b2ab900 Use monotonic clock for timeout
The system clock can be updated manually by the sys-admin or
automatically by NTP, so use monotonic clock instead.
2018-12-23 21:37:12 +09:00
Sönke Ludwig 968084f074 Remove the default dependency to libanl. Fixes #78.
The dependency wasn't used at all, but is now optionally used through the epoll-gaia configuration.
2018-11-11 13:07:48 +01:00
Sönke Ludwig 4ae402223c Fix compilation of the getaddrinfo_a based DNS resolver. 2018-11-11 13:06:56 +01:00
Martin Nowak 619f266a4b
typo 2018-11-06 00:54:23 +01:00
Sönke Ludwig b33f710420 Keep timers with active waits referenced.
Avoids calling the wait callback with reference count zero. In case of a non-pending timer, the wait will be canceled if the wait reference is the last one to avoid keeping starved timers.
2018-10-27 15:45:55 +02:00
Sönke Ludwig dbb8267540 Introduce TimerCallback2.
This allows getting notified also if the timer has been stopped, so that it is guaranteed to be called, except if cancelWait is called.

Necessary for fixing vibe-d/vibe-core#86
2018-10-27 14:11:11 +02:00
Sönke Ludwig 16749d0a58 Use stderr instead of stdout for debug messages.
Avoids polluting the regular application output.
2018-10-26 20:40:22 +02:00
Sönke Ludwig e2e8bf30aa Change shutdown behavior to allow graceful handle leaks.
This avoids crashing in case of any handle references left-over in GC allocated memory that gets finalized after module destructors have already been run.
2018-10-26 20:40:22 +02:00
Sönke Ludwig c553df66e1 Fix freeing of the loop in PosixEventDriver 2018-10-24 21:06:31 +02:00
Sönke Ludwig 4d8d08b27d Fix destruction code in ChoppedVector. 2018-10-24 21:05:45 +02:00
Sönke Ludwig 406367b6c6 Fix epoll compile error on older frontends. 2018-10-24 12:08:38 +02:00
Sönke Ludwig 6e839de7e2 Refactor PollEventDriverWatchers.
- Better encapsulates the mutex protection inside PollingThread
- Uses mallocT/freeT to allocate snapshot nodes
2018-10-24 11:38:14 +02:00
Sönke Ludwig 0b73eda8d5 Deprecate the non-nogc userData overload.
This allows more of the implementation to become nogc.
2018-10-24 11:38:14 +02:00
Sönke Ludwig 73abd867b4 Initialize the driver instance lazily. 2018-10-24 11:38:14 +02:00
Sönke Ludwig 284d4f43c3 Make the WinAPI driver initialization nogc. 2018-10-24 11:38:14 +02:00
Sönke Ludwig e7e4a0f5f5 Make the Posix driver initialization nogc. 2018-10-24 11:38:14 +02:00
Sönke Ludwig a4eaafce9a Avoid GC allocation in StaticTaskPool. 2018-10-24 11:38:13 +02:00
Sönke Ludwig d66f257179 Avoid GC allocations for LoopTimeoutTimerDriver.m_firedTimers. 2018-10-24 11:38:13 +02:00
Sönke Ludwig 4a605640bc Make ConsumableQueue nogc. 2018-10-24 11:38:13 +02:00
Sönke Ludwig 90a60f7981 Add nogc typed alloc/free functions and make assert_nogc actually nogc. 2018-10-24 11:38:13 +02:00
Sönke Ludwig 4e3edf5292 Fix ThreadedFileEventDriver event cancellation when not waiting. 2018-10-02 10:16:26 +02:00
Sönke Ludwig 8495d7d91c Fix UCS-2 to UTF-8 conversion in the Windows watchers implementation. 2018-10-01 22:00:26 +02:00
Sönke Ludwig 87fb595aee Clear WSA buffers to make sure to detect erroneous accesses. 2018-10-01 22:00:22 +02:00
Sönke Ludwig 491e100ef5
Merge pull request #83 from vibe-d/s-ludwig-patch-1
Add Solaris definition for O_CLOEXEC. Fixes #82.
2018-08-29 23:16:47 +02:00
Sönke Ludwig c404cc2e5b
Merge pull request #76 from Boris-Barboris/keepalive_params
fix Keepalive on Linux, expose keepalive options, TCP_USER_TIMEOUT for linux.
2018-08-29 23:16:23 +02:00
Sönke Ludwig 0c62764216
Add Solaris definition for O_CLOEXEC. Fixes #82. 2018-08-16 15:19:12 +02:00
Boris-Barboris ed9fdcd467 ease asserting, constants wrapped for future robustness 2018-06-06 11:45:36 +00:00
Sönke Ludwig 5d317ca9e7 Remove special case for zero-wait processing off events.
This ensures that all kinds of events are processed, including timers and I/O events.
2018-06-05 11:35:57 +02:00
Sönke Ludwig abdbc91c4b
Merge pull request #72 from kubo39/res_init
Call __res_init on linux when getaddrinfo failed, fix #40
2018-05-13 09:45:12 +02:00
The Dlang Bot ca56b31566
Merge pull request #71 from kubo39/somaxconn
Get the listen backlog size from net.core.somaxconn on Linux
merged-on-behalf-of: Sönke Ludwig <s-ludwig@users.noreply.github.com>
2018-05-13 09:44:42 +02:00
Sönke Ludwig 48b214dd09
Fix initialization behavior when being loaded as a shared library.
When loading a shared library where both, the host and the library, use eventcore, the static constructors/destructors will be called multiple times.
2018-05-04 17:45:10 +02:00
Boris-Barboris a2d96f1831 fix setKeepAliveParams on Windows 2018-04-02 18:06:00 +03:00
Boris-Barboris 322438697c TCP_USER_TIMEOUT 2018-04-02 14:02:09 +00:00
Boris-Barboris cdb141ba4a add setKeepAliveParams method 2018-04-02 11:11:28 +00:00
Sönke Ludwig 242432c416 Fix two possible causes for range violations in the WinAPI handle map. 2018-03-30 16:57:45 +02:00
Sönke Ludwig 811ae63698 Fix indentation. 2018-03-30 16:56:42 +02:00
Hiroki Noda e68f1425a9 format 2018-03-22 05:16:36 +09:00
Hiroki Noda d3708c5e66 Fix: leak fd 2018-03-22 05:14:10 +09:00
Hiroki Noda 041d55e584 Get the listen backlog size from net.core.somaxconn on linux 2018-03-22 05:12:37 +09:00
Sönke Ludwig 51527e77f8 Actually close files in the WinAPI driver. 2018-03-20 21:03:43 +01:00
Sönke Ludwig 3cb0891c58 Create the DNS helper event lazily.
Reduces resource usage on threads that don't perform DNS queries.
2018-03-18 01:32:09 +01:00
Sönke Ludwig b09d15d503 Fix dangling handles resulting from actively closing a file. 2018-03-17 17:11:03 +01:00
Sönke Ludwig 7da41301af Tighten the file descriptor slot checks.
Gives the chance to detect possible dangling file descriptors earlier.
2018-03-17 13:11:44 +01:00
Sönke Ludwig 16e2d9587d Implement EventDriverCore.runInOwnerThread. 2018-03-16 16:11:46 +01:00
Sönke Ludwig 7bfbb64899 Add userData!T properties for all descriptor based primitives. 2018-03-16 13:39:03 +01:00
Sönke Ludwig 68b8f44957
Merge pull request #63 from vibe-d/fix_connect_socket_callback
Call the callback on connectStream socket creation failure.
2018-03-14 22:19:14 +01:00
Sönke Ludwig 6262c48db3
Merge pull request #65 from vibe-d/fix_eventfd_leak
Fix leaked eventfd in PosixEventDriverCore.
2018-03-14 22:19:00 +01:00
Sönke Ludwig b6b32f4a49 Fix leaked eventfd in PosixEventDriverCore.
The leak occurred once per thread, which showed up in conjunction with DNS lookups in particular, as a thread is currently created for each lookup.
2018-03-14 21:59:42 +01:00
Sönke Ludwig 4192d31716 Create the event object in ThreadedFileEventDriver lazily.
Avoids creating event objects for every worker thread, even if never used.
2018-03-14 21:39:54 +01:00
Sönke Ludwig 02de8341aa Call the callback on connectStream socket creation failure.
The callback must *always* be called at some point, because the generic async->sync logic in vibe-core otherwise has no way to know whether to expect a callback or not.
2018-03-14 20:43:40 +01:00
Sönke Ludwig 53bb8eeead Fix cleanup code for directory watchers in the WinAPI driver.
- Fixes an assertion triggered by accessing a file field in releaseRef

- Fixed a potential leak of file system watcher handles when calling releaseRef from inside the supplied callback - this was the reason why the fixed assertion error wasn't triggered by the test code
2018-03-14 16:39:57 +01:00
Sönke Ludwig 3d7cf5744c
Merge pull request #61 from vibe-d/remove_obsolete_events
Fix issues in the WinAPI driver
2018-03-12 00:00:10 +01:00
Sönke Ludwig a681fc988b
Merge pull request #60 from vibe-d/single_file_taskpool
Use a single thread pool for all threaded file driver threads.
2018-03-11 23:36:34 +01:00
Sönke Ludwig f094b3934b Make sure that no obsolete I/O events get processed.
Removes overlapped I/O events when a handle gets closed prematurely (before all events have been processed) to avoid potential range violation errors as a consequence.
2018-03-11 20:32:32 +01:00
Sönke Ludwig 26907c7489 Fix set up of OVERLAPPED struct for files. 2018-03-11 20:31:44 +01:00
Sönke Ludwig 3090bc2c7c Implement filterPending for ConsumableQueue. 2018-03-11 20:31:44 +01:00
Sönke Ludwig f5f64ee476 Use a single thread pool for all threaded file driver threads.
This avoids multiplying the number of threads by 5 for each thread that performs file I/O.
2018-03-11 14:46:55 +01:00
Sönke Ludwig df78af96bb Use a custom nogc_assert in cleanup code.
Unfortunately the built-in assert GC allocates an exception, which means that if called directly or indirectly form a finalizer, the assertion will not become visible and instead an InvalidMemoryOperationError is thrown.

This implements a custom nogc_assert() function that directly prints the assertion message and uses abort() to end the process.
2018-03-11 13:56:10 +01:00
Sönke Ludwig 9dc8b796e5 Get rid of OVERLAPPED_FILE.
The hEvent member is currently unused for files. Using it for the file handle makes the OVERLAPPED_CORE struct sufficient.
2018-03-11 00:27:14 +01:00
Sönke Ludwig 0e1d74cc41 Call Windows IO callbacks outside of completion routines.
Calling WinSock functions from inside of a completion routine results in undefined behavior, because the completion routine may be triggered within another WinSock function that enters an alertable wait state. For this reason, none of the callbacks that are triggered by overlapped I/O may be invoked directly from a completion routine.

To solve this, a ConsumableQueue is filled with all completion events that occur and is processed after each MsgWaitForMultipleObjectsEx call.
2018-03-10 22:59:21 +01:00
Sönke Ludwig 0b02c84b2b Set ConnectionState.connected when accepting a connection. Fixes #54. 2018-03-07 11:00:03 +01:00
Sönke Ludwig 008163e913 Fix setTCPNoDelay/setKeepAlive and add assertions.
Assertions make sure that socket query functions are not called with an invalid handle (resulting in strange out-of-memory errors).
2018-03-07 10:52:01 +01:00
Sönke Ludwig 43ef41d4fa Fix deprecation warning on DMD 2.079.0. 2018-03-06 20:09:03 +01:00
Sönke Ludwig 3d2a2656bb Robustness fix for WinAPIEventDriverWatchers.
Under certain (rare) circumstances, the receive buffer contains data from a file instead of the expected FILE_NOTIFY_INFORMATION structure. No signs of handle or buffer reuse could be found, so the cause for this remains unclear. Until the cause can be narrowed down, this keeps the issue visible while avoiding to crash the application.
2018-03-03 20:04:51 +01:00
Sönke Ludwig fbd6927377 Improve robustness of file I/O callbacks for the WinAPI driver.
Explicitly gets the read/write slot from the handle map from within the callback instead of dereferencing the pointer assigned when starting the operation. This makes sure that no dangling reference is accessed. Instead, if the slot got reused before the callback is invoked (which is a bug), an assertion will be triggered if the slot now has a different handle type.
2018-03-03 19:56:54 +01:00
Sönke Ludwig 3a52e0f362 Fix cast from HANDLE to descriptor in the WinAPI driver.
Avoids truncation to 32-bit for 64-bit builds. Also improves robustness of the directory watcher shutdown procedure.
2018-03-03 19:56:54 +01:00
Sönke Ludwig e8e8f85271 Add DatagramSocket.broadcast property. Fixes #47. 2018-02-22 02:08:09 +01:00
Sönke Ludwig b2b072dd80 Reduce the number of ChoppedVector index operations. 2018-02-22 01:58:49 +01:00
Sönke Ludwig 30f614a7ff
Merge pull request #50 from vibe-d/fix_watcher_cancellation
Fix watcher cancellation
2018-02-22 01:56:13 +01:00
Sönke Ludwig 0e7091d085 Fix invalid watcher slot access in the win32 driver.
The underlying file handle and the associated slot could previously be destroyed before the I/O callback had been finally called. Now the callback itself is responsible to destroying the handle.
2018-02-22 01:14:31 +01:00
Sönke Ludwig c8f95f324b Enable canceling win32 file I/O.
The CancelIOEx call was disabled just due to historical reasons.
2018-02-22 01:12:13 +01:00
Diederik de Groot 41312a589e
Remove static compiler __VERSION check. "import core.sys.dragonflybsd.netinet.in_" will work, when compiler support is there.
[See](https://github.com/vibe-d/vibe.d/pull/2028#discussion_r161077152)
2018-01-11 10:40:37 +01:00
Diederik de Groot e062e44f1c
Fix compilation on DragonFlyBSD 2018-01-09 15:23:23 +01:00
Sönke Ludwig 6e2938297b Set O_CLOEXEC on the remaining FDs that are created by eventcore. 2017-12-19 22:10:14 +01:00
Hiroki Noda 214382dcb5 Set EFD_CLOEXEC
Add missing one.
2017-12-19 13:38:47 +09:00
Sönke Ludwig 8528b4ec00 Fix accidental resetting of O_NONBLOCK and set O_CLOEXEC on outgoing sockets, too. 2017-12-18 14:07:38 +01:00
Hiroki Noda 1179163150 Add O_CLOEXEC for some posix platform 2017-12-18 09:44:08 +01:00
Hiroki Noda b252c97012 Set close-on-exec flag to prevent fd leakage for command execution 2017-12-18 09:44:08 +01:00
Hiroki Noda 83317bb2bf Call __res_init on linux when getaddrinfo failed, fix #40 2017-12-17 11:55:20 +09:00
Sönke Ludwig c3fa500c3b
Merge pull request #39 from kubo39/epoll-cloexec
Set EPOLL_CLOEXEC to prevent fd leakage for command executation
2017-12-16 18:58:40 +01:00
Sönke Ludwig c45f7dc35e Properly increment the waiter count during async TCP connect. 2017-12-16 17:55:13 +01:00
Hiroki Noda 277743914b Set EPOLL_CLOEXEC to prevent fd leakage for command executation
This is for the same reason #38
2017-12-16 10:16:43 +09:00
Sönke Ludwig 9ca1a4c3a6 Fix inotify based directory watcher for recursive directory adds.
Newly added folders were not scanned recursively, which would result in sub folders that already exist or are added concurrently to not be watched.
2017-12-02 02:54:13 +01:00
Sönke Ludwig 29aee9ee52 Defer driver dispose in main thread to shared static ~this.
Allows dependent code to still access the driver from within their shared static ~this. vibe-core notably falls into this category.
2017-11-25 16:59:53 +01:00
Sönke Ludwig 2d4ccf454d Properly increment waiter count for WinAPI file I/O operations. 2017-11-25 16:47:29 +01:00
Sönke Ludwig 07d2bafcac Fix threading issues in the generic Posix event implementation.
Uses socketpair non-Linux systems and two separate UDP sockets on Windows for the cross-thread communication.
2017-11-25 11:42:19 +01:00
Sönke Ludwig a5d4cf875c Add adoptDatagramSocketInternal. 2017-11-25 00:26:44 +01:00
Sönke Ludwig c8eb30f6f0 Remove polling threads from map. 2017-11-25 00:26:20 +01:00
Sönke Ludwig 31286e4580 Ensure the socket handle passed to callbacks is always valid on Posix. 2017-11-23 23:12:35 +01:00