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

Added ::select to Windows sockets. #510

Merged
merged 1 commit into from
Dec 7, 2018

Conversation

maxsharabayko
Copy link
Collaborator

This fixes the high CPU load issue on Windows with non-blocking sockets (after PR #483).
Fixed type casting warnings in channel.cpp.

This fixes the high CPU load issue on Windows with non-blocking sockets (after PR Haivision#483).
Fixed type casting warnings in channel.cpp.
@@ -162,10 +162,10 @@ void CChannel::open(const sockaddr* addr)
if (0 != ::getaddrinfo(NULL, "0", &hints, &res))
throw CUDTException(MJ_SETUP, MN_NORES, NET_ERROR);

if (0 != ::bind(m_iSocket, res->ai_addr, res->ai_addrlen))
if (0 != ::bind(m_iSocket, res->ai_addr, (int) res->ai_addrlen))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here socklen_t, too... probably.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The last argument of the ::bind has type int. I think casting to socklen_t is not correct, although it is a typedef of int.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Depends. The version that I found in my manpage has the 3rd argument of ::bind set as socklen_t. Might be that there's some difference on Windows, but still the type of this argument should be the same as the type of addrinfo::ai_addrlen. This cast is then at least nonportable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ethouris, you are right on this. socklen_t is better.

@@ -433,7 +433,7 @@ int CChannel::sendto(const sockaddr* addr, CPacket& packet) const

if (packet.isControl())
{
for (int l = 0, n = packet.getLength() / 4; l < n; ++ l)
for (ptrdiff_t l = 0, n = packet.getLength() / 4; l < n; ++ l)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is cast to (ptrdiff_t) not required, while it's required in the loop above?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because in the loop above 'k' is not used to offset a pointer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The "above loop" I meant this in line 393 with 'i' control variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ethouris, do you mean this lines:
n = (ptrdiff_t) packet.getLength() / 4
and
n = packet.getLength() / 4
They should be the same, I missed this. I will remove this casting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants