]> Pileus Git - ~andy/rhawk/blob - select.awk
Save game after flipping the table
[~andy/rhawk] / select.awk
1 BEGIN {
2         extension("./select.so", "dlload");
3
4         nc0   = "netcat -l -p 12345"
5         nc1   = "netcat -l -p 54321"
6         stdin = "/dev/stdin"
7
8         while (1) {
9                 # Open pipes
10                 printf "" |& nc0
11                 printf "" |& nc1
12
13                 # Wait for input 
14                 if (!(fd = select("from", stdin, nc0, nc1))) {
15                         print "timeout"
16                         continue
17                 }
18
19                 # Read a line
20                 if (fd == stdin)
21                         if (!(st = getline line < fd))
22                                 exit 0
23                 if (fd == nc0 || fd == nc1)
24                         if (!(st = fd |& getline line)) {
25                                 print "broken pipe"
26                                 close(fd)
27                                 continue
28                         }
29
30                 # Print output
31                 print "line: [" fd "] -> [" line "]"
32         }
33 }