From: Romain Lenglet <rlenglet@domain.hid>
To: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Blocking reads from pipes
Date: Thu, 17 Nov 2005 19:21:42 +0900 [thread overview]
Message-ID: <200511171921.43221.rlenglet@domain.hid> (raw)
In-Reply-To: <437C5119.4060100@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 705 bytes --]
> One posix thread blocked reading from a pipe (using posix
> open/read) won't unblock when you close the file handle from
> another thread.
Yes, it does!
Compile the two attached source files:
$ gcc -o read read.c
$ gcc -o close close.c
Create the named pipe:
$ mkfifo testfifo
In two different terminals, run "read", which will block in
read(), then "close".
You will remark that the blocking read call is unblocked when the
other process closes its descriptor.
As a conclusion, the behaviour that you observed with Xenomai
pipes seems consistent with that of Linux' named pipes, except
that in Linux read() returns 0, and not an error code as you
observed with Xenomai.
--
Romain Lenglet
[-- Attachment #2: close.c --]
[-- Type: text/x-csrc, Size: 276 bytes --]
#include <stdio.h>
#include <fcntl.h>
#define SIZE 1024
int
main (int argc, char **argv)
{
int desc;
int nread;
char buf[SIZE];
desc = open ("./testfifo", O_WRONLY);
if (desc == -1)
{
perror (argv[0]);
return 1;
}
close (desc);
return 0;
}
[-- Attachment #3: read.c --]
[-- Type: text/x-csrc, Size: 517 bytes --]
#include <stdio.h>
#include <fcntl.h>
#define SIZE 1024
int
main (int argc, char **argv)
{
int desc;
int nread;
char buf[SIZE];
desc = open ("./testfifo", O_RDONLY);
if (desc == -1)
{
perror (argv[0]);
return 1;
}
while ((nread = read (desc, buf, SIZE)) > 0)
{
buf[nread] = 0;
printf ("child received \"%s\" (%d)\n", buf, nread);
}
if (nread == 0)
printf ("child received 0 bytes!\n");
if (nread == -1)
perror (argv[0]);
close (desc);
return 0;
}
next prev parent reply other threads:[~2005-11-17 10:21 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-10 21:05 [Xenomai-help] Creation of a rt-queue from the user space ROSSIER Daniel
2005-11-11 9:30 ` [Xenomai-help] printk Ignacio García Pérez
2005-11-11 11:07 ` Dmitry Adamushko
2005-11-14 10:52 ` Ignacio García Pérez
2005-11-14 11:26 ` Philippe Gerum
2005-11-14 12:03 ` Dmitry Adamushko
2005-11-14 13:22 ` Philippe Gerum
2005-11-14 13:47 ` Philippe Gerum
2005-11-14 14:50 ` [Xenomai-core] " Dmitry Adamushko
2005-11-14 15:56 ` [Xenomai-core] rt_pipe_* usage Ignacio García Pérez
2005-11-14 16:15 ` [Xenomai-core] More on rt pipes usage Ignacio García Pérez
2005-11-15 13:24 ` Philippe Gerum
2005-11-15 16:41 ` [Xenomai-help] " Ignacio García Pérez
2005-11-14 16:23 ` [Xenomai-core] rt_pipe_* usage Dmitry Adamushko
2005-11-14 16:36 ` Ignacio García Pérez
2005-11-15 12:41 ` [Xenomai-core] Web site error (API doc search) Ignacio García Pérez
2005-11-15 13:16 ` [Xenomai-core] rt_pipe_* usage Philippe Gerum
2005-11-15 16:22 ` Ignacio García Pérez
2005-11-16 5:38 ` Philippe Gerum
2005-11-15 9:38 ` [Xenomai-core] Re: [Xenomai-help] printk Philippe Gerum
2005-11-15 10:00 ` Dmitry Adamushko
2005-11-16 12:58 ` Philippe Gerum
2005-11-16 14:44 ` Dmitry Adamushko
2005-11-17 9:44 ` [Xenomai-help] Blocking reads from pipes Ignacio García Pérez
2005-11-17 10:21 ` Romain Lenglet [this message]
2005-11-17 13:16 ` Ignacio García Pérez
2005-11-17 15:11 ` Dmitry Adamushko
2005-11-17 17:24 ` Gilles Chanteperdrix
2005-11-17 17:55 ` [Xenomai-core] " Dmitry Adamushko
2005-11-17 19:17 ` Gilles Chanteperdrix
2005-11-17 19:45 ` Dmitry Adamushko
2005-11-18 8:57 ` Ignacio García Pérez
2005-11-18 9:10 ` Dmitry Adamushko
2005-11-17 19:40 ` Dmitry Adamushko
2005-11-17 10:46 ` Dmitry Adamushko
2005-11-14 12:15 ` [Xenomai-help] xn_pipe_create [minor] Ignacio García Pérez
2005-11-14 13:53 ` Dmitry Adamushko
2005-11-14 16:28 ` Ignacio García Pérez
2005-11-14 16:29 ` Philippe Gerum
2005-11-14 16:41 ` Ignacio García Pérez
2005-11-14 16:52 ` Dmitry Adamushko
2005-11-14 17:38 ` Philippe Gerum
2005-11-14 18:33 ` Dmitry Adamushko
2005-11-15 8:04 ` Philippe Gerum
2005-11-14 18:03 ` [Xenomai-help] Strange pipe behaviour Ignacio García Pérez
2005-11-16 5:45 ` Philippe Gerum
2005-11-16 7:45 ` Ignacio García Pérez
2005-11-16 11:45 ` Philippe Gerum
2005-11-14 16:40 ` [Xenomai-help] xn_pipe_create [minor] Dmitry Adamushko
2005-11-12 19:45 ` [Xenomai-help] printk Philippe Gerum
2005-11-14 10:47 ` [Xenomai-help] Invalid characters in task's names Ignacio García Pérez
2005-11-14 11:39 ` Philippe Gerum
2005-11-11 14:08 ` [Xenomai-help] Creation of a rt-queue from the user space Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200511171921.43221.rlenglet@domain.hid \
--to=rlenglet@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.