Does the SetDeadline() method on the net.Conn interface control "this whole transfer needs to finish by X" or "there needs to at least be activity by X"?
Thanks!
评论:
jerf:
JakeTheDev:It means "Any Read/Write call that is either still outstanding after this time, or made after this time, will fail with a timeout."
The intent is that if you want to keep advancing it, you can, so while your first quote is technically true if you make no further calls, it isn't necessarily the intent of the call.
nhooyr:That makes sense.
But just for the sake of being 100% clear: Suppose i'm writing a 30GB file to a socket directly via io.copy. If that copy is supposed to take 30 minutes and i've already begun the copy, if the deadline is set for 10 minutes from now, would the io.copy fail in the middle or would new io.copy calls fail?
I'm assuming it'd fail in the middle.
JakeTheDev:Fail in the middle.
jerf:Solid. Thanks
JakeTheDev:Someone out there on the Great Githubs must have this already written, but there must be somebody who has wrappers for io.Reader & io.Writer that take a connection and automatically refresh the deadline based on various criteria.
(I would say that there's a temptation to make it so that when one byte is sent you reset the deadline, but you really want to enforce a minimum bandwidth as well. It's almost always better to just fail a transfer than let it carry on at an average 56 bytes per second for minutes at a time. Might want to use that as an evaluation technique.)
I think i'm going to incorporate https://github.com/hashicorp/yamux so that I have multiplexing and then use the ConnectionWriteTimeout property of yamux.Session.