1

I am building a multithreaded async HTTP server on top of mio.

How should I handle events on client TcpStream connections?

  • For is_readable it's pretty straightforward: I read the request and write the response.
  • For other kinds I am not sure. Should I shutdown() the stream if I get is_error or is_hup? What about is_none()?
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
ElefEnt
  • 2,027
  • 1
  • 16
  • 20
  • 2
    Have you seen [this series by Herman J. Radtke](http://hermanradtke.com/2015/07/12/my-basic-understanding-of-mio-and-async-io.html)? It contains useful information on error-handling in `mio`. – ljedrz Oct 09 '16 at 10:10
  • Thanks, that read was interesting. Unfortunately he doesn't talk about error handling much :) – ElefEnt Oct 11 '16 at 18:35

1 Answers1

1

All things that you mention have very precise meaning and map directly to POSIX/BSD Socket API. It's up to you to decide.

is_hup on Read mean the other side hanged-up it's sending side. Meaning it won't send you anything again. However it might have kept the reading open, and you might still want to send some data to it.

shutdown closes Reading/Writing/Both https://doc.rust-lang.org/std/net/enum.Shutdown.html , so it's up to you what and when you want to do.

TcpStream internally holds FileDesc and that will close the fd when you drop it, so if you don't shutdown manually everything will be closed anyway, as soon as you remove given TcpStream from usage. https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/fd.rs#L217

dpc.pw
  • 3,462
  • 1
  • 19
  • 24