Question about conflicts while using accept() and timer
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Question about conflicts while using accept() and timer




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Question about conflicts while using accept() and timer  
Wang Tian News


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:01 PM

Hi,

I am writing a server program, I have to use accept() to get information fro
m client, at the same time i set a timer (using setitimer()) to do some peri
odical jobs(just some data update), but every time the timer function is inv
oked, the accept() will return with error. This always happens when the time
r is invoked the second time, no matter what interval I set to it. This stil
l happens when I put accept() and timer setup in two threads.

Anyone met this problem before?? Who can help me?
Thanks

Tian






[ Post a follow-up to this message ]



    Re: Question about conflicts while using accept() and timer  
David Schwartz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 some
quote:
> data update), but every time the timer function is invoked, the accept()
will return with
quote:
> error. This always happens when the timer is invoked the second time, no
matter what
quote:
> 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 ]



    Re: Question about conflicts while using accept() and timer  
David Schwartz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 some
quote:
> data update), but every time the timer function is invoked, the accept()
will return with
quote:
> error. This always happens when the timer is invoked the second time, no
matter what
quote:
> 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 ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:15 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register