<p>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"?</p>
<p>Thanks!</p>
<hr/>**评论:**<br/><br/>jerf: <pre><p>It means "Any Read/Write call that is either still outstanding after this time, or made after this time, will fail with a timeout."</p>
<p>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.</p></pre>JakeTheDev: <pre><p>That makes sense. </p>
<p>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?</p>
<p>I'm assuming it'd fail in the middle.</p></pre>nhooyr: <pre><p>Fail in the middle.</p></pre>JakeTheDev: <pre><p>Solid. Thanks</p></pre>jerf: <pre><p>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.</p>
<p>(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 <em>bandwidth</em> 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.)</p></pre>JakeTheDev: <pre><p>I think i'm going to incorporate <a href="https://github.com/hashicorp/yamux" rel="nofollow">https://github.com/hashicorp/yamux</a> so that I have multiplexing and then use the ConnectionWriteTimeout property of yamux.Session. </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传