-
Notifications
You must be signed in to change notification settings - Fork 866
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
Conversation
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)) |
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.
Here socklen_t
, too... probably.
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.
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
.
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.
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.
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.
@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) |
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.
Why is cast to (ptrdiff_t)
not required, while it's required in the loop above?
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.
Because in the loop above 'k' is not used to offset a pointer.
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.
The "above loop" I meant this in line 393 with 'i' control variable.
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.
@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.
This fixes the high CPU load issue on Windows with non-blocking sockets (after PR #483).
Fixed type casting warnings in channel.cpp.