async-std icon indicating copy to clipboard operation
async-std copied to clipboard

[tracking] net::TcpStream

Open dignifiedquire opened this issue 6 years ago • 6 comments

When working with TcpStream I realized some things are still missing, this is a list for tracking those

  • [x] connect
  • [ ] connect_timeout
  • [x] local_addr
  • [x] nodelay
  • [x] peek
  • [x] peer_addr
  • [ ] read_timeout
  • [x] set_nodelay
  • [ ] ~~set_nonblocking~~ - makes no sense in this context probably
  • [ ] set_read_timeout
  • [x] set_ttl
  • [ ] set_write_timeout
  • [x] shutdown
  • [ ] take_error
  • [ ] ~~try_clone~~ (I remember some discussion, so might not be happening)
  • [x] ttl
  • [ ] write_timeout

dignifiedquire avatar Nov 10 '19 22:11 dignifiedquire

Aren't all methods that end with _timeout hacks due to the synchronous nature of these operations in the stdlib? Do we really need to reproduce them in an asynchronous context?

tomaka avatar Nov 11 '19 13:11 tomaka

@tomaka they could still be useful, as convenience methods. Alternatively adding some documentation on how to achieve the same effect with the new tooling might be a better way to go.

dignifiedquire avatar Nov 11 '19 13:11 dignifiedquire

Regarding the read calls. Let's say that I've asked to read 7 bytes and the other side has sent me 6 bytes ("foobar").

Will the TcpStream::poll_read immediately return me Ready(Ok(6))? Can I be sure that it won't be Pending until a seventh byte arrives?

And would it make sense to repeat the TcpStream::poll_read with a smaller buffer if invoking it with a larger buffer returns Pending?

Similarly, will an await on the TcpStream::read return the 6 bytes soon as they arrive? Or will it keep waiting for the 7th byte?

This is usually under-specified in, say, the POSIX read calls and hence we have to read byte-by-byte from some streams if we want to access the incoming data as soon as it is available from the network interface. Would be nice to avoid these byte-by-byte reads while using async-std.

ArtemGr avatar Apr 16 '20 20:04 ArtemGr

keepalive & set_keepalive is useful when peer suddenly lose its access to network.

SuperHacker-liuan avatar Jan 23 '21 18:01 SuperHacker-liuan

keepalive is an HTTP thing, not a tcp thing?

Fishrock123 avatar Jan 27 '21 20:01 Fishrock123

keepalive is an HTTP thing, not a tcp thing?

FYR, https://tools.ietf.org/html/rfc1122#page-101

SuperHacker-liuan avatar Jan 28 '21 17:01 SuperHacker-liuan