Code:
if(pipe(client1r)<0){
perror("pipe");
}
if(pipe(client2r)<0){
perror("pipe");
}
if(pipe(client3r)){
perror("pipe");
}
listen(sock,5);
while(1){
FD_ZERO(&fds);
FD_SET(client1r[0],&fds);
FD_SET(client2r[0],&fds);
FD_SET(client3r[0],&fds);
FD_SET(sock,&fds);
a=select(256,&fds,NULL,NULL,NULL);
if(a>0){
c=0;
if(FD_ISSET(client1r[0],&fds)){
write(1,"test",12);
}
if(FD_ISSET(client3r[0],&fds)){
write(1,"test",12);
}
if(FD_ISSET(client2r[0],&fds)){
write(1,"You Win",7);
}
if(FD_ISSET(sock,&fds)){
fd_client = accept(sock,0,0);
if(fd_client == -1){
perror("accept");
}else{
(*numlogin)=(*numlogin)+1;
fill=fork();
switch(fill){
case 0:
if((*numlogin)==2){
close(client2r[0]);
Client(fd_client,logins,shmid1,shmid2,shmid3,client2r[1]);
}
if((*numlogin)==1){
close(client1r[0]);
Client(fd_client,logins,shmid1,shmid2,shmid3,client1r[1]);
}
if((*numlogin)==3){
close(client3r[0]);
Client(fd_client,logins,shmid1,shmid2,shmid3,client3r[1]);
}
break;
case -1:
write(1,"Error al fork\n",14);
break;
default:
close(client1r[1]);
close(client2r[1]);
close(client3r[1]);
close(fd_client); //No ho necessita
break; //PARE