【发布时间】:2012-03-11 07:06:19
【问题描述】:
我在 ubuntu 机器上使用 python 2.7。
客户端尝试连接到服务器。我得到了一个 EINPROGRESS,这是非阻塞套接字所期望的。
为了检查连接是否成功,我按照 {connect} 手册页的建议进行操作:
# EINPROGRESS The socket is nonblocking and the connection cannot be
# completed immediately. It is possible to select(2) or poll(2) for
# completion by selecting the socket for writing. After select(2)
# indicates writability, use getsockopt(2) to read the SO_ERROR option at
# level SOL_SOCKET to determine whether connect() completed successfully
# (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error
# codes listed here, explaining the reason for the failure)
当服务器离线时,这会给我一个 ECONNREFUSED。到目前为止一切顺利。
当连接失败时,我想再试几次。
问题:我第二次尝试连接同一个套接字时,{connect} 向我发送了 ECONNABORTED。这个不在 {connect} 的手册页中。什么意思?
【问题讨论】:
-
即使你让这个工作,如果我是你,我不会这样做。我不知道套接字 API 在技术上是否允许重用以前连接失败的套接字,但是虽然 Linux 似乎并不介意,但我在 MacOS 上得到了 EINVAL。每次打开一个新套接字。