# HG changeset patch # User Giulio Moro # Date 1440426969 -3600 # Node ID 6c8fb6f07b47d7db3336f66ff097ceafd0986690 # Parent 719119fb29055c7d947f89e817d414a089250b2f Prevented from hanging upon exit. The issue is with the waitForSocketTime value. See issue#1381 diff -r 719119fb2905 -r 6c8fb6f07b47 core/ReceiveAudioThread.cpp --- 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){