From: Steven Woody on
Hi,

I am working on unix domain sockets. In the sockets, we transfer data
with a specific structure. Will a signal interrupt my read(2) when it
get part of the data which already in kernel's buffer? If a reading
can be interrupted when I got part of bytes of the whole structure,
restart is not easy.

Thanks.
From: Barry Margolin on
In article
<f7b3555b-c83f-4c0d-9f22-d7433c10eb11(a)z32g2000prh.googlegroups.com>,
Steven Woody <narkewoody(a)gmail.com> wrote:

> Hi,
>
> I am working on unix domain sockets. In the sockets, we transfer data
> with a specific structure. Will a signal interrupt my read(2) when it
> get part of the data which already in kernel's buffer? If a reading
> can be interrupted when I got part of bytes of the whole structure,
> restart is not easy.

You have to write your program to handle getting part of the structure,
because nothing guarantees that read() will read the whole structure,
even if you don't get a signal.

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Chris Friesen on
Steven Woody wrote:
> Hi,
>
> I am working on unix domain sockets. In the sockets, we transfer data
> with a specific structure. Will a signal interrupt my read(2) when it
> get part of the data which already in kernel's buffer? If a reading
> can be interrupted when I got part of bytes of the whole structure,
> restart is not easy.

According to the spec, read() on a socket is the same as a recv() with
no flags, and for a SOCK_DGRAM socket the entire message will be read in
a single operation. This implies that either you get an EINTR and no
data, or else the operation is restarted automatically by the system.

Whether or not it will be restarted by default depends on
implementation. To force an automatic restart you can specify
SA_RESTART for all your signal handlers.

Chris
From: Steven Woody on
On Jun 28, 12:56 pm, Chris Friesen <cbf...(a)mail.usask.ca> wrote:
> Steven Woody wrote:
> > Hi,
>
> > I am working on unix domain sockets. In the sockets, we transfer data
> > with a specific structure. Will a signal interrupt my read(2) when it
> > get part of the data which already in kernel's buffer? If a reading
> > can be interrupted when I got part of bytes of the whole structure,
> > restart is not easy.
>
> According to the spec, read() on a socket is the same as a recv() with
> no flags, and for a SOCK_DGRAM socket the entire message will be read in
> a single operation. This implies that either you get an EINTR and no
> data, or else the operation is restarted automatically by the system.
>
> Whether or not it will be restarted by default depends on
> implementation. To force an automatic restart you can specify
> SA_RESTART for all your signal handlers.
>
> Chris

Thank you for the information! And, my OS (Linux) don't restart a
read(). Thank you!
From: Barry Margolin on
In article <7cydndytSoXtWfjVnZ2dnUVZ_hninZ2d(a)posted.sasktel>,
Chris Friesen <cbf123(a)mail.usask.ca> wrote:

> Steven Woody wrote:
> > Hi,
> >
> > I am working on unix domain sockets. In the sockets, we transfer data
> > with a specific structure. Will a signal interrupt my read(2) when it
> > get part of the data which already in kernel's buffer? If a reading
> > can be interrupted when I got part of bytes of the whole structure,
> > restart is not easy.
>
> According to the spec, read() on a socket is the same as a recv() with
> no flags, and for a SOCK_DGRAM socket the entire message will be read in
> a single operation. This implies that either you get an EINTR and no
> data, or else the operation is restarted automatically by the system.

When did he say it was a SOCK_DGRAM socket?

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***