-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
37 lines (30 loc) · 1.32 KB
/
Copy pathtest.cpp
File metadata and controls
37 lines (30 loc) · 1.32 KB
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
// test code that makes one thread handles mid-program key inputs as signals, might want to use this to print out current
// state of the server
#include <iostream>
#include <csignal>
#include <boost/asio.hpp>
#include <boost/bind/bind.hpp>
using namespace std;
using namespace boost::asio;
void signal_handler(int signum) {
cout << "here' help\n";
}
void handle_input(const boost::system::error_code& error, size_t bytes_transferred, char* input, boost::asio::posix::stream_descriptor& input_stream) {
if (!error) {
if (input[0] == 'h' || input[0] == 'H') {
signal_handler(SIGUSR1);
}
// Start another asynchronous read
async_read(input_stream, buffer(input, 1), boost::bind(handle_input, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, input, boost::ref(input_stream)));
}
}
int main() {
boost::asio::io_context io_context;
boost::asio::posix::stream_descriptor input_stream(io_context, ::dup(STDIN_FILENO));
char input[1];
// Start asynchronous read
async_read(input_stream, buffer(input, 1), boost::bind(handle_input, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, input, boost::ref(input_stream)));
// Run the io_context to process asynchronous events
io_context.run();
return 0;
}