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

Windows limitation on overlapped buffer size, Error 87 Wrong Parameter

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.7
    • Serial Port
    • None
    • Windows 10, VC 2013, Qt 5.7.1, QSerialPort
    • Windows

    Description

      Observation: when communicating with a Linux g_serial based device from Windows 10 I get Windows error 87 "Wrong Parameter" if the QByteArray passed to QSerialPort::write is 4.2 MB or greater, but it works if 4.1 MB or smaller.

      Analysis: _q_startAsyncWrite seems to hand over the original QByteArray 1:1 to ::WriteFile. The code does not assume any buffer size limitation and indeed I did not find any MS documentation or forum posts indicating such a limitation. But there seems to be one on Windows, even if undocumented. The issue does not occur on macOS. 

      Work-around: I can avoid the Windows error using the following adapter:

       

      static int serialWriteAdapter( QSerialPort* port, const QByteArray& buf ){
      #ifdef Q_OS_WIN 
          const int winBufferSizeLimit = 4100000;
         int i = 0; 
         while( i < buf.size() ) {
             const int res = port->write( buf.mid(i,winBufferSizeLimit) );
             if( res < 0 ) return -1;
             i += res;
          }
          return i;
      #else
          return port->write(buf);
      #endif
      }
      

       

      The work-around also works on Windows 7.

      Attachments

        For Gerrit Dashboard: QTBUG-69229
        # Subject Branch Project Status CR V

        Activity

          People

            Unassigned Unassigned
            r.k. Rochus Keller
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes