]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/example/cpp03/local/iostream_client.cpp
5 // Copyright (c) 2003-2016 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 enum { 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 using namespace std
; // For strlen.
40 std::cout
<< "Enter message: ";
41 char request
[max_length
];
42 std::cin
.getline(request
, max_length
);
43 size_t length
= strlen(request
);
46 char reply
[max_length
];
47 s
.read(reply
, length
);
48 std::cout
<< "Reply is: ";
49 std::cout
.write(reply
, length
);
52 catch (std::exception
& e
)
54 std::cerr
<< "Exception: " << e
.what() << "\n";
60 #else // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
61 # error Local sockets not available on this platform.
62 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)