]> git.lizzy.rs Git - rust.git/commit
std: Add support for an accept() timeout
authorAlex Crichton <alex@alexcrichton.com>
Tue, 22 Apr 2014 03:30:07 +0000 (20:30 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 24 Apr 2014 02:07:31 +0000 (19:07 -0700)
commite5d3e5180f667f8850cdd96af60fc5511746b1bd
treeb960b71ae8310007eabf6e2565173f7081cab267
parentbb580f1a56138bd5a96ccc95c0f61caab72cf975
std: Add support for an accept() timeout

This adds experimental support for timeouts when accepting sockets through
`TcpAcceptor::accept`. This does not add a separate `accept_timeout` function,
but rather it adds a `set_timeout` function instead. This second function is
intended to be used as a hard deadline after which all accepts will never block
and fail immediately.

This idea was derived from Go's SetDeadline() methods. We do not currently have
a robust time abstraction in the standard library, so I opted to have the
argument be a relative time in millseconds into the future. I believe a more
appropriate argument type is an absolute time, but this concept does not exist
yet (this is also why the function is marked #[experimental]).

The native support is built on select(), similarly to connect_timeout(), and the
green support is based on channel select and a timer.

cc #13523
src/libnative/io/c_win32.rs
src/libnative/io/net.rs
src/libnative/io/timer_win32.rs
src/librustuv/net.rs
src/librustuv/timer.rs
src/libstd/io/net/tcp.rs
src/libstd/rt/rtio.rs