"Interrupted system call" at "low level" - system calls

"Interrupted system call" at "low level" - system calls

Post by Jürg » Tue, 05 Nov 2002 19:46:21



Hi all,

I've read many emails in several groups and learned that interrupts
can interrupt low level system calls.
But I could not find out what low level system calls are.

Is there anybody who can help me?

Jrgen

 
 
 

"Interrupted system call" at "low level" - system calls

Post by Karl Heye » Wed, 06 Nov 2002 09:03:55



> Hi all,

> I've read many emails in several groups and learned that interrupts
> can interrupt low level system calls.
> But I could not find out what low level system calls are.

It's the ones provided by the kernel, and nicely wrapped up in glibc.
Look in section 2 of the man pages, calls like read, write, send,
select etc.  These calls can block or spend a significant amount of
time and can be interrupted.  Calls like kill don't because they
don't block per se.

As an example, say you wanted to use the write call, writing 4k of
data. An interrupt could happen before the write begins and cause
a return code of -1 (errno=EINTR) or part of the way through
returning say 2100.

karl.

 
 
 

"Interrupted system call" at "low level" - system calls

Post by Jürg » Fri, 15 Nov 2002 19:25:16




> > Hi all,

> > I've read many emails in several groups and learned that interrupts
> > can interrupt low level system calls.
> > But I could not find out what low level system calls are.

> It's the ones provided by the kernel, and nicely wrapped up in glibc.
> Look in section 2 of the man pages, calls like read, write, send,
> select etc.  These calls can block or spend a significant amount of
> time and can be interrupted.  Calls like kill don't because they
> don't block per se.

> As an example, say you wanted to use the write call, writing 4k of
> data. An interrupt could happen before the write begins and cause
> a return code of -1 (errno=EINTR) or part of the way through
> returning say 2100.

What do I have to do when a write-call returns a number which is not
exact the number of bytes as I wanted to send (like your example).
Have I to send the rest of the bytes with a new write-call?
Ok this would be no problem, but then two datastrings are made of one.
The same thing happens if the read-call is interrupted!
My applikation doesn't know how many bytes are sent so it gets two
datastrings but only one was sent!
How can I handle these problems?
 
 
 

"Interrupted system call" at "low level" - system calls

Post by Karl Heye » Fri, 15 Nov 2002 22:00:48



>> As an example, say you wanted to use the write call, writing 4k of
>> data. An interrupt could happen before the write begins and cause
>> a return code of -1 (errno=EINTR) or part of the way through
>> returning say 2100.

> What do I have to do when a write-call returns a number which is not
> exact the number of bytes as I wanted to send (like your example).
> Have I to send the rest of the bytes with a new write-call?

typically yes, but there maybe non-blocking file descriptors (like
sockets) which will mean a busy loop which you don't want.

Quote:> Ok this would be no problem, but then two datastrings are made of

one.

possibly, while you may issue two write calls of say 2k each,
invariably those get split upto into packets for transmission MTU
being 1500 say means like 1400odd bytes first then 600 next, but
if a second write has occured before the second packet is sent then
it can be more the 600 bytes.

Quote:> The same thing happens if the read-call is interrupted!

yes.

Quote:> My applikation doesn't know how many bytes are sent so it gets two
> datastrings but only one was sent!
> How can I handle these problems?

You won't receive more than is sent, but you have to determine the
syntax of the reads. It's a parsing problem. It's possible that with
2 data strings, you'll get

read - partial datastring1
read - rest of datastring1 and bit of datastring2
read - rest of datastring2

karl.

 
 
 

"Interrupted system call" at "low level" - system calls

Post by Jürg » Sat, 16 Nov 2002 22:07:59




> >> As an example, say you wanted to use the write call, writing 4k of
> >> data. An interrupt could happen before the write begins and cause
> >> a return code of -1 (errno=EINTR) or part of the way through
> >> returning say 2100.

> > What do I have to do when a write-call returns a number which is not
> > exact the number of bytes as I wanted to send (like your example).
> > Have I to send the rest of the bytes with a new write-call?

> typically yes, but there maybe non-blocking file descriptors (like
> sockets) which will mean a busy loop which you don't want.

> > Ok this would be no problem, but then two datastrings are made of
> one.

> possibly, while you may issue two write calls of say 2k each,
> invariably those get split upto into packets for transmission MTU
> being 1500 say means like 1400odd bytes first then 600 next, but
> if a second write has occured before the second packet is sent then
> it can be more the 600 bytes.

Is it possible that a write or read is interrupted during execution
although the whole data could be send in one packet?
For example I wanted to send or read 500 bytes and MTU is 1500.

Quote:> > My applikation doesn't know how many bytes are sent so it gets two
> > datastrings but only one was sent!
> > How can I handle these problems?

> You won't receive more than is sent, but you have to determine the
> syntax of the reads. It's a parsing problem. It's possible that with
> 2 data strings, you'll get

> read - partial datastring1
> read - rest of datastring1 and bit of datastring2
> read - rest of datastring2

How can I get out of these three datastrings the two correct
datastrings?

Jrgen

 
 
 

"Interrupted system call" at "low level" - system calls

Post by Karl Heye » Sun, 17 Nov 2002 23:27:41



> Is it possible that a write or read is interrupted during execution
> although the whole data could be send in one packet?

yes, if a signal came in.  A read may return a short read for other
reasons, like not enough data.

Quote:>> You won't receive more than is sent, but you have to determine the
>> syntax of the reads. It's a parsing problem. It's possible that with
>> 2 data strings, you'll get

>> read - partial datastring1
>> read - rest of datastring1 and bit of datastring2
>> read - rest of datastring2
> How can I get out of these three datastrings the two correct
> datastrings?

Well thats a problem of parsing, ie do you know the length of the
strings you want, is there some magic numbers, is there a separator.

karl.