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

QAbstractSocket::isValid() documentation is unclear

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.8.0 Beta2
    • None
    • All

    Description

      I'm open to the idea that this is a bug in my comprehension rather than the documentation, but I also think there's always room for more clarity.

      I find the documentation for QAbstractSocket::isValid() to be confusing. In its entirety:

      Returns true if the socket is valid and ready for use; otherwise returns false.
      Note: The socket's state must be ConnectedState before reading and writing can occur.
      

      The code is pretty slim:

      bool QAbstractSocket::isValid() const
      {
          return d_func()->socketEngine ? d_func()->socketEngine->isValid() : isOpen();
      }
      

      Neither the documentation nor the code is clear about what it means for the socket to be "valid." The documentation states that "the socket's state must be ConnectedState before reading and writing can occur." So, is the isValid() method equivalent to checking the socket's state and ensuring that it is in ConnectedState? Based on the code, no. At least, not without digging in to figure out what d_func() ->socketEngine is. Then I need to figure out what it means for a socketEngine to be valid.

      If the socket's state isn't the criterion for validity, then what is that note for? Can a socket be valid without being in the ConnectedState? In that case, a valid socket isn't necessarily one that can be used for reading and writing.

      Ultimately, what I (and possibly others) are interested in is a way to ask a socket if it's ok to read/write data. I can listen for the connected() and disconnected() signals and track the status as state data, but is that the "best" way? The way I read the documentation, a socket can be valid, and it may or may not be in the ConnectedState. If it isn't, then I don't really know what it means for it to be valid.

      Can this be clarified?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            manordheim MÃ¥rten Nordheim
            malocascio Mark Locascio
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes