#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.
You can see that 'main' process is still pending in 'read' function on already closed 'fd'.