From 73ebfb898f90ceed9dcb16fbf3fbe60b3f42c2bd Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 20 Sep 2014 15:33:11 +0200 Subject: Make closing MainWindow shut down the entire program (aka. fix hanging threads...). --- src/inputstreamer.cc | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'src/inputstreamer.cc') diff --git a/src/inputstreamer.cc b/src/inputstreamer.cc index 04edc7b..deffa71 100644 --- a/src/inputstreamer.cc +++ b/src/inputstreamer.cc @@ -67,6 +67,11 @@ InputStreamer::InputStreamer(QHostAddress addr, quint16 port) running = true; start(); } +int interrupted; + +void handle_int(int num) { + interrupted = 1; +} InputStreamer::~InputStreamer() { @@ -93,28 +98,33 @@ void InputStreamer::run() char packet[64*1024]; while(running) { - /* - if(!socket.hasPendingDatagrams()) { - qApp->processEvents(); - usleep(2000); // sleep 2ms - continue; - } - qint64 packetsize = - socket.readDatagram(packet, (quint64)sizeof(packet), 0, 0); - if(packetsize < 1) { - continue; + ssize_t packetsize; + + { + int fd = sock; + fd_set fds; + struct timeval timeout; + + timeout.tv_sec = 0; + timeout.tv_usec = 1000; + FD_ZERO(&fds); + FD_SET(fd, &fds); + if(select(fd + 1, &fds, NULL, NULL, &timeout) > 0) { + packetsize = recv(sock, (char*)packet, sizeof(packet), 0); + } else { + // timeout + continue; + } } - */ - ssize_t packetsize = recv(sock, (char*)packet, sizeof(packet), 0); if(packetsize == -1) { perror("recv()"); - usleep(100); // sleep 2ms + usleep(1000); continue; } if(packetsize == 0) { - usleep(100); // sleep 2ms + usleep(1000); continue; } @@ -149,6 +159,8 @@ void InputStreamer::run() } } + printf("done\n"); + status = lrtp_destroy_profile(lrtp, CSRC_V); if(status != LRTP_OK) printf("O:lrtp_destroy_profile (v) err: %d\n", status); -- cgit v1.2.3