Add reading from pipe and sending to stream for ClientSender

This commit is contained in:
flyingscorpio@clevo 2022-10-21 16:42:05 +02:00
parent dd7beccdf8
commit 8841e351d0

View file

@ -168,6 +168,20 @@ void *ClientListener(void *arg) {
/* Thread, sends messages to the client */ /* Thread, sends messages to the client */
void *ClientSender(void *arg) { void *ClientSender(void *arg) {
struct client_details details = *((struct client_details*) arg); struct client_details details = *((struct client_details*) arg);
char buf[BUF_LEN];
int n = 0;
while (1) {
while ((n = read(details.pipe[0], buf, BUF_LEN)) > 0) {
write(details.sockid, buf, n);
}
if (n < 0) {
fprintf(stderr, "ERROR: read\n");
sprintf(buf, "ERROR: read\n");
write(details.sockid, buf, strlen(buf + 1));
break;
}
}
pthread_exit(0); pthread_exit(0);
} }