changeset 127:6c8fb6f07b47 scope-refactoring

Prevented from hanging upon exit. The issue is with the waitForSocketTime value. See issue#1381
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 24 Aug 2015 15:36:09 +0100
parents 719119fb2905
children 2696a7f00053
files core/ReceiveAudioThread.cpp
diffstat 1 files changed, 4 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/core/ReceiveAudioThread.cpp	Mon Aug 24 15:25:34 2015 +0100
+++ b/core/ReceiveAudioThread.cpp	Mon Aug 24 15:36:09 2015 +0100
@@ -58,11 +58,10 @@
         return 0;
     if(writePointer<0)
         return 0;
-    if(socket.waitUntilReady(true, waitForSocketTime)){ // waitForSocketTime could have been set to -1 (wait forever),
-                                                        // but it would have made it more difficult for the thread to be killed
+    if(socket.waitUntilReady(true, waitForSocketTime)){// TODO: if waitForSocketTime here is >>5, the
+    	// destructor (always or sometimes) never actually gets called, despite run() returns ...see issue #1381
         pushPayload(writePointer); //backup headerLength samples. This could be skipped if writePointer==0
         //read header+payload
-//JUCE        int numBytes=socket.read(buffer+writePointer, bytesToRead,1);
         int numBytes=socket.read(buffer+writePointer, bytesToRead, true); //read without waiting.
             //TODO: (if using variable-length payload) validate the actual numBytes read against the size declared in the header
         if(numBytes<0){
@@ -108,14 +107,14 @@
 #else
 ReceiveAudioThread::ReceiveAudioThread() :
 #endif /* JUCE */
-	socket(NULL),
+	socket(0),
     listening(false),
     bufferReady(false),
     buffer(NULL),
     stackBuffer(NULL),
     bufferLength(0),
     lastValidPointer(0),
-    waitForSocketTime(100),
+    waitForSocketTime(5),
 #ifdef JUCE
     threadPriority(5)
 #else
@@ -126,15 +125,12 @@
 #ifdef JUCE
 	stopThread(1000);
 #else
-	printf("inside the destructor\n");
 	while(threadRunning){
-		printf("while in the destructor\n");
 		usleep(sleepTime*2);	//wait for thread to stop
 		std::cout<< "Waiting for receiveAudioTask to stop" << std::endl;
 	}
 #endif /* JUCE */
 	//TODO: check if thread stopped, otherwise kill it before dealloc
-	printf("dealloc\n");
     dealloc();
 }
 void ReceiveAudioThread::init(int aPort, int aSamplesPerBlock, int aChannel){