9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Giacomo Tesio <giacomo@tesio.it>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Cc: 9front@9front.org
Subject: Re: [9fans] Blocking on write
Date: Mon, 15 May 2017 17:46:16 +0200	[thread overview]
Message-ID: <CAHL7psH-aOtzJk5o8r-ROFaQb3MzRi8HcJsd8ZToQCpF5yrcBQ@mail.gmail.com> (raw)
In-Reply-To: <CAHL7psHZ8mCyy4=bcPOMePg3t-b8-BO5pKaWbDQsN5OFL474Mw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 873 bytes --]

I've just noticed a strange behaviour in devpipe that occurs on both
9front and Plan 9.

When the write blocks, if a note interrupt the process, the waserror
in pipewrite and pipebwrite will post another note that says "sys:
write on a closed pipe ..."

However the pipe is actually open, and still works, as you can see in
the attached test.

Shouldn't the waserror code check that the queue has been actually closed?


Giacomo

2017-05-15 15:36 GMT+02:00 Giacomo Tesio <giacomo@tesio.it>:
> Thanks Charles!
>
>
> Giacomo
>
> 2017-05-15 12:32 GMT+02:00 Charles Forsyth <charles.forsyth@gmail.com>:
>>
>> On 15 May 2017 at 11:05, Giacomo Tesio <giacomo@tesio.it> wrote:
>>>
>>> Is there any fs/device in Plan9 that can easily provide such behaviour?
>>
>>
>> Bind #| to a name and fill up one of the data files (blocks at 256k on my
>> system, might be 32k on small ones).

[-- Attachment #2: writeBlock.c --]
[-- Type: text/x-csrc, Size: 842 bytes --]

#include <u.h>
#include <libc.h>

int
writeTillBlock(int fd)
{
	int i = 0;
	char buf[1024];
	memset(buf, 1, sizeof(buf));
	while(i < 300){
		if(write(fd, buf, sizeof(buf)) < 0)
			break;
		print("%d\n",i);
		++i;
	}
	return i;
}

int
continueOnAlarm(void *v, char *s)
{
	if(strncmp(s, "alarm", 5) == 0)
		return 1;
	if(strncmp(s, "sys: write on closed pipe", 25) == 0)
		return 1;
	return 0;
}

void
main(void)
{
	int fds[2], res;
	char buf[1024];

	pipe(fds);

	atnotify(continueOnAlarm, 1);

	alarm(10000);
	res = writeTillBlock(fds[0]);

	if(res < 256){
		while(res > 1){
			read(fds[1], buf, sizeof(buf));
			--res;
		}
		if(write(fds[0], buf, sizeof(buf)) < 0){
			print("FAIL: can't write after reads: %r\n");
			exits("FAIL");
		}
		print("PASS\n");
		exits(nil);
	}else{
		print("FAIL: written %d kb\n", res);
		exits("FAIL");
	}
	
}

  reply	other threads:[~2017-05-15 15:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-15 10:05 Giacomo Tesio
     [not found] ` <CAOw7k5h4hbwv1CvDr3Mb=6+mifnG3CGgAaZ36G--vtGwLMMvNA@mail.gmail.com>
2017-05-15 13:36   ` [9fans] " Giacomo Tesio
2017-05-15 15:46     ` Giacomo Tesio [this message]
     [not found]       ` <CAOw7k5gA+PL07E7ThpendvY6fqppQV5GqCBXGEQ9-9w5FCEfEQ@mail.gmail.com>
2017-05-17 15:46         ` Giacomo Tesio

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=CAHL7psH-aOtzJk5o8r-ROFaQb3MzRi8HcJsd8ZToQCpF5yrcBQ@mail.gmail.com \
    --to=giacomo@tesio.it \
    --cc=9fans@9fans.net \
    --cc=9front@9front.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).