]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/example/cpp11/local/iostream_client.cpp
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 #include <boost/asio.hpp>
15 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
17 using boost::asio::local::stream_protocol
;
19 constexpr std::size_t max_length
= 1024;
21 int main(int argc
, char* argv
[])
27 std::cerr
<< "Usage: iostream_client <file>\n";
31 stream_protocol::endpoint
ep(argv
[1]);
32 stream_protocol::iostream
s(ep
);
35 std::cerr
<< "Unable to connect: " << s
.error().message() << std::endl
;
39 std::cout
<< "Enter message: ";
40 char request
[max_length
];
41 std::cin
.getline(request
, max_length
);
42 size_t length
= std::strlen(request
);
45 char reply
[max_length
];
46 s
.read(reply
, length
);
47 std::cout
<< "Reply is: ";
48 std::cout
.write(reply
, length
);
51 catch (std::exception
& e
)
53 std::cerr
<< "Exception: " << e
.what() << "\n";
59 #else // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
60 # error Local sockets not available on this platform.
61 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)