1 | #include <boost/asio.hpp>
|
---|
2 | #include <boost/asio/ssl.hpp>
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | /*
|
---|
6 | clang++ -std=c++11 -stdlib=libc++ testasiossl.cpp -I /opt/local/include -lssl -lcrypto -L/opt/local/lib -lboost_system-mt
|
---|
7 | g++-mp-4.7 -std=c++11 testasiossl.cpp -I /opt/local/include -lssl -lcrypto -L/opt/local/lib -lboost_system-mt
|
---|
8 | */
|
---|
9 | class teststream {
|
---|
10 | boost::asio::io_service &io;
|
---|
11 | public:
|
---|
12 | teststream(boost::asio::io_service &io_service) : io(io_service) { }
|
---|
13 |
|
---|
14 | template<typename ReadHandler>
|
---|
15 | void async_read_some(boost::asio::mutable_buffers_1, ReadHandler handler)
|
---|
16 | {
|
---|
17 | }
|
---|
18 |
|
---|
19 | template<typename WriteHandler>
|
---|
20 | void async_write_some(boost::asio::const_buffers_1 bufs, WriteHandler handler)
|
---|
21 | {
|
---|
22 | }
|
---|
23 |
|
---|
24 | typedef teststream lowest_layer_type;
|
---|
25 | lowest_layer_type& lowest_layer() { return *this; }
|
---|
26 | boost::asio::io_service &get_io_service() { return io; }
|
---|
27 | };
|
---|
28 |
|
---|
29 | int main(int, char**)
|
---|
30 | {
|
---|
31 | boost::asio::io_service io_service;
|
---|
32 |
|
---|
33 | typedef boost::asio::ssl::stream<teststream> ssl_socket;
|
---|
34 |
|
---|
35 | boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23);
|
---|
36 |
|
---|
37 | ssl_socket sock(io_service, ctx);
|
---|
38 |
|
---|
39 | sock.set_verify_mode(boost::asio::ssl::verify_none);
|
---|
40 | sock.async_handshake(ssl_socket::client, [&sock](const boost::system::error_code& error) {
|
---|
41 | boost::asio::async_write(sock, boost::asio::buffer("test123", 7), [](const boost::system::error_code& error, std::size_t n) { std::cout << "xmitted " << n << " bytes\n"; });
|
---|
42 |
|
---|
43 | uint8_t *rcv= new uint8_t[16];
|
---|
44 | boost::asio::async_read(sock, boost::asio::buffer(rcv, 16), [rcv](const boost::system::error_code& error, std::size_t n) { std::cout << "received " << n << " bytes\n"; });
|
---|
45 | });
|
---|
46 | }
|
---|