When `write` is called on a `StreamTransport`, the current sequence of
operations is:
* copy data to queue
* register for "write" event notification
* return unfinished future to `write` caller
* wait for "write" notification (in `poll`)
* perform one `send`
* wait for notification again if there's more data to write
* complete the future
In this PR, we introduce a fast path for writing:
* If the queue is empty, try to send as much data as possible
* If all data is sent, return completed future without `poll` round
* If there's more data to send than can be sent in one go, add the
rest to queue
* If the queue is not empty, enqueue as above
* When notified that write is possible, keep writing until OS buffer is
full before waiting for event again
The fast path provides significant performance benefits when there are
many small writes, such as when sending gossip to many peers, by
avoiding the poll loop and data copy on each send.
Also fixes an issue where the socket would not be removed from the
writer set if there were pending writes on close.
* Add more accept() call error handlers.
Fix issue when HTTP server silently stops accepting new connections.
Remove unneeded MacOS syscall to disable SIG_PIPE on socket, we already mask this signal in process.
* User `if` instead `case` because constants are actually variables.
* Fix mistypes.
* Do not use case for posix constants.
* Fix Linux compilation error.
* Change Future identifier type from `int` to `uint64`.
* Fix compilation error and tests.
* Add integer overflow test, to avoid confusion with next Nim versions, we expect that unsigned integers do not raise any exceptions if overflow happens.
* Switch from `uint64` to `uint` type.
* Add `uint` overflow tests.
Fix async streams issue with replacing state.
Add `closing` states to HTTP's server connection, request and bodyrw.
Fix Http server cancellation leaks.
* Initial commit.
* Some refactoring.
* Allow boundstream to accept uint64.
Fix httpserver and asyncstream tests to follow new uint64 requirement.
* send() and getBodyBytes() implementations.
* Add closeWait for response and request.
Refactor finish/close flow.
* Changes in state machine
Add first test.
* Missing test file.
* Fixed tests
Add http leaking trackers and tests.
* Some fixes in multipart.
Fix automatic Content-Length header for requests with body.
Fix getBodyBytes() assertions.
Merging tests to main suite.
* Post rebase fixes.
* Fix tests big message generation.
* Fix response state management and leaks for getBodyXXX() procedures.
* Add redirection support to client and server.
Add fetch(url) procedure with redirection support.
Add tests for redirection.
* Restore functionality of zero-sized bounded reader/writer streams.
Adding tests for it.
* run build_nim.sh unconditionally
Co-authored-by: Ștefan Talpalaru <stefantalpalaru@yahoo.com>