tools/hexnet: start implementing console input
parent
209d0828b4
commit
48f8a7dcf2
|
@ -84,6 +84,16 @@ void signalHandler(int signal) {
|
|||
std::exit(signal);
|
||||
}
|
||||
|
||||
void readFromConsole(){
|
||||
while(!exitProgram){
|
||||
char * test = new char[420];
|
||||
consoleMutex.lock();
|
||||
std::cout << "> ";
|
||||
std::cin.read(test, 1);
|
||||
consoleMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void readFromTCPSocket(sockpp::tcp_socket* socket, int64_t mtu) {
|
||||
ssize_t numBytes;
|
||||
uint8_t buffer[mtu];
|
||||
|
@ -91,9 +101,11 @@ void readFromTCPSocket(sockpp::tcp_socket* socket, int64_t mtu) {
|
|||
while (!exitProgram && (numBytes = socket->read(buffer, sizeof(buffer))) > 0) {
|
||||
tcpSocketMutex.unlock();
|
||||
consoleMutex.lock();
|
||||
std::cout << "\n";
|
||||
for (ssize_t i=0; i<numBytes; i++) {
|
||||
std::cout << std::hex << std::setfill('0') << std::setw(2) << (short) buffer[i];
|
||||
}
|
||||
std::cout << "\n";
|
||||
std::cout.flush();
|
||||
consoleMutex.unlock();
|
||||
tcpSocketMutex.lock();
|
||||
|
@ -314,6 +326,9 @@ int main(int argc, char* argv[]){
|
|||
}
|
||||
|
||||
std::thread threadReadFromTCP = std::thread(readFromTCPSocket, tcpSocket, mtu);
|
||||
std::thread threadReadFromConsole = std::thread(readFromConsole);
|
||||
|
||||
threadReadFromConsole.join();
|
||||
threadReadFromTCP.join();
|
||||
|
||||
delete tcpSocket;
|
||||
|
|
Loading…
Reference in New Issue