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

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

    XMLWordPrintable

Details

    • 2
    • e83c9e4e8e74c57708fa88ee441584eee18f19b6 eacca3d2c2 (qt/qtbase/6.2) eacca3d2c2 (qt/tqtc-qtbase/6.2) fd3a0b5491 (qt/qtbase/6.3) fd3a0b5491 (qt/tqtc-qtbase/6.3) fd3a0b5491 (qt/tqtc-qtbase/6.3.0)
    • Team Two Foundation Sprint 52, Team B Foundation Sprint 53

    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

            manordheim Mårten Nordheim
            sebastian.f.zenker Sebastian Zenker
            Vladimir Minenko Vladimir Minenko
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes