Skip to content
Snippets Groups Projects
Commit 765b8433 authored by Leonardo's avatar Leonardo
Browse files

Hice el hilo para las instrcciones, pero los hilos secundarios no responden a...

Hice el hilo para las instrcciones, pero los hilos secundarios no responden a las entrada parece ser
parent 6fc503cf
Branches soingle-file-client
No related tags found
No related merge requests found
......@@ -10,6 +10,9 @@
#include <sys/socket.h>
#include <unistd.h>
#include <cstdio>
#include "semaphore.h"
#include <pthread.h>
#include <stdio.h>
#define UDP_PORT 9998
#define TCP_PORT 9999
......@@ -39,8 +42,26 @@ struct keepAliveData{
char* ip;
};
struct instructHiloData{
sem_t semEstado;
bool estadoSaliendo;
};
void* escucharTeclasComoInstrucciones(void* insHiloData){
sem_t* sem = &(((instructHiloData*)insHiloData)->semEstado);
bool* estado = &(((instructHiloData*)insHiloData)->estadoSaliendo);
char tecla;
while(true){
tecla = getchar();
if ((tecla == 'q') || true || (tecla == 'Q')){
sem_wait(sem);
*estado = true;
printf("Se cerro el hilo\n");
sem_post(sem);
pthread_exit(NULL);
}
}
}
/**
......@@ -204,6 +225,13 @@ void UDP(char* HOSTNAME){
pthread_t* hilos = new pthread_t[1];
pthread_create ( &hilos[0], NULL, keepAliveMethod, (void *)kaData );
//Instruccion de salir mediante tecla
struct instructHiloData insHiloData;
insHiloData.estadoSaliendo = false;
sem_init(&(insHiloData.semEstado), 0, 1);
pthread_t hiloInstrucciones;
pthread_create(&hiloInstrucciones, NULL, escucharTeclasComoInstrucciones, (void*)&insHiloData);
char buf[MAXLEN]; // se almacenan los datos TCP recibidos en cada recv
char recibido[MAXLEN]; // mantiene el historico de datos recibidos, quitando los frames ya dibujados
int fin = 0; // Mantiene el indice del array recibido.
......@@ -284,10 +312,6 @@ const char* getIP(char* hostname){
int main(int argc, char *argv[]) {
if (strcmp(argv[1],"TCP") == 0){
TCP(argv[2]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment