Unix Programming - How can I interrupt blocking accept() to get errno=EINTR

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > August 2006 > How can I interrupt blocking accept() to get errno=EINTR





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 How can I interrupt blocking accept() to get errno=EINTR
lazy.tramp@gmail.com

2006-08-29, 1:35 pm

I wonder how can I interrupt blocking accept() to get errno=EINTR. I
have tried SIGALRM but my program just terminated (I couldnt catch
EINTR).

thank you.

Maxim Yegorushkin

2006-08-29, 7:33 pm


lazy.tramp@gmail.com wrote:
> I wonder how can I interrupt blocking accept() to get errno=EINTR. I
> have tried SIGALRM but my program just terminated (I couldnt catch
> EINTR).


You send a signal. Don't forget to handle a signal by installing a
signal handler or ignoring the signal if possible.

lazy.tramp@gmail.com

2006-08-29, 7:33 pm

Thank you for reply. I tried to catch the signal but when I catch the
signal (SIGALRM) however, the
socket function accept() still blocking.


Maxim Yegorushkin wrote:
> lazy.tramp@gmail.com wrote:
>
> You send a signal. Don't forget to handle a signal by installing a
> signal handler or ignoring the signal if possible.


Rick Jones

2006-08-29, 7:33 pm

lazy.tramp@gmail.com wrote:
> Thank you for reply. I tried to catch the signal but when I catch
> the signal (SIGALRM) however, the socket function accept() still
> blocking.


IIRC some systems may restart an interupted system call for "slow"
system calls. You may be able to set flags when you enable the signal
handler to control that on your platform. In other cases it has been
possible in the signal hander to see which system call was being
interrupted and tell, upon return from the signal handler, whether or
not the system call should be restarted. Try delving deeper into the
manpages for signal (all versions) and also for sigaction, and siginfo
if your system has that one.

rick jones
--
denial, anger, bargaining, depression, acceptance, rebirth...
where do you want to be today?
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
David Schwartz

2006-08-30, 1:23 am


lazy.tramp@gmail.com wrote:
> I wonder how can I interrupt blocking accept() to get errno=EINTR. I
> have tried SIGALRM but my program just terminated (I couldnt catch
> EINTR).
>
> thank you.


If you have control over all of the code, why does it matter what
'accept' returns? Just create a flag to indicate that you want it to
stop accepting, set that flag, and then make a dummy connection (to
ensure 'accept' returns). When 'accept' returns, check the value of the
flag.

DS

Nils O. Selåsdal

2006-08-30, 1:23 am

lazy.tramp@gmail.com wrote:
> Thank you for reply. I tried to catch the signal but when I catch the
> signal (SIGALRM) however, the
> socket function accept() still blocking.


Use sigaction to install the handler, without setting
the SA_RESTART flag.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com