select.epoll.poll和select.POLLIN究竟如何工作?

时间:2016-07-07 01:52:04

标签: python sockets asynchronous networking network-programming

import select
import socket

loop = select.epoll()

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('0.0.0.0', 8000))
sock.listen(1000)
conn, src = sock.accept()

loop.register(conn.fileno(), select.POLLIN)
while True:
    loop.poll()
    data = conn.recv(1024)
    if not data:
        print('receive nothing')

我上面有这个脚本,(我猜)它永远不会打印"receive nothing",因为poll()注册的select.POLLIN只有在确实要从套接字中读取内容时才会返回。但是,当我

> nc localhost 8000
test

脚本不断喷出"receive nothing"

0 个答案:

没有答案