net.Conn - SetDeadline() confusion

polaris · · 2787 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Does the SetDeadline() method on the net.Conn interface control &#34;this whole transfer needs to finish by X&#34; or &#34;there needs to at least be activity by X&#34;?</p> <p>Thanks!</p> <hr/>**评论:**<br/><br/>jerf: <pre><p>It means &#34;Any Read/Write call that is either still outstanding after this time, or made after this time, will fail with a timeout.&#34;</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&#39;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&#39;m writing a 30GB file to a socket directly via io.copy. If that copy is supposed to take 30 minutes and i&#39;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&#39;m assuming it&#39;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 &amp; io.Writer that take a connection and automatically refresh the deadline based on various criteria.</p> <p>(I would say that there&#39;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&#39;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&#39;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

2787 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传