对我来说,连接将始终可读,或者可写。
我们不能依赖 r/w 事件吗? 当客户端关闭连接时,r/w迟早会得到错误返回,然后我们可以关闭fds。
所以连接管理的唯一意义是防止连接不执行任何操作(它可能始终可写入服务器,但服务器在正常交互后没有任何内容可写),对吗?
最佳答案
to me,the connection will all the time be readable,or it will be writeable
不,不会。仅当套接字接收缓冲区中已存在数据时才可读,并且仅当套接字发送缓冲区中有空间时才可写(这是大多数情况,但不是全部)。
这就是 select()
的用途:告诉您这些事件何时发生。
can't we rely on the r/w event?
如果这意味着“读写”事件,那么这就是 select()
为您提供的。如果您指的是其他内容,则必须解释一下是什么。
when client close connection, r/w will get error return sooner or later
不,不会。它将获得流结束指示。根据您使用的 API 和语言,这有多种形式,但它们都不是错误。
then we can close fds.
当然,当您使用完 fd
后,您应该关闭它们,但网络编程远不止这些。
so the only meaning of connection management is to prevent a connection from doing nothing (it may all the time be writable to the sever,but server got nothin to write after Normal interaction),is this right?
毫无意义。您在没有来源或引文的情况下引入了“连接管理”一词,然后断言它仅具有您赋予它的含义,而没有证据,而“so”一词只是一个不合逻辑的推论。
关于c++ - 为什么我们需要连接超时管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28870491/