>But why does it removes the file descriptor from the fd_sets?
the point of select is to tell you which fds wouldn't block if you used some function on them. Removing the inactive fds leaves the active fds, which you can then read/write/send/recv on.
>the sentence is suppose to delete the connection in case that it's not responding, I've tested it as it was originally and it worked perfectly.
which line?
Code:
if((nbytes = recv(i, buf, sizeof(buf), 0)) <= 0) { /* this thing is what I'm worried of*/
if(nbytes == 0) {
close(i);
FD_CLR(i, &master);
printf("Conexion perdida\n");
}
else {
recievefile(&i);
}
I don't know what you're trying to do there.
>I also wanna know what do you think about using fork for handling the requests,
do you have a specific question?
> I think that the select won't handle the incomming connection if it is doing the function of recieve file, I mean, two people sending a file at the same time is not possible as the code is right now right?
If you want multiple connections with select, you'll have to rearrage your code a little bit, yes. Something like this:
Code:
while do socket stuff
set up fd_sets
call select
for each fd in fd_set
if listener
accept connection
else if file receive connection
recv chunk //only receive a chunk of the file at a time.
endif
endfor
endwhile