File: looptest.cc

package info (click to toggle)
wvstreams 4.0.2-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,420 kB
  • ctags: 6,518
  • sloc: cpp: 52,544; sh: 5,770; ansic: 810; makefile: 461; tcl: 114; perl: 18
file content (36 lines) | stat: -rw-r--r-- 728 bytes parent folder | download | duplicates (12)
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
/*
 * Worldvisions Weaver Software:
 *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
 *
 * WvLoopback test.  Forks and has each process to write to the other.
 */
#include "wvloopback.h"
#include "wvlog.h"

int main()
{
    WvLoopback loop;
    WvLog log("loopy", WvLog::Info);
    char buf[1024];
    size_t size;
    pid_t pid;
    
    pid = fork();
    
    // each line should print twice, but no one guarantees in what order!
    loop.print("blah\n");
    loop.print("weasels!\n");
    
    if (pid) // parent only
    {
	while (loop.select(100))
	{
	    size = loop.read(buf, sizeof(buf));
	    log.write(buf, size);
	}
    }
    else
	_exit(0); // do not run destructors in the child
    
    return 0;
}