Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-67576

QAbstractSocket::setSocketOption() has no effect if called before QAbstractSocket::connectToHost()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.6, 5.11.0 Beta 2
    • Fix Version/s: None
    • Labels:
      None

      Description

      Setting QAbstractSocket::LowDelayOption option via QAbstractSocket::setSocketOption() has no effect if called before QAbstractSocket::connectToHost().

      Example:

      #include <QCoreApplication>
      #include <QHostAddress>
      #include <QTcpSocket>
      
      static void example1(QTcpSocket& socket)
      {
         socket.setSocketOption(QAbstractSocket::LowDelayOption, 1);
         socket.connectToHost(QHostAddress::LocalHost, 22);
      }
      
      static void example2(QTcpSocket& socket)
      {
         socket.connectToHost(QHostAddress::LocalHost, 22);
         socket.setSocketOption(QAbstractSocket::LowDelayOption, 1);
      }
      
      int main(int argc, char *argv[])
      {
         QCoreApplication app(argc, argv);
         QTcpSocket socket;
         example1(socket);
         return app.exec();
      }
      

      `example1()` silently ignores setting `QAbstractSocket::LowDelayOption` and produce syscalls as attached in appendix log1.txt. On the other hand, `example2()`seems to work (see appendix log2.txt)

      Actually, the documentation contains a hint, that `QAbstractSocket::KeepAliveOption` must be set before the socket is connected when running on Windows Runtime. In my opinion, setting an option via `QAbstractSocket::setSocketOption()` should be always possible and independent if the socket is already connected, connecting or idle. POSIX API also allows to configure socket options before establishing a connection.

        Attachments

        1. log1.txt
          1 kB
        2. log2.txt
          1 kB
        3. main.cpp
          0.5 kB
        4. setsocketopt.pro
          0.0 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              docteam Qt Documentation Team
              Reporter:
              sebastian.f.zenker Sebastian Zenker
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes