char *
{
int bytesRead, bytesTotal(0);
for(; bytesTotal < length; bytesTotal += bytesRead)
{
if((bytesRead = ds.readRawData(buffer + bytesTotal, length - bytesTotal)) == -1)
{
qFatal("%s:%s(%d) - failed to read raw data: %s", __FILE__, __FUNCTION__, __LINE__, ds.device()->errorString().toLocal8Bit().constData());
}
if(!bytesRead)
{
qFatal("%s:%s(%d) - broken connection while reading raw data", __FILE__, __FUNCTION__, __LINE__);
}
}
return buffer;
}
const char *
writeRawData
(const char *buffer,
QDataStream &ds,
int size
){
int bytesWritten, bytesTotal(0);
for(; bytesTotal < size; bytesTotal += bytesWritten)
{
if((bytesWritten = ds.writeRawData(buffer + bytesTotal, size - bytesTotal)) == -1)
{
qFatal("%s:%s(%d) - Failed to write raw bytes: %s", __FILE__, __FUNCTION__, __LINE__, ds.device()->errorString().toLocal8Bit().constData());
}
if(!bytesWritten)
{
qFatal("%s:%s(%d) - stream closed while writing raw data", __FILE__, __FUNCTION__, __LINE__);
}
}
return buffer;
}
char *
readRawData(char *buffer, QDataStream &ds, int length)
{
int bytesRead, bytesTotal(0);
for(; bytesTotal < length; bytesTotal += bytesRead)
{
if((bytesRead = ds.readRawData(buffer + bytesTotal, length - bytesTotal)) == -1)
{
qFatal("%s:%s(%d) - failed to read raw data: %s", __FILE__, __FUNCTION__, __LINE__, ds.device()->errorString().toLocal8Bit().constData());
}
if(!bytesRead)
{
qFatal("%s:%s(%d) - broken connection while reading raw data", __FILE__, __FUNCTION__, __LINE__);
}
}
return buffer;
}
const char *
writeRawData(const char *buffer, QDataStream &ds, int size)
{
int bytesWritten, bytesTotal(0);
for(; bytesTotal < size; bytesTotal += bytesWritten)
{
if((bytesWritten = ds.writeRawData(buffer + bytesTotal, size - bytesTotal)) == -1)
{
qFatal("%s:%s(%d) - Failed to write raw bytes: %s", __FILE__, __FUNCTION__, __LINE__, ds.device()->errorString().toLocal8Bit().constData());
}
if(!bytesWritten)
{
qFatal("%s:%s(%d) - stream closed while writing raw data", __FILE__, __FUNCTION__, __LINE__);
}
}
return buffer;
}
To copy to clipboard, switch view to plain text mode
... which, when viewed in a debugger, shows that I get
Bookmarks