Hi Guys,
I have encountered an epoll issues. On the server side, I use epoll.poll() to
wait for events, when there is a socket which has EPOLLIN/EPOLLUP events, I
first try to read the socket (I did this coz it says EPOLLIN ready, I might
think it has some data in its recv queue). After reading 0 length data, the
code thinks the peer shutdown its socket, so it notifies the epoll that it
doesn't care any events for this socket anymore by calling epoll.modify(sock,
0). But this call seems failed to function, coz when I did another round of
epoll.poll(), the socket is still ready for EPOLLUP. My understanding for epoll
Linux interface is that it should work if we pass no events when calling
epoll_ctl.
Steps to reproduce this problem. Open up two consoles, one for client, one for
server. Input the following code in the two consoles by the following order.
---
Server
---
>>> import socket
>>> accept_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> accept_socket.setblocking(False)
>>> accept_socket.bind(('10.5.6.10', 9999))
>>> accept_socket.listen(socket.SOMAXCONN)
>>> import select
>>> ep = select.epoll()
>>> ep.register(accept_socket.fileno(), select.EPOLLIN)
client
---
>>> import socket
>>> st = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> st.connect(('10.5.6.10', 9999))
Server
----
>>> ep.poll()
[(4, 1)]
>>> sock, peer_addr = accept_socket.accept()
>>> ep.register(sock, select.EPOLLIN)
Client
---
>>> st.send('ahello')
6
Server
---
>>> ep.poll()
[(6, 1)]
>>> sock.recv(1024)
'ahello'
>>> sock.shutdown(socket.SHUT_WR)
Client
---
>>> st.recv(1024)
''
>>> st.shutdown(socket.SHUT_WR)
Server
----
>>> ep.poll()
[(6, 17)]
>>> sock.recv(1024)
''
>>> ep.modify(sock, 0) <= I am saying, i don't care any events for the sock
>>> ep.poll() <= but epoll still return the event for this sock
[(6, 16)]
>>> ep.poll()
[(6, 16)]
>>> ep.modify(sock, 0)
>>> ep.poll()
[(6, 16)]
--
http://mail.python.org/mailman/listinfo/python-list