TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Each socket should have two file descriptors

120 点作者 riobard将近 12 年前

12 条评论

pierrebai将近 12 年前
A small compendium of errors...<p>For starter, a | b |c doesn&#x27;t create two file descriptors. It creates four, two per pipe. Then there is a problem with the central argument. For regular files, and in fact all method of creating file descriptor, <i>except</i> pipes, opening in RW mode creates a single descriptor. The reason for pipe() special behaior is two pronged:<p>1. The raison d&#x27;être of pipes is for sequential communication between producer&#x2F;consumer processes. There is no other reason for their design. As such, it made sense to break the convention of a single FD.<p>2. At the time of their design, the 70s, memory footprint was a crucial part of any design. Thus, sharing buffers between the producer and consumer FD was primordial, and the best way to make it happen is to create the FD at the same time.<p>The other problem is that the pipe analogy for TCP is wrong. Which client &#x2F; server protocol over TCP ever had single direction data transfer? Close to 100% of all TCP usages are between a single client and a single server, communicating both ways.<p>The design for socket is practical for their intended purpose. Trying to shoe-horn an artifical problem an a design will, unsuprinsingly, no yield proper result.
评论 #6081755 未加载
munin将近 12 年前
this is something I hate about the &quot;unix design philosophy&quot;. when you start digging deeper, you realize that &quot;everything is a file&quot; is true, except for network connections, and A&#x2F;V devices, and input peripherals, and really that the only things that actually are files, are files. everything else is allllmost a file except in one little weird way, or, many big big ways...
评论 #6080625 未加载
评论 #6080866 未加载
评论 #6080476 未加载
评论 #6080781 未加载
评论 #6081578 未加载
评论 #6080497 未加载
评论 #6082431 未加载
评论 #6081802 未加载
评论 #6080466 未加载
tankenmate将近 12 年前
I just don&#x27;t see the problem that djb is highlighting. To me the crucial mistake comes in this sentance; &quot;When the generate-data program finishes, the same fd is still open in the consume-data program, so the kernel has no idea that it should send a FIN.&quot; generate-data and consume-data should <i>NEVER</i> share a fd; the two pipes in the &quot;same machine model&quot; are two seperate sets to fds (the pipe() returns both ends of the fd in one call). Likewise the TCP model should use two separate (sets of)sockets. shutdown()&#x27;s real use is for poorly implemented protocols where the server has no real time way of initiating a control message to the client apart from &quot;abort&quot;ing the connection; some protocols only allow the client to initiate sending a message. Also note that one end of the connection sending a FIN doesn&#x27;t preclude the other end from sending more data.
评论 #6086963 未加载
shabble将近 12 年前
The original doesn&#x27;t appear to be dated, but archive.org[1] has the same thing going back to at least 2003.<p>[1] <a href="http://web.archive.org/web/20030805143958/http://cr.yp.to/tcpip/twofd.html" rel="nofollow">http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20030805143958&#x2F;http:&#x2F;&#x2F;cr.yp.to&#x2F;tc...</a><p>Edit: HTTP Last-Modified header looks like it might be right:<p><pre><code> Last-Modified: Tue, 10 Jun 2003 23:44:11 GMT</code></pre>
评论 #6080794 未加载
jingo将近 12 年前
Hey, I got a better idea. Let&#x27;s give each socket a &quot;human-friendly&quot; name. Translating back and forth to the underlying numerical representation should be easy enough.[1]<p>Heck, we could even create a centralized system for managing our new namespace. OMG, maybe we could charge people money for the names? Yes! We&#x27;re rich!<p>And the result: Hundreds of millions of &quot;parked&quot; domains serving up cheap advertising. Simply brilliant!<p>1. See Hobbit&#x27;s comments in netcat source code for a differing opinion.<p>I often wish that people like djb or Hobbit (=low tolerance for nonsense) had designed the systems that we are now stuck with.<p>Though they are only applications, netcat and ucpsi have aged well and remain a pleasure to use.
评论 #6080674 未加载
评论 #6081347 未加载
评论 #6081761 未加载
tomp将近 12 年前
Hmmm... use two TCP sockets?
评论 #6080741 未加载
rumcajz将近 12 年前
Absolutely true. Too late to fix now though.
评论 #6080293 未加载
perfunctory将近 12 年前
I don&#x27;t quite understand the appeal of everything is a file philosophy. Neither everything is an object for that matter. It makes the world look like this:<p><a href="http://www.youtube.com/watch?v=HPeattKV74A" rel="nofollow">http:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=HPeattKV74A</a>
nly将近 12 年前
Now let&#x27;s talk about how half the higher layer protocols in the world that use TCP should probably be using a reliable datagram protocol...
评论 #6083366 未加载
binarymax将近 12 年前
Someone please correct me if I am wrong, but is this something that Plan9 was solving? Everything (including sockets) being treated as a file?
评论 #6080348 未加载
drudru11将近 12 年前
tl;dr - this is about &#x27;leaky abstractions&#x27;<p><a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html" rel="nofollow">http:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;articles&#x2F;LeakyAbstractions.htm...</a><p>this was written about by Joel in 2002.<p>This article probably dates before that, but is last modified circa 2003 (see other comment on that)
beachstartup将近 12 年前
netcat solves this.
评论 #6080217 未加载