mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:24:24 +02:00
fix threaded socket joins so that socket has timeout on blocking receive
This commit is contained in:
parent
200982dddc
commit
345ec8b938
3 changed files with 19 additions and 11 deletions
|
@ -44,9 +44,8 @@ const char EC2_WEST_MIXER[] = "54.241.92.53";
|
||||||
const int AUDIO_UDP_LISTEN_PORT = 55444;
|
const int AUDIO_UDP_LISTEN_PORT = 55444;
|
||||||
|
|
||||||
int starve_counter = 0;
|
int starve_counter = 0;
|
||||||
bool stopAudioReceiveThread = false;
|
|
||||||
|
|
||||||
StDev stdev;
|
StDev stdev;
|
||||||
|
bool stopAudioReceiveThread = false;
|
||||||
|
|
||||||
#define LOG_SAMPLE_DELAY 1
|
#define LOG_SAMPLE_DELAY 1
|
||||||
|
|
||||||
|
@ -263,6 +262,8 @@ void *receiveAudioViaUDP(void *args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -306,6 +307,7 @@ Audio::Audio(Oscilloscope * s)
|
||||||
Pa_StartStream(stream);
|
Pa_StartStream(stream);
|
||||||
if (paError != paNoError) goto error;
|
if (paError != paNoError) goto error;
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -420,6 +422,9 @@ void Audio::render(int screenWidth, int screenHeight)
|
||||||
*/
|
*/
|
||||||
bool Audio::terminate ()
|
bool Audio::terminate ()
|
||||||
{
|
{
|
||||||
|
stopAudioReceiveThread = true;
|
||||||
|
pthread_join(audioReceiveThread, NULL);
|
||||||
|
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
initialized = false;
|
initialized = false;
|
||||||
|
|
||||||
|
@ -428,14 +433,10 @@ bool Audio::terminate ()
|
||||||
|
|
||||||
paError = Pa_Terminate();
|
paError = Pa_Terminate();
|
||||||
if (paError != paNoError) goto error;
|
if (paError != paNoError) goto error;
|
||||||
|
|
||||||
delete audioData;
|
|
||||||
|
|
||||||
logFile.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stopAudioReceiveThread = true;
|
logFile.close();
|
||||||
pthread_join(audioReceiveThread, NULL);
|
delete audioData;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ const int DOMAINSERVER_PORT = 40102;
|
||||||
|
|
||||||
AgentList agentList;
|
AgentList agentList;
|
||||||
pthread_t networkReceiveThread;
|
pthread_t networkReceiveThread;
|
||||||
bool stopAgentDataReceiveThread = false;
|
bool stopNetworkReceiveThread = false;
|
||||||
|
|
||||||
// For testing, add milliseconds of delay for received UDP packets
|
// For testing, add milliseconds of delay for received UDP packets
|
||||||
int packetcount = 0;
|
int packetcount = 0;
|
||||||
|
@ -362,8 +362,9 @@ void terminate () {
|
||||||
//close(serial_fd);
|
//close(serial_fd);
|
||||||
|
|
||||||
audio.terminate();
|
audio.terminate();
|
||||||
stopAgentDataReceiveThread = true;
|
stopNetworkReceiveThread = true;
|
||||||
pthread_join(networkReceiveThread, NULL);
|
pthread_join(networkReceiveThread, NULL);
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -767,7 +768,7 @@ void *networkReceive(void *args)
|
||||||
ssize_t bytesReceived;
|
ssize_t bytesReceived;
|
||||||
char *incomingPacket = new char[MAX_PACKET_SIZE];
|
char *incomingPacket = new char[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
while (!stopAgentDataReceiveThread) {
|
while (!stopNetworkReceiveThread) {
|
||||||
if (agentList.getAgentSocket()->receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
if (agentList.getAgentSocket()->receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
||||||
packetcount++;
|
packetcount++;
|
||||||
bytescount += bytesReceived;
|
bytescount += bytesReceived;
|
||||||
|
|
|
@ -81,6 +81,12 @@ UDPSocket::UDPSocket(int listeningPort) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set timeout on socket recieve to 0.5 seconds
|
||||||
|
struct timeval tv;
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 500000;
|
||||||
|
setsockopt(handle, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv);
|
||||||
|
|
||||||
printf("Created UDP socket listening on port %d.\n", listeningPort);
|
printf("Created UDP socket listening on port %d.\n", listeningPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue