9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Doesn't 'close' call finish pending 'read' on the same 'fd'?
@ 2014-11-13 12:21 Pavel Klinkovský
  2014-11-13 12:43 ` cinap_lenrek
  0 siblings, 1 reply; 12+ messages in thread
From: Pavel Klinkovský @ 2014-11-13 12:21 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

Hi all,

I am trying such simple program:

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

static void
closer(int dfd) {
print("closer(%d): 1\n", getpid());
sleep(10 * 1000);
print("closer(%d): 2\n", getpid());
close(dfd);
print("closer(%d): 3\n", getpid());
}

void
main(int, char**)
{
int dfd;
char ddir[NETPATHLEN];
char buf[1024];
long nr;

print("main  (%d): 1\n", getpid());
dfd = dial("tcp!192.168.8.61!23", nil, ddir, nil);
if (dfd < 0)
sysfatal("dial: %r");

print("main  (%d): 2\n", getpid());
switch (rfork(RFPROC|RFREND|RFMEM)) {
case -1:
sysfatal("fork: %r");

case 0:
closer(dfd);
break;

default:
for (;;) {
print("main  (%d): 3\n", getpid());
nr = read(dfd, buf, sizeof buf);
print("main  (%d): 4\n", getpid());
if (nr <= 0)
break;
}

print("main  (%d): 5\n", getpid());
close(dfd);
break;
}

exits(nil);
}

I want to have one process waiting in 'read' function on opened TCP
connection.
I want to close such a TCP connection from another process (created with
shared file descriptor table).
I would expect that 'read' function is finished with -1...
...but it is not.

Here is the output of the program:
main  (11112): 1
main  (11112): 2
closer(11113): 1
main  (11112): 3
main  (11112): 4
main  (11112): 3
closer(11113): 2
closer(11113): 3

You can see that 'main' process is still pending in 'read' function on
already closed 'fd'.

Do I really have to use notes to release the pending 'main' in 'read' call?

Pavel

[-- Attachment #2: Type: text/html, Size: 4066 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-11-13 15:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-13 12:21 [9fans] Doesn't 'close' call finish pending 'read' on the same 'fd'? Pavel Klinkovský
2014-11-13 12:43 ` cinap_lenrek
2014-11-13 12:49   ` Pavel Klinkovský
2014-11-13 13:08     ` cinap_lenrek
2014-11-13 13:13       ` Pavel Klinkovský
2014-11-13 13:17         ` cinap_lenrek
2014-11-13 13:20           ` Pavel Klinkovský
2014-11-13 13:37             ` cinap_lenrek
2014-11-13 13:45               ` Pavel Klinkovský
2014-11-13 14:43                 ` cinap_lenrek
2014-11-13 14:50                   ` Pavel Klinkovský
2014-11-13 15:35                     ` Pavel Klinkovský

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).