MCPcopy Create free account
hub / github.com/boostorg/asio / main

Function main

example/cpp11/local/connect_pair.cpp:74–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72};
73
74int main()
75{
76 try
77 {
78 boost::asio::io_context io_context;
79
80 // Create a connected pair and pass one end to a filter.
81 stream_protocol::socket socket(io_context);
82 stream_protocol::socket filter_socket(io_context);
83 boost::asio::local::connect_pair(socket, filter_socket);
84 uppercase_filter filter(std::move(filter_socket));
85
86 // The io_context runs in a background thread to perform filtering.
87 boost::thread thread(
88 [&io_context]()
89 {
90 try
91 {
92 io_context.run();
93 }
94 catch (std::exception& e)
95 {
96 std::cerr << "Exception in thread: " << e.what() << "\n";
97 std::exit(1);
98 }
99 });
100
101 for (;;)
102 {
103 // Collect request from user.
104 std::cout << "Enter a string: ";
105 std::string request;
106 std::getline(std::cin, request);
107
108 // Send request to filter.
109 boost::asio::write(socket, boost::asio::buffer(request));
110
111 // Wait for reply from filter.
112 std::vector<char> reply(request.size());
113 boost::asio::read(socket, boost::asio::buffer(reply));
114
115 // Show reply to user.
116 std::cout << "Result: ";
117 std::cout.write(&reply[0], request.size());
118 std::cout << std::endl;
119 }
120 }
121 catch (std::exception& e)
122 {
123 std::cerr << "Exception: " << e.what() << "\n";
124 std::exit(1);
125 }
126}
127
128#else // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
129# error Local sockets not available on this platform.

Callers

nothing calls this directly

Calls 7

connect_pairFunction · 0.85
writeFunction · 0.85
bufferFunction · 0.85
readFunction · 0.85
runMethod · 0.45
sizeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected