0

I'm using blocking socket with SSL_read on server side.In some un expected conditions if the client die i need to disconnect that specific client connection on server side with SO_KEEPALIVE.How can i setsockopt with 5 minutes SO_KEEPALIVE ? Thanks in advance.

  • In some OSes, yes. Which one are you looking for an answer for? – Shawn Jun 08 '20 at 04:03
  • `SO_KEEPALIVE` is probably not the option you were looking for (keep-alive is for keeping idle connection alive), `SO_RCVTIMEO` and `SO_SNDTIMEO` are the one you want to set, see [this answer](https://stackoverflow.com/a/4182564/105104) – dvhh Jun 08 '20 at 04:15
  • Looking for Centos @Shawn – Sudhakar K Jun 08 '20 at 05:49
  • is there any other problems do we face if we use SO_RCVTIMEO @dvhh? – Sudhakar K Jun 08 '20 at 05:51

1 Answers1

0

In Linux, you can adjust the timeout on a socket that's had SO_KEEPALIVE turned on with the TCP_KEEPIDLE option. It takes a time in seconds:

int timeout = 300;
setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE, &timeout, sizeof timeout);
Shawn
  • 47,241
  • 3
  • 26
  • 60