Skip to content

Commit

Permalink
reset ostream flags when done
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-zimoch authored and mdavidsaver committed Nov 19, 2021
1 parent 284de4f commit ec85ffc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/remote/abstractResponseHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ void ResponseHandler::handleResponse(osiSockAddr* responseFrom,
char ipAddrStr[24];
ipAddrToDottedIP(&responseFrom->ia, ipAddrStr, sizeof(ipAddrStr));

std::cerr<<"Message [0x"<<std::hex<<(int)command<<", v0x"<<std::hex
std::ios::fmtflags initialflags = std::cerr.flags();
std::cerr<<"Message [0x"<<std::hex<<(int)command<<", v0x"
<<int(version)<<"] received from "<<ipAddrStr<<" on "<<transport->getRemoteName()
<<" : "<<_description<<"\n"
<<HexDump(*payloadBuffer, payloadSize).limit(0xffff);
std::cerr.flags(initialflags);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/remoteClient/clientContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3000,8 +3000,10 @@ class ClientResponseHandler : public ResponseHandler {
if (command < 0 || command >= (int8)m_handlerTable.size())
{
if(IS_LOGGABLE(logLevelError)) {
std::ios::fmtflags initialflags = std::cerr.flags();
std::cerr<<"Invalid (or unsupported) command: "<<std::hex<<(int)(0xFF&command)<<"\n"
<<HexDump(*payloadBuffer, payloadSize).limit(256u);
std::cerr.flags(initialflags);
}
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/server/responseHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ void ServerResponseHandler::handleResponse(osiSockAddr* responseFrom,
"Invalid (or unsupported) command: %x.", (0xFF&command));

if(IS_LOGGABLE(logLevelError)) {
std::ios::fmtflags initialflags = std::cerr.flags();
std::cerr<<"Invalid (or unsupported) command: "<<std::hex<<(int)(0xFF&command)<<"\n"
<<HexDump(*payloadBuffer, payloadSize).limit(256u);
std::cerr.flags(initialflags);
}
return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/utils/hexDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ std::ostream& operator<<(std::ostream& strm, const HexDump& hex)
if(len%hex._perLine)
nlines++;

std::ios::fmtflags initialflags = strm.flags();
strm<<std::hex<<std::setfill('0');
for(size_t l=0; l<nlines; l++)
{
size_t start = l*hex._perLine;
strm<<"0x"<<std::hex<<std::setw(addrwidth)<<std::setfill('0')<<start;
strm<<"0x"<<std::setw(addrwidth)<<start;

// print hex chars
for(size_t col=0; col<hex._perLine; col++)
Expand All @@ -89,7 +91,7 @@ std::ostream& operator<<(std::ostream& strm, const HexDump& hex)
strm<<' ';
}
if(start+col < len) {
strm<<std::hex<<std::setw(2)<<std::setfill('0')<<unsigned(hex.buf[start+col]&0xff);
strm<<std::setw(2)<<unsigned(hex.buf[start+col]&0xff);
} else {
strm<<" ";
}
Expand All @@ -113,6 +115,7 @@ std::ostream& operator<<(std::ostream& strm, const HexDump& hex)

strm<<'\n';
}
strm.flags(initialflags);

return strm;
}
Expand Down

0 comments on commit ec85ffc

Please sign in to comment.