简体   繁体   English

TCP无阻塞socket.connect()和socket.recv()错误问题。 (Python或C)

[英]TCP non-blocking socket.connect() and socket.recv() Error questions. (Python or C)

I am doing some stress test to a simple HTTP redirect server in Python scripts. 我正在对Python脚本中的简单HTTP重定向服务器进行压力测试。 The script is set up with epoll (edge trigger mode) with non-blocking sockets. 该脚本是通过具有非阻塞套接字的epoll(边缘触发模式)设置的。 But I observed something that I don't quite understand, 但是我观察到一些我不太了解的东西,

1) epoll can get both ECONNREFUSED and ETIMEOUT errno while the connect() is in process. 1)在connect()处理过程中,epoll可以同时获取ECONNREFUSED和ETIMEOUT错误。 Don't they both indicates the remote server can't accept the connection? 两者都不表示远程服务器无法接受连接吗? How are they different, how does a client tell the difference? 它们有何不同,客户如何分辨?

2) sometimes when EPOLLIN is notified by epoll, socket.recv() returns empty string without any exception thrown (or errno in C), I can keep reading the socket without getting any exception or error, it just always returns empty string. 2)有时,当epoll通知EPOLLIN时,socket.recv()返回空字符串而不会引发任何异常(或C中的errno),我可以继续读取套接字而不会出现任何异常或错误,它总是返回空字符串。 Why is that? 这是为什么?

Thanks, 谢谢,

  1. ECONNREFUSED signals that the connection was refused by the server, while ETIMEOUT signals that the attempt to connect has timed out, ie that no indication (positive or negative) about the connection attempt was received from the peer. ECONNREFUSED表示服务器拒绝了连接,而ETIMEOUT表示连接尝试已超时,即未从对等方收到有关连接尝试的指示(正或负)。

  2. socket.recv() returning an empty string without error is simply the EOF condition, corresponding to an empty read in C. This happens when the other side closes the connection, or shuts it down for writing. socket.recv()返回空字符串且没有错误只是EOF条件,对应于C中的空读取。这种情况发生在另一端关闭连接或将其关闭以进行写入时。 It is normal that EPOLLIN is notified when EOF occurs, because you want to know about the EOF (and because you can safely recv from the socket without it hanging). 通常,在发生EOF时会通知EPOLLIN ,因为您想了解EOF(并且可以在不挂起套接字的情况下安全地从套接字中recv )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM