* Add automatic constructors for TCP and UDP transports.
* Add port number argument.
Add some documentation comments.
Fix tests.
* Make datagram test use request/response scheme.
* Add helper.
* Fix issue with non-zero port setups.
Add test.
* Fix tests to probe ports.
* Attempt to fix MacOS issue.
* Add Opt[IpAddress].
Make IPv4 mapping to IPv6 space automatic.
* Add tests.
* Add stream capabilities.
* Fix Linux issues.
* Make getTransportFlags() available for all OSes.
* Fix one more compilation issue.
* Workaround weird compiler bug.
* Fix forgotten typed version of constructor.
* Make single source for addresses calculation.
* Add one more check into tests.
* Fix flags not being set in transport constructor.
* Fix post-rebase issues with flags not being set.
* Address review comments.
In `stream.readLoop`, a finished `Future` was left in `transp.reader`
if there was an error in `resumeRead`. Set it to `nil` as well.
Co-authored-by: Jacek Sieka <jacek@status.im>
We can check at compile-time that at least one parameter is passed
* clean up closure environment explicitly in some callbacks to release
memory earlier
* Fix `or` should not create future with OwnCancelSchedule flag set.
* Fix `CancelledError` missing from raises list when both futures has empty raises list.
* Fix macros tests.
```nim
import chronos
proc f(): Future[void] {.async: (raises: []).} =
discard
discard f() or f() or f()
```
```
/Users/etan/Documents/Repos/nimbus-eth2/vendor/nim-chronos/chronos/internal/raisesfutures.nim(145, 44) union
/Users/etan/Documents/Repos/nimbus-eth2/vendor/nimbus-build-system/vendor/Nim/lib/core/macros.nim(185, 28) []
/Users/etan/Documents/Repos/nimbus-eth2/test.nim(6, 13) template/generic instantiation of `or` from here
/Users/etan/Documents/Repos/nimbus-eth2/vendor/nim-chronos/chronos/internal/asyncfutures.nim(1668, 39) template/generic instantiation of `union` from here
/Users/etan/Documents/Repos/nimbus-eth2/vendor/nimbus-build-system/vendor/Nim/lib/core/macros.nim(185, 28) Error: illegal conversion from '-1' to '[0..9223372036854775807]'
```
Fix by checking for `void` before trying to access `raises`
* Add more specific accept() exceptions raised.
Add some refactoring to HTTP server code.
* Refactor acceptLoop.
* Print GC statistics in every failing test.
* Try to disable failing tests.
Features:
* Exception effects / raises for async procedures helping you write more
efficient leak-free code
* Cross-thread notification mechanism for suitable building channels,
queues and other multithreaded primitives
* Async process I/O
* IPv6 dual stack support
* HTTP middleware support alloing multiple services to share a single
http server
* A new [documentation web
site](https://status-im.github.io/nim-chronos/) covering the basics,
with several simple examples for getting started
* Implicit returns, support for `results.?` and other conveniences
* Rate limiter
* Revamped cancellation support with more control over the cancellation
process
* Efficiency improvements with `lent` and `sink`
See the [porting](https://status-im.github.io/nim-chronos/porting.html)
guides for porting code from earlier chronos releases (as well as
asyncdispatch)
Feature flags allow consumers of chronos to target versions with and
without certain features via compile-time selection. The first feature
flag added is for raise tracking support.
* simplify `closeWait` implementations
* remove redundant cancellation callbacks
* use `noCancel` to avoid forgetting the right future flags
* add a few missing raises trackers
* enforce `OwnCancelSchedule` on manually created futures that don't raise `CancelledError`
* ensure cancellations don't reach internal futures
Because the callback types were used explicitly in some consumers of
chronos, the change of type introduces a backwards incompatibility
preventing a smooth transition to v4 for code that doesn't uses
`raises`.
This PR restores backwards compatibility at the expense of introducing a
new type with a potentially ugly name - that said, there is already
precedence for using numbered names to provide new error handling
strategy in chronos.
* Fixes.
* Make httpcommon no-raises.
* Make httpbodyrw no-raises.
* Make multipart no-raises.
* Make httpdebug no-raises.
* Make httpagent no-raises.
* Make httpclient no-raises.
* Make httpserver/shttpserver no-raises.
* fix prepend/remove when E is noraises
---------
Co-authored-by: Jacek Sieka <jacek@status.im>
This avoids copies here and there throughout the pipeline - ie
`copyString` and friends can often be avoided when moving things into
and out of futures
Annoyingly, one has to sprinkle the codebase liberally with `sink` and
`move` for the pipeline to work well - sink stuff _generally_ works
better in orc/arc
Looking at nim 1.6/refc, sink + local variable + move generates the best
code:
msg directly:
```nim
T1_ = (*colonenv_).msg1; (*colonenv_).msg1 = copyStringRC1(msg);
```
local copy without move:
```nim
T60_ = (*colonenv_).localCopy1; (*colonenv_).localCopy1 =
copyStringRC1(msg);
```
local copy with move:
```nim
asgnRef((void**) (&(*colonenv_).localCopy1), msg);
```
Annoyingly, sink is also broken for refc+literals as it tries to
changes the refcount of the literal as part of the move (which shouldn't
be happening, but here we are), so we have to use a hack to find
literals and avoid moving them.
* Fix transports addresses functions should not return so many exceptions.
* Add raising `Defect` functions to AsyncQueue.
* Add raises/asyncraises into async streams.
* Remove `Safe` primitives.
Make AsyncStreamError to be ancestor of AsyncError.
Make AsyncStreamReader/Writer loops requirement to not raise any exceptions
* Remove `par` fields.
* Remove `par` fields from TLSStream.
* Attempt to lower memory usage.
Dedicated exceptions for `read` failures reduce the risk of mixing up
"user" exceptions with those of Future itself. The risk still exists, if
the user allows a chronos exception to bubble up explicitly.
Because `await` structurally guarantees that the Future is not `pending`
at the time of `read`, it does not raise this new exception.
* introduce `FuturePendingError` and `FutureCompletedError` when
`read`:ing a future of uncertain state
* fix `waitFor` / `read` to return `lent` values
* simplify code generation for `void`-returning async procs
* document `Raising` type helper
With these fixes, `transports`/`asyncsync` correctly propagate and document their raises information - generally, most transport functions (send etc) raise `TransportError` and `CancelledError` - `closeWait` is special in that it generally doesn't fail.
This PR introduces the syntax `Future[void].Raises([types])` to create the `InternalRaisesFuture` type with the correct encoding for the types - this allows it to be used in user code while retaining the possibility to change the internal representation down the line.
* introduce raising constraints on stream callbacks - these constraints now give a warning when called with a callback that can raise exceptions (raising callbacks would crash
* fix fail and its tests, which wasn't always given a good generic match
* work around nim bugs related to macro expansion of generic types
* make sure transports raise only `TransportError`-derived exceptions (and `CancelledError`)
* introduce user guide based on `mdbook`
* set up structure for adding simple `chronos` usage examples
* move most readme content to book
* ci deploys book and api guide automatically
* remove most of existing engine docs (obsolete)
* Fix waitFor() should not exit earlier last callback will be scheduled.
* Tune tests to use less memory.
* Fix `testutils`. There is no more last poll() needed.
* Update chronos/internal/asyncfutures.nim
---------
Co-authored-by: Jacek Sieka <jacek@status.im>