问题
I wrote my own server with epoll. When I sent TCP keep alive packages from client to server, epoll event will not get triggered. Question: I want my server to keep the connection open when server gets tcp keep alive packages.
I also tried to look at tcp info but there are no update for its attributes when server got keep alive packages.
I understand tcp keep alive packages is no data but header. I saw in my tcpdump, kernel sent back tcp keep alive ACK after received keep alive package. My goal is to keep connection open when keep alive arrives (kind like reset timer in my server, my server can close connection in no tcp real data)
I set up my client to make connection and send data (e.g "hello world") then send keep alive packages to server.
My server is epoll triggered. I already also tried to set my server to be non-blocking.
// epoll setting I tested
EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET
(most questions I found on internet are related to client side, my question is more towards server or receiver side of tcp keep alive, how to keep it open)
回答1:
No, this is not possible as far as I know.
You will have to implement a heartbeat in the application protocol, and then you can stop using TCP keepalive.
来源:https://stackoverflow.com/questions/56434706/how-to-detect-tcp-keep-alive-packets-and-keep-connection-open