Skip to content
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

[core] WSASend overlapped #974

Conversation

maxsharabayko
Copy link
Collaborator

Added check of the WSASend result, as reported in #973.
Given that ::send(...) wan not observed to fail on Linux, adding a common ::select(...) call for both Windows and Linux might decrease the performance.
This PR uses Windows OverlappedIO API to wait for WSASend to suceed.
50 ms waiting time was chosen empiricaly. 10 ms produce more failures on sending.

@maxsharabayko maxsharabayko added Type: Bug Indicates an unexpected problem or unintended behavior [core] Area: Changes in SRT library core labels Nov 25, 2019
@maxsharabayko maxsharabayko added this to the v1.4.1 milestone Nov 25, 2019
// Wait for 20 ms
int rc = WSAWaitForMultipleEvents(1, &m_SendOverlapped.hEvent, TRUE, 50, TRUE);

if (rc == WSA_WAIT_FAILED) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Convention.

m_SendOverlapped.hEvent = WSACreateEvent();
if (m_SendOverlapped.hEvent == NULL) {
LOGC(mglog.Error, log << CONID() << "IPE: WSACreateEvent failed with error: " << NET_ERROR);
throw CUDTException(MJ_SETUP, MN_NONE, NET_ERROR);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the minor code should be MN_NORES, as the new CChannel occurs only once in updateMux, which is called directly from bind and connect calls. Note that the documentation would have to be updated.

@maxsharabayko maxsharabayko force-pushed the hotfix/wsasend-overlapped branch from 6147294 to 7492746 Compare November 6, 2020 14:55
@maxsharabayko
Copy link
Collaborator Author

Rebased on the latest master ☝️

@mbakholdina mbakholdina modified the milestones: v1.5.1, Backlog May 26, 2021
@maxsharabayko
Copy link
Collaborator Author

A common mistake is to reuse an OVERLAPPED structure before the previous asynchronous operation has been completed. You should use a separate structure for each request. You should also create an event object for each thread that processes data. If you store the event handles in an array, you could easily wait for all events to be signaled using the WaitForMultipleObjects function.

https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-overlapped?redirectedfrom=MSDN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Type: Bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants