I can pretty much promise everything in the API works properly, since most of the internet depends on linux sockets.
However, I'll concurr it is not always easy to get it to work. I'm not sure exactly what your problem is, but I do see a potential design flaw.
I presume that is the server socket, since it's what you use with accept().
Code:
for(count = 0; count < fdmax; count++){
Why do this? fds 0-2 are stdin, stdout, and stderr. You should not be polling them, or polling fd's willy-nilly. You poll only the fd's which are actually part of one of your sets. [edit: actually I guess you aren't polling them...anyway]
Now, you do advance fdmax to include new sockets:
Code:
fdmax = connected_socket;
Chances are you could just count from sock up to fdmax, but I still think you need to maintain an array of open descriptors (possibly you could examine how the fd_set bit array works and get it from there). Your method of setting this number is also very sloppy:
Code:
if(select(fdmax+1, &read_fds, NULL, NULL, NULL) == -1){
That should be the actual number of readable sockets, not the number of the highest one+1. There is only one socket in read_fds initially, but you are telling select there are at least 4.
Of course, that maybe does not explain why the code isn't working; sloppiness is not complete condemnation
You could try a little more debugging:
Code:
fprintf(stderr,"read_fds: %ld\n",read_fds);
for(count = 0; count < fdmax; count++){
if(FD_ISSET(count,&read_fds) != 0){
fprintf(stderr,"\t-->%d\n",count);