Repository navigation
core: send without IO-thread round trip when the socket accepts the data #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev/ethernet_queue_size
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,34 @@ void AsioGenericRawByteStream::AsyncWriteSome(ConstBufferSequence bufferSequence | |
| } | ||
|
|
||
|
|
||
| auto AsioGenericRawByteStream::TryWriteSome(ConstBufferSequence bufferSequence) -> size_t | ||
| { | ||
| #if defined(__linux__) | ||
| std::unique_lock<decltype(_mutex)> lock{_mutex}; | ||
|
|
||
| if (_shutdownPending || _writing || bufferSequence.size() != 1) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| // Bypasses asio's socket object on purpose: a plain non-blocking send() on the descriptor does not | ||
| // touch asio's per-socket state, so it cannot race with the asynchronous read pending on the IO | ||
| // thread, and it completes without posting a completion handler (i.e. without waking the IO thread). | ||
| const auto& buffer = bufferSequence.data()[0]; | ||
| const auto result = ::send(_socket.native_handle(), buffer.GetData(), buffer.GetSize(), MSG_DONTWAIT | MSG_NOSIGNAL); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. asio already sets non_blocking on the socket, no? MSG_DONTWAIT doesnt add anything, except making this non-portable (i think FreeBSD and macos has that, too). but the MSG_NOSIGNAL is definitely not portable (SO_NOSIGPIPE in bsd) ... we should use the asio builtins instead of raw syscalls, and flip the #ifdef to ignore windows: |
||
| if (result < 0) | ||
| { | ||
| // EAGAIN as well as real errors: let the asynchronous path wait for writability or report the error. | ||
| return 0; | ||
| } | ||
| return static_cast<size_t>(result); | ||
| #else | ||
| SILKIT_UNUSED_ARG(bufferSequence); | ||
| return 0; | ||
| #endif | ||
| } | ||
|
|
||
|
|
||
| void AsioGenericRawByteStream::Shutdown() | ||
| { | ||
| SILKIT_TRACE_METHOD_(_logger, "()"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A fundamental design in the SIL Kit it that the sending, receiving and invoking handlers happens on the IO Thread. Main purpose is that
@KyllianAubry can you say how this is affected by this change.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So part of my assumption (and also the code comment) was misleading, this does not alter the threading behavior of sending because at least through the public API
SendMsgstill goes through VAsioConnection.hpp'sExecuteOnIoThread...