Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

What does QAbstractSocket::KeepAliveOption actually do?



  • The documentation is a bit unclear, but if I enable QAbstractSocket::KeepAliveOption on a TCP socket, will it automatically send the keepalive packets for me?


  • Moderators

    @Vadi2
    as the docs also state it sets the SO_KEEPALIVE option on the underlying platform socket.
    So you should look up this option for your target platform.



  • What does that practically mean on Windows/Linux/macOS?


  • Moderators

    @Vadi2
    Windows, Linux
    the principle should be the same on all platforms (for TCP)



  • @Vadi2
    Behaviour of SO_KEEPALIVE varies enormously between various OSes, different TCP stacks, etc. You really do have to do a lot of reading (e.g. @raven-worx's link, stackoverflow etc.) if you really know what it might or might not do.

    My experience (maybe a bit old now)? Don't rely on it to do anything.

    Or, in particular: I used to use to (try to) keep a connection from timing out. In practice, far from that, what it actually did was: caused my app to notice that a connection had become lost, and so complain, when had I not used it then the app wouldn't have noticed a lost connection till I sent/received, and by then might have silently re-established the connection without complaint. So I gave up on it!


Log in to reply