gpt4 book ai didi

linux - 为什么在设置 O_NONBLOCK 时此读取阻塞?

转载 作者:太空狗 更新时间:2023-10-29 11:44:27 30 4
gpt4 key购买 nike

Strace 摘录(请忽略将 xml 发送到 ssh):

dup(12)                                 = 13
getsockname(13, {sa_family=AF_INET, sin_port=htons(46811), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
getsockopt(13, SOL_SOCKET, SO_TYPE, [1], [4]) = 0
fstat(13, {st_mode=S_IFSOCK|0777, st_size=0, ...}) = 0
getsockname(13, {sa_family=AF_INET, sin_port=htons(46811), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
getsockopt(13, SOL_SOCKET, SO_TYPE, [1], [4]) = 0
fcntl(13, F_SETFD, FD_CLOEXEC) = 0
fcntl(13, F_GETFL) = 0x802 (flags O_RDWR|O_NONBLOCK)
fcntl(13, F_SETFL, O_RDWR|O_NONBLOCK) = 0
setsockopt(13, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
setsockopt(13, SOL_SOCKET, SO_REUSEPORT, [0], 4) = 0
setsockopt(13, SOL_TCP, TCP_NODELAY, [0], 4) = 0
setsockopt(13, SOL_TCP, TCP_CORK, [0], 4) = 0
fcntl(12, F_GETFL) = 0x802 (flags O_RDWR|O_NONBLOCK)
fcntl(12, F_SETFL, O_RDWR) = 0
close(12) = 0
getpeername(13, {sa_family=AF_INET, sin_port=htons(22), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
sendto(13, "<stream:stream xmlns:stream='htt"..., 133, MSG_NOSIGNAL, NULL, 0) = 133
read(13, "SSH-2.0-OpenSSH_6.6.1\r\n", 4096) = 23
read(13, <unfinished ...>

(最后我 kill -9 it.)

最后的 read() 是阻塞的;即使 O_NONBLOCK 是通过 fcntl() 设置的。

这怎么可能?


版本信息:

$ uname -r
3.16.4-1-ARCH

最佳答案

因为 FD 13 是 FD 12 的 dup(),所以这一行删除了你的 O_NONBLOCK:

fcntl(12, F_SETFL, O_RDWR)              = 0

关于linux - 为什么在设置 O_NONBLOCK 时此读取阻塞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26514160/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com