forked from ravinet/mahimahi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelayshell.cc
49 lines (38 loc) · 1.33 KB
/
delayshell.cc
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
/* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <vector>
#include <string>
#include "delay_queue.hh"
#include "util.hh"
#include "packetshell.cc"
using namespace std;
int main( int argc, char *argv[] )
{
try {
/* clear environment while running as root */
char ** const user_environment = environ;
environ = nullptr;
check_requirements( argc, argv );
if ( argc < 2 ) {
throw Exception( "Usage", string( argv[ 0 ] ) + " delay-milliseconds [command...]" );
}
const uint64_t delay_ms = myatoi( argv[ 1 ] );
vector< string > command;
if ( argc == 2 ) {
command.push_back( shell_path() );
} else {
for ( int i = 2; i < argc; i++ ) {
command.push_back( argv[ i ] );
}
}
PacketShell<DelayQueue> delay_shell_app( "delay" );
delay_shell_app.start_uplink( "[delay " + to_string( delay_ms ) + " ms] ",
user_environment,
command,
delay_ms );
delay_shell_app.start_downlink( delay_ms );
return delay_shell_app.wait_for_exit();
} catch ( const Exception & e ) {
e.perror();
return EXIT_FAILURE;
}
}