Hi All,
I have a scenario like this
Function 1
{
Send a message
Wait for the reply for that message in a while(1) loop
}
Function 2
{
Processes requests and replies.
I have a code snippet like this
while(1)
{
while((n = read(connection->sock, buf, len)) < 0 && errno ==
EINTR);
if (n>0)
return n;
if(n==0)
close the connection
if(errno==EINTR)
retry the read call
}
In one of the scenario I receive SIGTERM, and code switched to the
signal handler. From the
signal handler I will do a siglong jump and do some celan up
processing.
If I receive the signal when middle of the read doing some thing,
after signal handler return. The read function trying to read some
thing on the socket and got hung there.Is it because, after returnig
from the signal handler, I lost the context to previous read, and the
other guy continuously looking for the reply for this message. So the
read() got the garbage after return from the signal handler
Some sample log
---------------
Sent the message 0x307 looking for reply
Entering Readit before while(1) of sock read()with len 4000<---signal
hit
TADI:Iam in handle_arbot_sig and the signal mask before calling
siglongjmp:
TADI: abortsig with signo 15 sig_flag 1
Entering Readit before while(1) of sock read()
sock read() n> 0 cas and returning 48 bytese
Entering Readit before while(1) of sock read()
<Got hung here>
If I receive a signal, not in the middle of the read everyting I will
get a reply for the message which I sent.
What could be the possible solution.
This what I thought, set a global flag in the signal handler, check
that flag in the Function 2 and return -1 from there, this will make
the thread 1 guy to take appropriate action and come out of the while
loop.
I couldn't understad why the read is hung after return from the signal
handler,is it because of I am siglongjumping in the signal handler,
After return to the read in Function 2, I lost the previous read
context.
Looking for suggestions.
Thanks
-Tadi
|
|
0
|
|
|
|
Reply
|
sudhakar
|
11/19/2004 11:12:30 AM |
|
Tadi <sudhakar.tadi@gmail.com> wrote:
> I have a scenario like this
> Function 1
> {
> Send a message
> Wait for the reply for that message in a while(1) loop
> }
> Function 2
> {
> Processes requests and replies.
> I have a code snippet like this
> while(1)
> {
> while((n = read(connection->sock, buf, len)) < 0 && errno ==
> EINTR);
> if (n>0)
> return n;
> if(n==0)
> close the connection
> if(errno==EINTR)
> retry the read call
How is this supposed to happen? You already checked errno within the
loop where you are reading. And you are supposed to check errno only
when the call returned -1, otherwise the value stored in errno does
not have any significance and shouldn't be evaluated.
> }
> In one of the scenario I receive SIGTERM, and code switched to the
> signal handler. From the
> signal handler I will do a siglong jump and do some celan up
> processing.
Why a longjmp()? Sounds rather dangerous unless you know extremely
well what you're doing... And how do you want to return from the
signal handler back to the function that does the reading/writing
after a longjmp() call?
> If I receive the signal when middle of the read doing some thing,
A read() call is interrupted by a signal only before any data are
read, never while the read is already in progress. But I don't
know if you are aware that read() can return less bytes than you
are waiting for. If you are sure that more data are going to come
you have to call read() again. The same holds for write(), so
always check how much got read or written and, if reasonable, call
the function again for the rest of the data.
> after signal handler return. The read function trying to read some
> thing on the socket and got hung there.Is it because, after returnig
> from the signal handler, I lost the context to previous read, and the
> other guy continuously looking for the reply for this message. So the
> read() got the garbage after return from the signal handler
Sorry, but I am at a loss to understand what you're writing here.
What's "the context to previous read"?
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
|
|
0
|
|
|
|
Reply
|
Jens
|
11/19/2004 1:03:18 PM
|
|
|
1 Replies
744 Views
(page loaded in 0.026 seconds)
Similiar Articles: Interrupted system calls (socket read) , EINTR and SIGTERM - comp ...Hi All, I have a scenario like this Function 1 { Send a message Wait for the reply for that message in a while(1) loop } F... "Interrupted system call", read and socket - comp.unix.programmer ...Interrupted system calls (socket read) , EINTR and SIGTERM - comp ... Hi All, I have a scenario like this Function 1 { Send a message Wait for the reply for that message ... write system call - comp.lang.asm.x86Interrupted system calls (socket read) , EINTR and SIGTERM - comp ... Can I catch the EINTR signal and how can I repeat concerned calls such as write, read or ... ... socket lock in multithred programming - comp.unix.programmer ...Interrupted system calls (socket read) , EINTR and SIGTERM - comp ... Interrupted system calls (socket read) , EINTR and SIGTERM programming.itags.org ... read() call by ... Read carry flag - comp.lang.asm.x86Interrupted system calls (socket read) , EINTR and SIGTERM - comp ... I have a code snippet like this while(1) { while((n = read(connection->sock ... write to socket broken pipe (32) - comp.unix.programmerEINTR means the call was interrupted by a signal. ... Your code seems fine. EINTR means the call was ... ... You cannot read data from a socket or pipe until ... Interrupted system calls (socket read) , EINTR and SIGTERMprogramming.itags.org: Unix & Linux question: Interrupted system calls (socket read) , EINTR and SIGTERM, created at:Wed, 30 Apr 2008 10:34:00 GMT with 2,249 bytes ... Interrupted system calls (socket read) , EINTR and SIGTERM - comp ...Hi All, I have a scenario like this Function 1 { Send a message Wait for the reply for that message in a while(1) loop } F... 7/23/2012 1:49:53 PM
|