ocean.io.select.client.EpollProcess

Posix process with epoll integration of output streams (stdout & stderr).

Usage example:

1 
2 import ocean.io.Stdout;
3 import ocean.io.select.client.EpollProcess;
4 import ocean.io.select.EpollSelectDispatcher;
5 
6 // Simple epoll process class which uses curl to download data from a
7 // url
8 class CurlProcess : EpollProcess
9 {
10     this ( EpollSelectDispatcher epoll )
11     {
12         super(epoll);
13     }
14 
15     // Starts the process downloading a url
16     public void start ( char[] url )
17     {
18         super.start("curl", [url]);
19     }
20 
21     // Called by the super class when the process sends data to stdout.
22     // (In the case of curl this is data downloaded from the url.)
23     protected void stdout ( ubyte[] data )
24     {
25         Stdout.formatln("Received: '{}'", data);
26     }
27 
28     // Called by the super class when the process sends data to stderr.
29     // (In the case of curl this is progress & error messages, which we
30     // just ignore in this example.)
31     protected void stderr ( ubyte[] data )
32     {
33     }
34 
35     // Called by the super class when the process is finished.
36     protected void finished ( bool exited_ok, int exit_code )
37     {
38         if ( exited_ok )
39         {
40             Stdout.formatln("Process exited with code {}", exit_code);
41         }
42         else
43         {
44             Stdout.formatln("Process terminated abnormally");
45         }
46     }
47 }
48 
49 // Create epoll selector instance.
50 auto epoll = new EpollSelectDispatcher;
51 
52 // Create a curl process instance.
53 auto process = new CurlProcess(epoll);
54 
55 // Start the process running, executing a curl command to download data
56 // from a url.
57 process.start("http://www.google.com");
58 
59 // Handle arriving data.
60 epoll.eventLoop;

It is sometimes desirable to use more than one EpollSelectDispatcher instance with various EpollProcess instances. One example of such usage is when an application needs to create short-lived EpollProcess instance(s) in a unittest block. In this case one EpollSelectDispatcher instance would be needed in the unittest block, and a different one in the application's main logic.

This will work provided that all processes created during the test have terminated before the main application starts.

Members

Classes

EpollProcess
class EpollProcess

Posix process with epoll integration of output streams (stdout & stderr).

Meta

License

Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. Alternatively, this file may be distributed under the terms of the Tango 3-Clause BSD License (see LICENSE_BSD.txt for details).