File: socketpair.pl

package info (click to toggle)
taktuk 3.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,252 kB
  • sloc: perl: 6,715; ansic: 1,211; makefile: 188; sh: 161
file content (34 lines) | stat: -rwxr-xr-x 634 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl
# Test code for socketpair system call
# should replace pipes in Taktuk (got do check portability before doing the change)

use Socket;

my ($un, $deux);
socketpair($un, $deux, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die $!;
#pipe ($deux, $un) or die $!;
my $pid;
my ($buffer1, $buffer2);
if ($pid = fork())
{
  close($un);
  print "MON PID : $pid\n";
  while (1)
    {
      sysread($deux,$buffer2,128);
      print $buffer2;
      sleep 1;
    }
}
else
{
  close($deux);
  $buffer1="Pong\n";
  print "MON PID : $pid\n";
  open(STDOUT,">&",$un);
  close($un);
  while (1)
    {
      syswrite(STDOUT,$buffer1,6);
    }
}