Commit ee4f00aa authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Broadcast in case of socket closing.

parent cd3cff30
......@@ -146,16 +146,18 @@ int PrrtSocket_interrupt(PrrtSocket *sock_ptr) {
void **res = NULL;
if (sock_ptr->sendThread != 0) {
pthread_mutex_lock(&sock_ptr->outQueueFilledMutex);
pthread_cond_signal(&sock_ptr->outQueueFilledCv);
pthread_cond_broadcast(&sock_ptr->outQueueFilledCv);
pthread_mutex_unlock(&sock_ptr->outQueueFilledMutex);
pthread_join(sock_ptr->sendThread, res);
sock_ptr->sendThread = 0;
}
printf("%d\n", sock_ptr->receiveDataThread);
if (sock_ptr->receiveDataThread != 0) {
debug("Shutting down receive data thread.");
pthread_mutex_lock(&sock_ptr->inQueueFilledMutex);
pthread_cond_signal(&sock_ptr->inQueueFilledCv);
pthread_cond_broadcast(&sock_ptr->inQueueFilledCv);
pthread_mutex_unlock(&sock_ptr->inQueueFilledMutex);
pthread_cancel(sock_ptr->receiveDataThread);
......
......@@ -5,12 +5,12 @@
#include "util/dbg.h"
#include "prrt/socket.h"
PrrtSocket sock;
static volatile int keepRunning = 1;
PrrtSocket* sock = NULL;
static volatile int keepRunning = true;
void intHandler(int dummy) {
keepRunning = 0;
PrrtSocket_interrupt(&sock);
keepRunning = false;
PrrtSocket_interrupt(sock);
}
int main(int argc, char* const argv[]) {
......@@ -25,18 +25,22 @@ int main(int argc, char* const argv[]) {
printf("PRRT - RECEIVER\n");
PrrtSocket* sock = PrrtSocket_create(port, false);
sock = PrrtSocket_create(port, false);
check(sock != NULL, "Could not create socket.");
printf("SOCK: %d\n", sock->receiveDataThread);
int i = 1;
while(keepRunning) {
unsigned char buffer[MAX_PAYLOAD_LENGTH];
debug("about to recv");
int n = PrrtSocket_recv(sock, buffer);
debug("Done receiving");
if(n < 0 ) {
printf("n<0\n");
continue;
}
buffer[n] = '\0';
//printf("[B (n: %3d, i: %3d)] %s", n, i, buffer);
printf("[B (n: %3d, i: %3d)] %s", n, i, buffer);
i++;
usleep(1);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment