Commit graph

324 commits

Author SHA1 Message Date
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
Sönke Ludwig 4d00376873 Ensure proper reference count for created Posix events. 2017-11-23 23:12:35 +01:00
Sönke Ludwig 19879712e6 Fix shutdown procedure and rename event order for the polling watcher.
Renames should always be reported as removed->added instead of added->removed.
2017-11-23 23:11:16 +01:00
Sönke Ludwig 1d4fbc4fa2 Fixup poll driver. 2017-11-23 23:11:16 +01:00
Sönke Ludwig c8fd340240 Fix destruction of PosixEventDriverEvents event.
The reference count was one too high and the waiter count was not properly decremented when an event got destroyed.
2017-11-23 23:11:16 +01:00
Sönke Ludwig aa9a08f571 Explicitly dispose the event driver on thread shutdown.
Handle multiple calls to dispose() gracefully, because external code may already make an explicit call to dispose().
2017-11-23 23:11:16 +01:00
Sönke Ludwig 16e95b03e8 Fix WinAPI watcher to be consistent. 2017-11-22 17:14:31 +01:00
Sönke Ludwig a9ae496fb4 Avoid "." path in InotifyEventDriverWatchers.
The vibe-core tests broke because a "/./" path segment slipped into the resulting paths.
2017-11-22 17:07:49 +01:00
Sönke Ludwig 5246593432 Fix handling recursive inotify based directory watchers. 2017-11-21 10:42:21 +01:00
Sönke Ludwig 0ec498207d Gag directory modified events in win32. 2017-11-21 10:42:21 +01:00
Sönke Ludwig 99088e1202 Implement a generic polling based directory watcher.
This is used on platforms that don't have a specialized watcher implementation.
2017-11-21 10:42:21 +01:00
Sönke Ludwig 815db0727c Change all invalid handle values to ~0 and improve FileChange.
FileChange now has the full path of a file split into the base path (as specified when creating the watcher), the sub directory, and the file name. This allows to work with less dynamic memory allocations internally.
2017-11-21 10:42:14 +01:00
Sönke Ludwig 3352423414 Fix decrementing the waiter count when destroying a WinAPI event with active waiters. 2017-11-21 00:09:41 +01:00
Sönke Ludwig fdeef38ef4 Fix waiter count tracking for WinAPI directory watchers and avoid empty callbacks. 2017-11-20 15:59:35 +01:00
Sönke Ludwig 314bd2bb48 Fix WinAPI condition for outOfWaiters event loop exit reason.
Calling processEvents could previously block indefinitely even if there were no waiters left.
2017-11-20 15:59:35 +01:00
Sönke Ludwig 7cc6bec14a Fix a possible range error when a win32 file watcher gets destroyed while waiting.
This is not a final solution, but avoids the fatal error and replaces it with, at worst, bogus change events being reported.
2017-11-17 18:35:48 +01:00
Sönke Ludwig 0897b1bc9e Implement WinAPIEventDriverSockets.cancelConnectStream. 2017-11-12 14:41:08 +01:00
Sönke Ludwig 569b75e050 More detailed documentation for cancelConnectStream(). 2017-11-12 14:34:58 +01:00
Boris-Barboris 36b0413d32 remove cabblack invocation 2017-11-11 15:44:13 +00:00
Boris-Barboris 0cac9d56e0 cancelConnectStream for Posix 2017-11-11 01:14:54 +00:00
Sönke Ludwig c4550f0e59
Fix ThreadedFileEventDriver read/write issues.
I/O errors were being reported as IOStatus.ok instead of IOStatus.error, and the I/O operation finalization protocol had a potential race-condition when storing the number of bytes processed.
2017-10-30 22:54:14 +01:00
Sönke Ludwig 8799b7b01e Add assertion. 2017-09-26 15:49:13 +02:00
Sönke Ludwig 60407b783b Fix re-enqueuing of periodic timers. Fixes #25.
Periodic timers were first re-enqueued and then removed, effectively causing them to stay at their old position, cutting off the tail of the timer queue.
2017-09-26 15:49:13 +02:00
Sönke Ludwig a52d064c9e Add multicast constant definitions for Solaris. 2017-09-26 15:45:51 +02:00
Sönke Ludwig fc6c18faad Add missing default parameter. 2017-09-23 15:00:46 +02:00
Sönke Ludwig 28e1a83057 Add an interface_index argument to joinMulticastGroup. 2017-09-11 13:35:34 +02:00
Sönke Ludwig 06c6e0a4ca
Add basic UDP multicast support.
This also adds a new setOption method to handle boolean socket options in a generic way.
2017-09-03 18:14:57 +02:00
Sönke Ludwig 07baa0f612
Improve performance of accepting incoming connections.
- Removes the accept() loop, as that doesn't measurably improve performance in practice. This also gives each connection the possibility to perform initial I/O before more concurrency is generated by accepting the next connection.

- Uses SOCK_NONBLOCK in conjunction with socket() and accept4() to save one additional syscall per connection.
2017-09-02 15:40:07 +02:00
Sönke Ludwig fc5df2f949
Use level-triggered events for listening stream sockets.
The limit of 20 accepted connections per event invocation can otherwise lead to no more connections being accepted when more that 20 connections are available at a time. This is an adaptation of @Boris-Barboris pull request #21 to restrict the level triggered behavior to listening sockets. See also #20.
2017-09-02 00:12:58 +02:00
Sönke Ludwig eb595ef858 Fix always calling GC.addRange in ChoppedVector if necessary. 2017-08-26 22:33:00 +02:00
Sönke Ludwig 74352a9ac5 Avoid dangling socket slot access in the WinAPI driver.
When the last reference got released while a blocking socket operation was still in progress, the old slot was still accessed from the completion callback, leading to null pointer accesses or other issues.
2017-08-21 21:02:13 +02:00
Sönke Ludwig 44b43e8415
Fix error message. 2017-08-14 15:14:05 +02:00
Sönke Ludwig a63907b9f7
Fix multiple bugs in ThreadedFileEventDriver.
- Errors were reported as "ok"
- The cancel state logic was flawed and could lose cancel requests
- Operations could be removed from the active sets before they actually finished, causing the callback to never get called
2017-08-14 01:58:42 +02:00
Sönke Ludwig dd873ec6cf
Add example to get(Local/Remove)Address and fix some ddoc syntax errors. 2017-08-12 21:25:27 +02:00
Sönke Ludwig 09a67149bc
Use a linked list for the timer queue.
Improves insertion and deletion times for many pending timers considerably.
2017-07-21 21:35:10 +02:00
Sönke Ludwig beef9c2567
Add a doubly linked list implementation. 2017-07-21 21:35:10 +02:00
Sönke Ludwig 1c666a0191
Fix send() return value handling.
A value of 0 doesn't indicate a closed connection as for recv().
2017-07-19 10:42:33 +02:00
Sönke Ludwig 9518ec4dce
Remove log noise for listening TCP sockets. 2017-07-14 12:35:17 +02:00
Sönke Ludwig 077c643e08 Fix 64-bit compile error. 2017-06-27 00:54:32 +02:00
Sönke Ludwig a7e5b49943 Implement basic UDP support for the WinAPI driver.
Note that the IOMode.immediate semantics are not compatible with the current 0-udp.d test and will instead call the callback asynchronously. It appears that non-blocking semantics are generally not possible with overlapped sockets.
2017-06-26 23:37:33 +02:00
Sönke Ludwig a263637bd3 Fix WSASend/WSARecv usage w.r.t. WSABUF parameter.
The documentation states that the buffer must be kept alive during the whole operation, so using a stack allocated buffer is illegal.
2017-06-26 23:31:22 +02:00
Sönke Ludwig ef065762b3 Fix WinAPIEventDriverCore.waiterCount to include pending timers. 2017-06-26 23:28:15 +02:00
Sönke Ludwig ca11fdec82 Implement WinAPI based TCP socket support. 2017-06-24 22:31:16 +02:00
Sönke Ludwig ab796477e2 Move .userData to the socket driver.
Generally each FD type should have its own .userData property in the respective driver. This is important for drivers that don't have a unified file descriptor space and need to store user data in a type specific way.
2017-06-24 22:01:32 +02:00
Sönke Ludwig d99eb1be34
Fix waiter count tracking in the Posix driver. Fixes #8. 2017-06-10 10:27:55 +02:00
Sönke Ludwig abf8587078
Add SmallIntegerSet.empty. 2017-06-10 10:27:20 +02:00
Sönke Ludwig 8e385d8b1d
Fix epoll status event masks. Fixes #10. 2017-06-10 00:06:45 +02:00
Sönke Ludwig 1ff3d00020
Check return value of eventfd for errors. 2017-06-10 00:06:45 +02:00
Sönke Ludwig f4ca542b92
Add assertions in ChunkedVector to detect failed memory allocations. 2017-06-10 00:06:45 +02:00
pinver 435e365c3a idem, avoid to pollute the console as default 2017-04-25 16:32:01 +02:00
pinver 1be26214e6 avoid to pollute the console by default 2017-04-25 16:28:31 +02:00
Sönke Ludwig 872f1b12b9
For direction of getLocalAddress and getRemoteAddress. 2017-03-24 09:04:32 +01:00
Sönke Ludwig 420c361b5f Fix WinAPI sockets stub. 2017-03-11 09:17:38 +01:00
Sönke Ludwig 758256c210
Fix compilation of the libasync driver stub. 2017-03-10 22:56:07 +01:00
Sönke Ludwig 1d330d6330
Extend datagram socket API.
Adds .setTargetAddress() and makes .getXAddress() work for datagram sockets, too.
2017-03-10 22:46:43 +01:00
Sönke Ludwig 2e5b13ee98
Add EventDriverSockets.getRemoteAddress. 2017-03-10 20:25:28 +01:00
Sönke Ludwig a25b49228f Properly count IO completion as an event in WinAPIEventDriverCore.processEvents. 2017-03-09 16:02:42 +01:00
Sönke Ludwig bcc059e6d7 Fix bogus outOfWaiters event loop exit reason for active event waits. 2017-02-22 17:35:26 +01:00
Sönke Ludwig 578065f70a Fix exit conditions in the WinAPI event loop. 2017-02-22 17:34:44 +01:00
Sönke Ludwig f84139ba63 Fix infinite look when stopping timers with multiple others pending. 2017-02-22 17:33:03 +01:00
Sönke Ludwig 49521f2586
Remove debug output. 2017-01-31 10:06:51 +01:00
Sönke Ludwig 4b357c3326
Make sure the socket ref count can reach zero in user code. 2017-01-30 23:11:09 +01:00
Sönke Ludwig 490dc15128
Properly handle the case where a TCP connection gets immediately disconnected.
This can result in both, the write-ready and the disconnect events, to be triggered during the same event loop iteration.
2017-01-30 22:52:13 +01:00
Sönke Ludwig 773e09cd3d
Fix (immediate) detection of remove connection close for EPOLL. 2017-01-30 21:01:31 +01:00
Sönke Ludwig 5a5dcd6376
Remove debug output. 2017-01-30 20:11:40 +01:00
Sönke Ludwig 6851776358
Add EventDriverTimers.isUnique. 2017-01-30 19:54:38 +01:00
Sönke Ludwig 956978cc79
Fix out of order processing issue with the TCP connection callback.
It could happen that the socket FD got reused before the connection callback was cleared. This in turn could result in the new connection callback to get overwritten with null.
2017-01-30 10:54:43 +01:00
Sönke Ludwig 4703f021ec
Fix setting initial state for incoming TCP connections. 2017-01-29 21:00:27 +01:00
Sönke Ludwig 3d81854214
Add StreamListenOptions.
Can be used to set the SO_REUSEPORT option for multi-thread/multi-process incoming TCP connection distribution.
2017-01-27 22:09:05 +01:00
Sönke Ludwig 4e830a408f Split up WinAPI driver into separate files. 2017-01-25 16:14:06 +01:00
Sönke Ludwig 87394165de Only bind outgoing stream sockets explicitly if requested. 2017-01-25 12:57:02 +01:00
Sönke Ludwig ea60f55a8d
Fix another compile error. 2017-01-25 12:35:42 +01:00
Sönke Ludwig b52747247b
Fix Linux compilation. 2017-01-25 12:33:00 +01:00
Sönke Ludwig d1829669ec Split up Posix event driver into separate files. 2017-01-25 00:11:57 +01:00
Sönke Ludwig 0b012e7ec7 Remove duplicate declaration. 2017-01-23 22:31:23 +01:00
Sönke Ludwig d3e8005662 Fix Win64 compilation. 2017-01-23 22:24:27 +01:00
Sönke Ludwig 356a34fad2 Implement simple (synchronous) DNS lookup for the WinAPI driver. 2017-01-23 21:37:35 +01:00
Sönke Ludwig 607bd1df09 Try executing DNS resolve tasks in a new thread to work around macOS hang. 2017-01-23 15:07:47 +01:00
Sönke Ludwig e72b071057 Add debug output for the getaddrinfo based DNS lookup driver. 2017-01-23 12:17:53 +01:00
Sönke Ludwig e55e23368a Fix compile error on macOS. 2017-01-23 11:52:09 +01:00
Sönke Ludwig d6321a2b52
Fix waiter count bookkeeping in PosixEventDriverEvents. 2017-01-23 11:34:14 +01:00
Sönke Ludwig e5078ad399
Fix ConsumableQueue.consume with no entries present. 2017-01-23 11:33:45 +01:00
Sönke Ludwig 0422ee495c
Fix null pointer error. 2017-01-23 11:15:03 +01:00
Sönke Ludwig a8aa505373
Fix Linux build. 2017-01-23 10:38:09 +01:00
Sönke Ludwig b556849af2 Fully fix the Win64 build (test might still fail). 2017-01-23 10:03:36 +01:00
Sönke Ludwig 2c4534d178 Fix Win64 build. 2017-01-23 09:09:30 +01:00
Sönke Ludwig 217a6698cb Fix type conversion error. 2017-01-22 21:55:51 +01:00
Sönke Ludwig 619948c4d5 Another fix attempt for the special read 0 behavior. 2017-01-22 21:29:12 +01:00
Sönke Ludwig 25bab3e37e Make the kqueue event driver work. 2017-01-22 20:54:09 +01:00
Sönke Ludwig c9c6d73f5e Make the kqueue event driver compile on macOS (doesn't work yet). 2017-01-22 18:43:29 +01:00
Sönke Ludwig 1c83076897 Fixup TCP read wait special case. 2017-01-22 12:40:07 +01:00
Sönke Ludwig dd5c88d1ed Fix compilation and event behavior on macOS. 2017-01-22 12:36:27 +01:00
Sönke Ludwig f5b514899a Add basic documentation for the driver interface. 2017-01-22 11:39:01 +01:00
Sönke Ludwig 58c89a7369 Implement proper zero size wait semantics for Posix stream sockets. 2017-01-22 10:47:58 +01:00
Sönke Ludwig ca81d25645 Implement socket adoption and fix wait loops on Windows for the Posix driver. 2017-01-22 10:43:18 +01:00
Sönke Ludwig 28040004cf Another compile fix. 2017-01-22 03:32:38 +01:00
Sönke Ludwig 55ea6c192f DMD 2.073.0-rc1 compile fixes. 2017-01-22 03:26:47 +01:00
Sönke Ludwig 922c9e8e72 Revert "Make the address parameter of send() scoped."
This reverts commit 1385250884.
2017-01-22 03:16:36 +01:00
Sönke Ludwig d6f6fc8357 Posix compile fix. 2017-01-22 03:10:46 +01:00
Sönke Ludwig 1385250884 Make the address parameter of send() scoped. 2017-01-22 03:05:46 +01:00
Sönke Ludwig 17c4fe65a8 Fix the Windows events implementation in the Posix driver. 2017-01-22 03:05:01 +01:00
Sönke Ludwig 924f2087f2 Fix premature event loop exit in case of waiting for events in the Posix driver. 2017-01-22 02:30:00 +01:00
Sönke Ludwig 0e38717669 Add unit test for SmallIntegerSet. 2017-01-22 02:28:40 +01:00
Sönke Ludwig 6b68e934f3 Implement file support for the WinAPI driver. 2017-01-22 02:01:13 +01:00
Sönke Ludwig 2a5252977e Implement events for the WinAPI driver. 2017-01-21 23:19:39 +01:00
Sönke Ludwig f7ec3da756 Implement directory watchers for the WinAPI driver. 2017-01-21 21:10:17 +01:00
Sönke Ludwig 4c7281dd01
Trivial refactor. 2017-01-21 17:27:54 +01:00
Sönke Ludwig 74d9242086
Final compile fix attempt. 2017-01-21 17:27:28 +01:00
Sönke Ludwig 40595fe133 Fix another compilation error. 2017-01-21 17:17:11 +01:00
Sönke Ludwig 0f325a47e4 Fix compilation error on Linux. 2017-01-21 16:40:28 +01:00
Sönke Ludwig 12e59b9c3c Implement basic event processing and timers for the WinAPI driver. 2017-01-21 16:39:48 +01:00
Sönke Ludwig 373cf45b1e Also fix compilation of PosixEventDriverEvents on Windows.
The previous commit actually didn't fully fix the Windows build.
2017-01-21 16:34:06 +01:00
Sönke Ludwig 64f6bb2a14 Make the select based configuration compile on Windows. 2017-01-21 16:19:34 +01:00
Sönke Ludwig a1f0cafeb3
Add IOMode parameter for file IO operations. 2017-01-19 00:24:38 +01:00
Sönke Ludwig 672e1c951d Adjust high level wrapper and test. 2017-01-15 21:59:15 +01:00
Sönke Ludwig 8b8169b868 Add EventDriverSockets.setBroadcast. 2017-01-15 21:42:05 +01:00
Sönke Ludwig 116940a5a7 Add EventDriverSockets.getLocalAddress and make parameters scope where possible. 2017-01-15 20:56:06 +01:00
Sönke Ludwig d8f10972eb Added EventDriverSockets.setKeepAlive. 2017-01-15 17:21:18 +01:00
Sönke Ludwig 2341762992 Fix range violation errors in ConsumableQueue. 2017-01-13 20:30:56 +01:00
Sönke Ludwig aa7b2946f3 Add shared overload of the EventDriver.events property.
This allows accessing the shared "trigger" method from a shared event driver.
2017-01-13 10:20:51 +01:00
Sönke Ludwig a3ca0965cf Fix wrong epoll timeout in case of already expired timers.
This could cause process/task starvation due to an infinite wait timeout.
2016-12-29 22:51:07 +01:00