-1

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)

dbush
  • 205,898
  • 23
  • 218
  • 273
user292048
  • 15
  • 6
  • 3
    TCP keepalives are empty data packets, they're not visible to applications. – Barmar Jun 03 '19 at 21:34
  • You should use application-layer heartbeat messages. – Barmar Jun 03 '19 at 21:34
  • 4
    Why do you think you need to do anything to keep the connection open? Just don't close it. – Barmar Jun 03 '19 at 21:35
  • 4
    Note that the name "keepalive" is misleading. It doesn't keep the connection alive, it detects when the connection has gone away without a normal shutdown. – Barmar Jun 03 '19 at 21:42
  • 3
    What problem are you having? The connection will stay open automatically as long as neither the client nor server calls `close()`. You can't detect keepalives, but you don't need to. – Barmar Jun 03 '19 at 21:44
  • 1
    Then you need an application heartbeat. And if you do this, you don't need TCP keepalive. – Barmar Jun 03 '19 at 21:48
  • 3
    And I want a pony. Neither of us will get what we want. – Barmar Jun 03 '19 at 21:57
  • You never explained what exactly you are trying to implement. Are you implementing TCP over raw-sockets? Then your problem is desribed [here](https://stackoverflow.com/questions/13082023/raw-socket-listener). –  Jun 04 '19 at 00:13
  • 2
    @user292048 Then you are talking about HTTP keep-alive, not TCP keep-alive. Those are different things. –  Jun 04 '19 at 02:01
  • The server *will* keep the connection open until it times the connection out or receives EOS or an error on it. Your question doesn't make sense. – user207421 Aug 18 '19 at 02:46

1 Answers1

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.

Barmar
  • 741,623
  • 53
  • 500
  • 612