On Sun, Sep 30, 2018 at 6:41 PM, Dan Kortschak
<dan.kortsc...@adelaide.edu.au> wrote:
>
> I have been translating some C socket networking code (not my main area
> of expertise) and there is something that I don't see a way to do with
> net.TCPConn.
>
> The original code sets a revc timeout using
>
> ```
> setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
> ```
>
> Short of messing around with the fd and using syscall.SetsockoptTimeval
> (or unix.SetsockoptTimeval) which seems like overkill, is there a
> sensible way to do this or is it omitted because it is not a useful
> thing to do?

As you know, Go's net package uses deadlines rather than timeouts.  We
made this choice because timeouts are inherently ambiguous when
reading more than 1 byte from a TCP connection: does the timeout refer
to reading all the requested data, or does it refer to reading a
single byte, or does it refer to the amount of time between each byte
that arrives?  And in the modern era this has to be considered in the
context of slowloris attacks.  Rather than try to sort out what people
might want, we just use a deadline, which is always clear.

The best approach for your case is going to be to figure out what the
code you are porting actually wants.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to