tools/hexnet: Reduce redundant code

Soda
BodgeMaster 2022-10-21 23:00:38 +02:00
parent f681c54c82
commit 89cfb9d850
1 changed files with 4 additions and 13 deletions

View File

@ -68,20 +68,11 @@ void signalHandler(int signal) {
void readFromTCPSocket() {
ssize_t byteCount;
uint8_t buffer[1536];
if (outgoing) {
while (!exitProgram && (byteCount = tcpConnector.read(buffer, sizeof(buffer))) > 0) {
for (ssize_t i=0; i<byteCount; i++) {
std::cout << std::hex << std::setfill('0') << std::setw(2) << (short) buffer[i] << " ";
}
std::cout.flush();
}
} else {
while (!exitProgram && (byteCount = tcpSocket.read(buffer, sizeof(buffer))) > 0) {
for (ssize_t i=0; i<byteCount; i++) {
std::cout << std::hex << std::setfill('0') << std::setw(2) << (short) buffer[i] << " ";
}
std::cout.flush();
while (!exitProgram && (outgoing? (byteCount = tcpConnector.read(buffer, sizeof(buffer))) > 0 : (byteCount = tcpSocket.read(buffer, sizeof(buffer))) > 0)) {
for (ssize_t i=0; i<byteCount; i++) {
std::cout << std::hex << std::setfill('0') << std::setw(2) << (short) buffer[i] << " ";
}
std::cout.flush();
}
}