How epoll detect clientside close in Python?

后端 未结 10 572
清歌不尽
清歌不尽 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条回答
  •  梦毁少年i
    2021-02-04 21:44

    My ad-hoc solution to bypass this problem

    --- epoll_demo.py.orig  2009-04-28 18:11:32.000000000 +0800
    +++ epoll_demo.py   2009-04-28 18:12:56.000000000 +0800
    @@ -18,6 +18,7 @@
     epoll.register(s.fileno(), select.EPOLLIN) # Level triggerred
    
     cs = {}
    +en = {}
     data = ''
     while True:
         time.sleep(1)
    @@ -29,10 +30,18 @@
                 sk.setblocking(0)
                 print addr
                 cs[sk.fileno()] = sk
    +            en[sk.fileno()] = 0
                 epoll.register(sk.fileno(), select.EPOLLIN)
    
             elif event & select.EPOLLIN:
                 data = cs[fileno].recv(4)
    +            if not data:
    +                en[fileno] += 1
    +                if en[fileno] >= 3:
    +                    print 'closed'
    +                    epoll.unregister(fileno)
    +                continue
    +            en[fileno] = 0
                 print 'recv ', data
                 epoll.modify(fileno, select.EPOLLOUT)
             elif event & select.EPOLLOUT:
    

提交回复
热议问题