File: io2.e

package info (click to toggle)
entity 0.7.2-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,352 kB
  • ctags: 5,272
  • sloc: ansic: 61,707; sh: 7,921; makefile: 732; perl: 399
file content (58 lines) | stat: -rwxr-xr-x 1,290 bytes parent folder | download | duplicates (3)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env entity

<object title="sdf">
  <window ondelete="entity:exit">
    <label text="This is the IO test, this is only a test."/>
    <label text="Had this been a real emergency, we would"/>
    <label text="have fled in terror and you would not"/>
    <label text="have been informed."/>
  </window>
    
  <io 
    name="read"
    onnewdata="read_line"
    onerror="got_messed"
   />
  <io 
    name="write"
    onerror="got_messed"
   />
  <timer interval="1000" action="write_line"/>
  <perl>
  <![CDATA[
    
    open (RFH, "/etc/passwd") or die "Unable to open /etc/passwd";
    my $io = enode ('io.read');
    $fd = fileno (RFH);
    print ("fd is $fd\n");
    $io->attrib ('fd' => $fd);
    print ("read io is $io\n");
    
    open (WFH, ">foofile.txt");
    $io = enode ('io.write');
    $io->attrib ('fd' => fileno (WFH));
    print ("write io is $io\n");

    sub read_line
    {
      my ($node, $chunk, $size) = @_;
      print ("args, node $node, chunk $chunk, size $size\n");
      
      if ($size <= 0) {
        $node->attrib ('fd' => -1);
      }
      print ("read $chunk");
    }
    
    sub write_line
    {
      my $io = enode ('io.write');
      $io->write ("Hello\n");
      if (0) {
        print WFH "Hello";
      }
    }
  ]]>
  </perl>

</object>