Stream dumpHex output to an output stream.
Also output debug directly to stderr to avoid std::cerr re-direction. Change-Id: Ib2a0eaa3514ef88d7fe8d8fbb3706925aabf3346
This commit is contained in:
parent
024e786e85
commit
29b92444b1
2 changed files with 21 additions and 14 deletions
|
@ -138,30 +138,37 @@ void SocketDisposition::execute()
|
|||
|
||||
namespace {
|
||||
|
||||
void dump_hex (const char *legend, const char *prefix, std::vector<char> buffer)
|
||||
void dump_hex (std::ostream &os, const char *legend, const char *prefix, std::vector<char> buffer)
|
||||
{
|
||||
unsigned int i, j;
|
||||
fprintf (stderr, "%s", legend);
|
||||
char scratch[64];
|
||||
|
||||
os << legend;
|
||||
for (j = 0; j < buffer.size() + 15; j += 16)
|
||||
{
|
||||
fprintf (stderr, "%s0x%.4x ", prefix, j);
|
||||
sprintf (scratch, "%s0x%.4x ", prefix, j);
|
||||
os << scratch;
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if ((j + i) < buffer.size())
|
||||
fprintf (stderr, "%.2x ", (unsigned char)buffer[j+i]);
|
||||
sprintf (scratch, "%.2x ", (unsigned char)buffer[j+i]);
|
||||
else
|
||||
fprintf (stderr, " ");
|
||||
sprintf (scratch, " ");
|
||||
os << scratch;
|
||||
if (i == 8)
|
||||
fprintf (stderr, " ");
|
||||
os << " ";
|
||||
}
|
||||
fprintf (stderr, " | ");
|
||||
os << " | ";
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if ((j + i) < buffer.size() && ::isprint(buffer[j+i]))
|
||||
fprintf (stderr, "%c", buffer[j+i]);
|
||||
sprintf (scratch, "%c", buffer[j+i]);
|
||||
else
|
||||
fprintf (stderr, ".");
|
||||
fprintf (stderr, "\n");
|
||||
sprintf (scratch, ".");
|
||||
os << scratch;
|
||||
}
|
||||
os << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +179,7 @@ void WebSocketHandler::dumpState(std::ostream& os)
|
|||
os << (_shuttingDown ? "shutd " : "alive ")
|
||||
<< std::setw(5) << 1.0*_pingTimeUs/1000 << "ms ";
|
||||
if (_wsPayload.size() > 0)
|
||||
dump_hex("\t\tws queued payload:\n", "\t\t", _wsPayload);
|
||||
dump_hex(os, "\t\tws queued payload:\n", "\t\t", _wsPayload);
|
||||
}
|
||||
|
||||
void StreamSocket::dumpState(std::ostream& os)
|
||||
|
@ -183,9 +190,9 @@ void StreamSocket::dumpState(std::ostream& os)
|
|||
<< _inBuffer.size() << "\t" << _outBuffer.size() << "\t";
|
||||
_socketHandler->dumpState(os);
|
||||
if (_inBuffer.size() > 0)
|
||||
dump_hex("\t\tinBuffer:\n", "\t\t", _inBuffer);
|
||||
dump_hex(os, "\t\tinBuffer:\n", "\t\t", _inBuffer);
|
||||
if (_outBuffer.size() > 0)
|
||||
dump_hex("\t\toutBuffer:\n", "\t\t", _inBuffer);
|
||||
dump_hex(os, "\t\toutBuffer:\n", "\t\t", _inBuffer);
|
||||
}
|
||||
|
||||
void StreamSocket::send(Poco::Net::HTTPResponse& response)
|
||||
|
|
|
@ -2647,7 +2647,7 @@ void dump_state()
|
|||
srv.dumpState(oss);
|
||||
|
||||
const std::string msg = oss.str();
|
||||
std::cerr << msg << std::endl;
|
||||
fprintf(stderr, "%s\n", msg.c_str());
|
||||
LOG_TRC(msg);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue