I am doing serial port programming using XCODE 4. My read() calls are set to blocking mode so I use the select() function to block up to a certain time limit before I call read(). In order to get a little bit finer resolution than seconds, I use the tv_usec field to specify how long select should block before returning. The problem I am having is when I specify a microsecond value > 999,999 select immediately returns reporting error == 22 (EINVAL = Invalid argument), essentially saying the time out value is incorrect. I don't see any documentation anywhere stating the microsecond value has to be smaller than 1 second(1,000,000us). The variable is an int so it should be able to hold quite a large value. Is this a bug in select() or some undocumented behavior or am I missing something obvious(which happens quite often)?
....This works
tv.tv_sec = 0;
tv.tv_usec = 999999;
wait_result = select(file_descriptor + 1, &read_flags, NULL, NULL, &tv);
....This doesn't
tv.tv_sec = 0;
tv.tv_usec = 1000000;
wait_result = select(file_descriptor + 1, &read_flags, NULL, NULL, &tv);
....This works
tv.tv_sec = 0;
tv.tv_usec = 999999;
wait_result = select(file_descriptor + 1, &read_flags, NULL, NULL, &tv);
....This doesn't
tv.tv_sec = 0;
tv.tv_usec = 1000000;
wait_result = select(file_descriptor + 1, &read_flags, NULL, NULL, &tv);