Skip to content

Commit

Permalink
Improve debug output when we attempt to write to a socket that has be…
Browse files Browse the repository at this point in the history
…en disconnected from under us..

This will print the start of the data being sent... It should at least give us a hint as to the cause of the 'No data written on writeBlock' and 'Error, socket went unconnected.' errors some people are seeing.
  • Loading branch information
daniel-kristjansson committed May 6, 2011
1 parent 946ad5b commit 519b692
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions mythtv/libs/libmythbase/mythsocket.cpp
Expand Up @@ -267,6 +267,18 @@ qint64 MythSocket::writeBlock(const char *data, quint64 len)
return rval;
}

static QString toSample(const QByteArray &payload)
{
QString sample("");
for (uint i = 0; (i<60) && (i<(uint)payload.length()); i++)
{
sample += QChar(payload.data()[i]).isPrint() ?
QChar(payload.data()[i]) : QChar('?');
}
sample += (payload.length() > 60) ? "..." : "";
return sample;
}

bool MythSocket::writeStringList(QStringList &list)
{
if (list.size() <= 0)
Expand Down Expand Up @@ -325,7 +337,8 @@ bool MythSocket::writeStringList(QStringList &list)
VERBOSE(VB_IMPORTANT, LOC +
"writeStringList: Error, socket went unconnected." +
QString("\n\t\t\tWe wrote %1 of %2 bytes with %3 errors")
.arg(written).arg(written+size).arg(errorcount));
.arg(written).arg(written+size).arg(errorcount) +
QString("\n\t\t\tstarts with: %1").arg(toSample(payload)));
return false;
}

Expand Down Expand Up @@ -355,7 +368,9 @@ bool MythSocket::writeStringList(QStringList &list)
{
VERBOSE(VB_GENERAL, LOC + "writeStringList: Error, " +
QString("No data written on writeBlock (%1 errors)")
.arg(errorcount));
.arg(errorcount) +
QString("\n\t\t\tstarts with: %1")
.arg(toSample(payload)));
return false;
}
usleep(1000);
Expand Down

0 comments on commit 519b692

Please sign in to comment.