Posix process with epoll integration of output streams (stdout & stderr).
Usage example:
1 2 importocean.io.Stdout;
3 importocean.io.select.client.EpollProcess;
4 importocean.io.select.EpollSelectDispatcher;
5 6 // Simple epoll process class which uses curl to download data from a7 // url8 classCurlProcess : EpollProcess9 {
10 this ( EpollSelectDispatcherepoll )
11 {
12 super(epoll);
13 }
14 15 // Starts the process downloading a url16 publicvoidstart ( 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 protectedvoidstdout ( 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 we30 // just ignore in this example.)31 protectedvoidstderr ( ubyte[] data )
32 {
33 }
34 35 // Called by the super class when the process is finished.36 protectedvoidfinished ( boolexited_ok, intexit_code )
37 {
38 if ( exited_ok )
39 {
40 Stdout.formatln("Process exited with code {}", exit_code);
41 }
42 else43 {
44 Stdout.formatln("Process terminated abnormally");
45 }
46 }
47 }
48 49 // Create epoll selector instance.50 autoepoll = newEpollSelectDispatcher;
51 52 // Create a curl process instance.53 autoprocess = newCurlProcess(epoll);
54 55 // Start the process running, executing a curl command to download data56 // 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.
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).
Posix process with epoll integration of output streams (stdout & stderr).
Usage example:
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.