How epoll detect clientside close in Python?

后端 未结 10 675
清歌不尽
清歌不尽 2021-02-04 21:22

Here is my server

\"\"\"Server using epoll method\"\"\"

import os
import select
import socket
import time

from oodict import OODict

addr = (\         


        
10条回答
  •  面向向阳花
    2021-02-04 21:45

    After I move select.EPOLLHUP handling code to the line before select.EPOLLIN, hup event still cant be got in 'telnet'. But by coincidence I found that if I use my own client script, there are hup events! strange...

    And according to man epoll_ctl

       EPOLLRDHUP (since Linux 2.6.17)
              Stream socket peer closed connection, or shut down writing half of connection.  (This flag is especially useful for writing simple code  to
              detect peer shutdown when using Edge Triggered monitoring.)
    
       EPOLLERR
              Error  condition  happened on the associated file descriptor.  epoll_wait(2) will always wait for this event; it is not necessary to set it
              in events.
    
       EPOLLHUP
              Hang up happened on the associated file descriptor.  epoll_wait(2) will always wait for this event; it  is  not  necessary  to  set  it  in
              events.
    

    Seems there shall be a EPOLLRDHUP event when remote side closed connection, which is not implemented by python, don't know why

提交回复
热议问题