select command
I have a doubt in select command,
select program: highsock is an global variable while(1) { FD_ZERO (&socks); FD_SET (highsock, socks); readsocks = select(highsock+1, &socks, 0, 0, &timeout); if (readsocks < 0) { perror("select"); exit(EXIT_FAILURE); } if (readsocks == 0) { /* Nothing ready to read, just show that we're alive */ printf("."); fflush(stdout); } else read_socks(readsocks); } void read_socks(int readsocks) { int listnum; if (FD_ISSET(highsock,&socks)) handle_new_connection(); else perror("No data available :%d\n", readsocks); } In our case selects returns with total number of socket descriptors as 38 and also while checking with FD_ISSET it gets failed with error as No data available :38 My question is 1. Whether select can return such more number of file descriptors ? 2. How this type of errors can be handled to avoid error? |
I don't see enough data here to help you out. Where are socks and highsock declared? Where is highsock initialized? Where is the while loop running? Is socks a global variable? Else, how does read_socks fit into the scope?
A bigger code listing may be in order. I've reposted it below to clarify indentations & such in your code. Quote:
|
If you have 38 file descriptors, then those are 0 .. 37 - there is no '38'.
|
I think you need to change your FD_ISSET call to be FD_ISSET(readsocks,&socks);
Am I right? |
Pokemaster,
I have reedited the code once again and posted in the same way. Can you now provide us the answer for this? |
I'm making a few assumptions here, and doing the best I can. Here is a full code listing, one that actually works all on its own. Open two terminal windows in the same directory. Run
Code:
mkfifo tmpfile Code:
echo > tmpfile The problem with your post is that you have given us the teeniest window into your program and, to be honest, I cannot see where the bug lies (especially since I cannot compile what you've given us). Next time, post all the related code so we can help. If you cannot post it all because this is schoolwork, then go ask your teacher. If it is work related and covered under an NDA, hire a consultant to help you out; go ask an expert who will also sign an NDA. Don't ask in a public forum. If nothing is holding you back from posting all the code, then post it all. Here's a working select program, give it a try as illustrated. Code:
#include <sys/time.h> |
All times are GMT -5. The time now is 07:12 AM. |