How epoll detect clientside close in Python?

后端 未结 10 590
清歌不尽
清歌不尽 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:33

    If the socket is still open but no read/write available epoll.poll will timeout.

    If data if available from the peer, you get an EPOLLIN and data will be available.

    If the socket is closed by the peer, you will get an EPOLLIN but when you read it it will return "".

    you could then close the socket by shutting it down and picking up the resulting EPOLLHUP event to clean up your internal structures.

    or perform cleanup and unregister the epoll.

    elif event & select.EPOLLIN:
        data = cs[fileno].recv(4)
    
    if not data:
        epoll.modify(fileno, 0)
        cs[fileno].shutdown(socket.SHUT_RDWR)
    

提交回复
热议问题