From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 Date: Thu, 13 Nov 2014 13:21:34 +0100 Message-ID: From: =?UTF-8?Q?Pavel_Klinkovsk=C3=BD?= To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=001a11c11c2ca2112a0507bc8d2c Subject: [9fans] Doesn't 'close' call finish pending 'read' on the same 'fd'? Topicbox-Message-UUID: 2718d766-ead9-11e9-9d60-3106f5b1d025 --001a11c11c2ca2112a0507bc8d2c Content-Type: text/plain; charset=UTF-8 Hi all, I am trying such simple program: #include #include 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 --001a11c11c2ca2112a0507bc8d2c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 =C2=A0(%d): 1\n", g= etpid());
dfd = =3D dial("tcp!192.168.8.61!23", nil, ddir, nil);
if (dfd < 0)
sysfatal("dial: %r&quo= t;);

<= /span>print("main =C2=A0(%d): 2\n", getpid());
switch (rfork(RFPROC|RFREND|RFME= M)) {
case -1= :
sysfatal(&= quot;fork: %r");

case 0:
closer(dfd);
break;

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

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

exits(nil);
}

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

Here is the output of the program:<= /div>
main =C2=A0(11112): 1
main =C2=A0(11112): 2
<= div>closer(11113): 1
main =C2=A0(11112): 3
main =C2=A0(= 11112): 4
main =C2=A0(11112): 3
closer(11113): 2
<= div>closer(11113): 3

You can see that 'm= ain' process is still pending in 'read' function on already clo= sed 'fd'.

Do I=C2=A0really=C2=A0have to us= e notes to release the pending 'main' in 'read' call?
=

Pavel

--001a11c11c2ca2112a0507bc8d2c--