ECONNRESET在AF_LOCAL套接字的上下文中是什么意思? [英] What does ECONNRESET mean in the context of an AF_LOCAL socket?

查看:115
本文介绍了ECONNRESET在AF_LOCAL套接字的上下文中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道对于TCP套接字,ECONNRESET与RST数据包有关.但是我在read()和write()调用中也看到了AF_LOCAL套接字的ECONNRESET错误.这是什么意思? ECONNRESET与read()返回0或write()抛出EPIPE有何不同?

I understand that for TCP sockets ECONNRESET has got something to do with RST packets. But I've seen ECONNRESET errors for AF_LOCAL sockets too, on read() and write() calls. What does this mean? How is ECONNRESET different from read() returning 0 or write() throwing EPIPE?

推荐答案

似乎ECONNRESET表示另一侧已关闭连接而未读取已发送给它的未完成数据,并且可以在两个read( ) 和写().但是确切的行为取决于操作系统.

It would appear that ECONNRESET means that the other side has closed the connection without reading outstanding data that has been sent to it, and can be triggered on both read() and write(). But the exact behavior depends on the operating system.

似乎对一个已经关闭的套接字执行write()操作,并且没有未完成的传出数据时,将触发该事件.适用于PF_LOCAL和TCP套接字.示例(Ruby):

Seems to be triggered when one write()s to a socket that has already been closed, and there is no outstanding outgoing data. Applicable to both PF_LOCAL and TCP sockets. Example (Ruby):

a, b = UNIXSocket.pair
b.close
a.write("foo")   # => EPIPE, on all OSes

read()返回0

在另一端关闭连接且没有未完成的传出数据时触发.同时适用于PF_LOCAL和TCP套接字.

read() returning 0

Triggered when the other side has closed the connection, and there is no outstanding outgoing data. Applicable to both PF_LOCAL and TCP sockets.

a, b = UNIXSocket.pair
b.close
a.read    # => 0 bytes, on all OSes

ECONNRESET

在Linux上,其行为如下:

ECONNRESET

On Linux it behaves like this:

在尚未将未完成的传出数据写入另一端时触发. read()对PF_LOCAL和TCP套接字都触发它,但是write()仅对TCP套接字触发它; PF_LOCAL套接字触发EPIPE.

Triggered when there's outstanding outgoing data that has not yet been written to the other side. read() triggers it for both PF_LOCAL and TCP sockets, but write() triggers it only for TCP sockets; PF_LOCAL sockets trigger EPIPE.

请参阅示例以了解特定的OS行为.如果您知道其他操作系统的行为,请做出贡献.

See examples for specific OS behavior. Please contribute if you know how other OSes behave.

示例1:PF_LOCAL套接字上的read()

Example 1: read() on PF_LOCAL socket

a, b = UNIXSocket.pair
a.write("hello")
b.close
a.read
# Linux: ECONNRESET
# OS X : returns 0 bytes

示例2:TCP套接字上的read()

Example 2: read() on TCP socket

# Side A                                # Side B
                                        s = TCPServer.new('127.0.0.1', 3001)
                                        c = s.accept
c = TCPSocket.new('127.0.0.1', 3001)
c.write("hello")
                                        c.close
c.read
# Linux: ECONNRESET
# OS X : returns 0 bytes

示例3:在PF_LOCAL套接字上写入()

Example 3: write() on PF_LOCAL socket

a, b = UNIXSocket.pair
a.write("hello")
b.close
a.write("world")
# Linux: EPIPE and not ECONNRESET
# OS X : EPIPE and not ECONNRESET

示例4:在TCP套接字上写入()

Example 4: write() on TCP socket

# Side A                                # Side B
                                        s = TCPServer.new('127.0.0.1', 3001)
                                        c = s.accept
c = TCPSocket.new('127.0.0.1', 3001)
c.write("hello")
                                        c.close
c.write("world")
# Linux: ECONNRESET
# OS X : no error

这篇关于ECONNRESET在AF_LOCAL套接字的上下文中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆