|
Home > Archive > Unix Programming > March 2005 > ualarm() Interrupts select()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ualarm() Interrupts select()
|
|
| William 2005-03-27, 5:54 pm |
| For the following code snippet:
for ( ;; ) {
numFDInSet = select( fdmax+1, &readfds, NULL, NULL, &tv );
// ...
signal( SIGALRM, alarm_handler );
// ...
ualarm( waitPeriod * 1000, 0 );
}
The problem being if the alarm goes off when select() is scanning the
FD_SET, select is interruped with the following error:
Error on select(): Interrupted system call
Ideally, when the alarm goes off, I would still want select() to continue
scanning the FD_SET and the "main loop" to continue ( select() is inside
the main loop ). Any suggestions to achieving achieving this is
appreicated.
| |
|
| William wrote:
> For the following code snippet:
>
> for ( ;; ) {
> numFDInSet = select( fdmax+1, &readfds, NULL, NULL, &tv );
>
> // ...
>
> signal( SIGALRM, alarm_handler );
>
> // ...
>
> ualarm( waitPeriod * 1000, 0 );
> }
>
> The problem being if the alarm goes off when select() is scanning the
> FD_SET, select is interruped with the following error:
>
> Error on select(): Interrupted system call
>
This is normal behaviour. It allows the select() loop to
react on the signals that occured while inside the system call.
( in some cases that is what you want )
If you don't want it: just do something like:
while (1) {
... fd_set(), timeval = ... etc here. ...
rc = select(...);
if (rc == -1) switch(errno) {
case EINTR: continue;
default: printf( ...) ;
...
}
... loop stuff ...
}
To complicate things even more, there is a nasty SYSV<->BSD -difference
lurking here. GIYF
HTH,
AvK
|
|
|
|
|