Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Add read timeout to socket. #8

Merged
merged 14 commits into from
Jun 22, 2015
Merged

Add read timeout to socket. #8

merged 14 commits into from
Jun 22, 2015

Conversation

meqif
Copy link
Owner

@meqif meqif commented Jun 21, 2015

Currently, all reads from the underlying UDP are blocking. This raises several problems, such as:

  • no timeout detection on ACKs for sent packets (which need to be resent),
  • no timeout detection on receive (which may signal a dead connection),
  • no timeout detection on close (meaning a socket may hang in the SocketState::FinSent state indefinitely).

This branch pull request creates a sub-crate with a new trait, WithReadTimeout, implemented for UdpSocket, adding the method recv_timeout(&mut [u8], i64) to it. This method is only properly implemented for POSIX targets, with the Windows implementation being a dummy which ignores the timeout.

@meqif
Copy link
Owner Author

meqif commented Jun 21, 2015

I added a Windows implementation which compiles fine but seems to not be timing out at all.

@meqif meqif mentioned this pull request Jun 21, 2015
@meqif
Copy link
Owner Author

meqif commented Jun 21, 2015

In any case, it seems like we'll have proper methods soon-ish: rust-lang/rust#25818.

@dirvine
Copy link

dirvine commented Jun 21, 2015

Ah nice :-)

@meqif
Copy link
Owner Author

meqif commented Jun 22, 2015

I re-read the manual page for select and noticed I should have done a more extensive check on the return value. Previously, I considered only -1 as indication of an error. However, 0 is also an error:

The select function returns the total number of socket handles that are ready and contained in the fd_set structures, zero if the time limit expired, or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR, WSAGetLastError can be used to retrieve a specific error code.

Now that is fixed, but select always returns 0.

@meqif
Copy link
Owner Author

meqif commented Jun 22, 2015

It seems to be working correctly now. :)

@meqif meqif force-pushed the read-timeout branch 2 times, most recently from ee736f6 to cdd26e7 Compare June 22, 2015 15:56
meqif added a commit that referenced this pull request Jun 22, 2015
Add read timeout to socket.
@meqif meqif merged commit 92dbbf8 into master Jun 22, 2015
@meqif meqif deleted the read-timeout branch June 22, 2015 15:56
vinipsmaker added a commit to vinipsmaker/rust-utp that referenced this pull request Dec 28, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants