01-23-04 10:01 PM
quote:
> "Wang Tian News" <wangtian@cs.unc.edu> wrote in message news:3fcb7b54
> $1_2@news.unc.edu...
quote:
> I am writing a server program, I have to use accept() to get information
from client,quote:
> at the same time i set a timer (using setitimer()) to do some periodical
jobs(just somequote:
> data update), but every time the timer function is invoked, the accept()
will return withquote:
> error. This always happens when the timer is invoked the second time, no
matter whatquote:
> interval I set to it. This still happens when I put accept() and timer
setup in two threads.
When you use 'setitimer', it's supposed to interrupt a blocking
function. I'm not sure why this is a problem for you. When 'accept' returns
with an error, just do the periodic jobs and call 'accept' again.
If you're going to use threads, don't use 'setitimer' since there's
nothing to interrupt. If you need to delay, just use 'nanosleep', 'usleep',
'select', or whatever makes sense on your platform. Though a bit ugly,
'select(0, NULL, NULL,NULL, &tv);' works on every pthreads platform I know
of.
DS
[ Post a follow-up to this message ]
|