How to detect internet disconnection on SSL/TCP so

2019-07-25 00:11发布

This question already has an answer here:

I am having a thread which blocks on select() based SSL_read(). The main thread writes whenever needed using SSL_write(). During unit testing, I found a problem:

  • Client TCP socket connect() to server on SSL(TLS)
  • After sometime, disable internet
  • Write some data on client TCP/SSL socket

Even without interenet, the SSL_write() returns the correct number of bytes written, instead of 0 or some error. Such interenet disconnections are arbitrary, neither too high nor too low.

My expectation is that, whenever there is an internet disconnection, the socket should generate some interesting event, which is detectable and I will discontinue the socket + SSL connections.
In case I have to establish some client-server hand made protocol, then that's possible.

What is the best way to achieve such internet detection?
Expecting a solution with lesser CPU cycles & lesser client server communication. I am sure that, this is not a very special problem and hence must have been solved before.

[P.S.: The client sockets are opened on mobile platforms like Android & iOS, however I would like to know a general solution.]

标签: c++ c sockets ssl tcp
1条回答
Animai°情兽
2楼-- · 2019-07-25 00:51

This is general problem with sockets. You can't have a certified delivery with them. If you want to know if the counterparty is indeed reachable, you have to implement some sort of hearbeats yourself.

Generally successful write to the socket is no indication of availability of the recepient on the other end.

查看更多
登录 后发表回答