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,21 +68,12 @@ void signalHandler(int signal) {
void readFromTCPSocket() { void readFromTCPSocket() {
ssize_t byteCount; ssize_t byteCount;
uint8_t buffer[1536]; uint8_t buffer[1536];
if (outgoing) { while (!exitProgram && (outgoing? (byteCount = tcpConnector.read(buffer, sizeof(buffer))) > 0 : (byteCount = tcpSocket.read(buffer, sizeof(buffer))) > 0)) {
while (!exitProgram && (byteCount = tcpConnector.read(buffer, sizeof(buffer))) > 0) {
for (ssize_t i=0; i<byteCount; i++) { for (ssize_t i=0; i<byteCount; i++) {
std::cout << std::hex << std::setfill('0') << std::setw(2) << (short) buffer[i] << " "; std::cout << std::hex << std::setfill('0') << std::setw(2) << (short) buffer[i] << " ";
} }
std::cout.flush(); 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();
}
}
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {