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

QNetworkAccessManager::post does not finish buffering

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.6.0
    • Network
    • None

    Description

      When a HTTP POST request is created using QNetworkAccessManager::post and a sequential QIODevice, the data is buffered. The operation is finished when iodevice returns -1. In case of return 0, buffering stops but nothing is sent yet. Is this intended behavior?

      qnetworkreplyimpl.cpp, lines 181-206:

          // read data into our buffer
          forever {
              bytesToBuffer = outgoingData->bytesAvailable();
              // unknown? just try 2 kB, this also ensures we always try to read the EOF
              if (bytesToBuffer <= 0)
                  bytesToBuffer = 2*1024;
      
              char *dst = outgoingDataBuffer->reserve(bytesToBuffer);
              bytesBuffered = outgoingData->read(dst, bytesToBuffer);
      
              if (bytesBuffered == -1) {
                  // EOF has been reached.
                  outgoingDataBuffer->chop(bytesToBuffer);
      
                  _q_bufferOutgoingDataFinished();
                  break;
              } else if (bytesBuffered == 0) {
                  // nothing read right now, just wait until we get called again
                  outgoingDataBuffer->chop(bytesToBuffer);
      
                  break;
              } else {
                  // don't break, try to read() again
                  outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered);
              }
          }
      

      http://doc.trolltech.com/4.6/qiodevice.html#readData says:
      Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an error occurred. If there are no bytes to be read, this function should return -1 if there can never be more bytes available (for example: socket closed, pipe closed, sub-process finished).

      http://doc.trolltech.com/4.6/qiodevice.html#read says:
      0 is returned when no more data is available for reading. However, reading past the end of the stream is considered an error, so this function returns -1 in those cases (that is, reading on a closed socket or after a process has died).

      Attachments

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

        Activity

          People

            tmacieir Thiago Macieira (closed Nokia identity) (Inactive)
            kko Kimmo Kotajärvi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes