在处理其他数据时接收到数据时,套接字select()的预期行为?
|
我有一个关于套接字编程和在while循环中运行select命令的概念性问题。从示例回显服务器(用python编写,但语言无关紧要)中查看以下摘录:http://ilab.cs.byu.edu/python/select/echoserver.html
while running:
inputready,outputready,exceptready = select.select(input,[],[])
for s in inputready:
if s == server:
# handle the server socket
client, address = server.accept()
input.append(client)
elif s == sys.stdin:
# handle standard input
junk = sys.stdin.readline()
running = 0
else:
# handle all other sockets
data = s.recv(size)
if data:
s.send(data)
else:
s.close()
input.remove(s)
问题:如果新客户端此时连接并发送数据,则进程在for循环中执行代码时预期的行为是什么?是否有某种类型的缓冲区是默认套接字库的一部分,以便在随后的select调用中,它将立即返回处理早期请求时输入的值?还是在服务器实际上没有在select()中等待时连接的新客户端被忽略,这样总是有可能(尽管这不太可能,因为我们正在谈论毫秒),所以请求将被丢弃?
(注意:我在使用套接字的不同代码库上进行了一些经验测试,似乎有一个缓冲区-如果实际上是设计使然,该缓冲区的典型大小是多少?)
没有找到相关结果
已邀请:
1 个回复
阀傻