Line data Source code
1 : #include <iostream>
2 : #include <iow/io/descriptor/holder.hpp>
3 : #include <iow/io/socket/dgram/aspect.hpp>
4 : #include <iow/io/socket/dgram/options.hpp>
5 : #include <iow/io/socket/dgram/tags.hpp>
6 : #include <iow/io/reader/asio/aspect.hpp>
7 : #include <iow/io/writer/asio/aspect.hpp>
8 : #include <iow/io/rw/aspect.hpp>
9 : #include <iow/io/basic/aspect.hpp>
10 :
11 : #include <fas/testing.hpp>
12 :
13 : namespace {
14 : typedef std::vector<char> data_type;
15 : typedef iow::asio::posix::stream_descriptor descriptor1_type;
16 : typedef iow::asio::ip::udp::socket descriptor2_type;
17 : typedef iow::io::socket::dgram::options options_type;
18 :
19 : struct aspect_stream : fas::aspect<
20 : fas::type< ::iow::io::descriptor::_descriptor_type_, descriptor2_type >,
21 : fas::type< ::iow::io::_options_type_, options_type >,
22 : ::iow::io::socket::dgram::aspect,
23 : fas::value< ::iow::io::socket::dgram::_current_endpoint_, std::shared_ptr< boost::asio::ip::udp::endpoint > >,
24 : ::iow::io::reader::asio::aspect,
25 : ::iow::io::writer::asio::aspect,
26 : ::iow::io::rw::aspect,
27 : ::iow::io::basic::aspect< std::recursive_mutex >::advice_list
28 : >{};
29 :
30 : typedef ::iow::io::descriptor::holder<aspect_stream> stream_holder;
31 : }
32 :
33 3 : UNIT(dgram_holder_unit, "")
34 : {
35 : using namespace fas::testing;
36 1 : iow::asio::io_service service;
37 1 : boost::asio::ip::udp::endpoint ep(boost::asio::ip::udp::v4(), 32000);
38 2 : boost::asio::ip::udp::socket sock_server(service);
39 1 : sock_server.open(boost::asio::ip::udp::v4());
40 1 : sock_server.bind( ep );
41 :
42 2 : boost::asio::ip::udp::socket sock_client(service, boost::asio::ip::udp::v4());
43 2 : auto server = std::make_shared<stream_holder>( std::move(sock_server) );
44 2 : options_type opt;
45 1 : opt.reader.sep="";
46 1 : opt.writer.sep="";
47 2 : opt.input_handler = [&]( iow::io::data_ptr d, size_t, options_type::output_handler_type)
48 : {
49 1 : server->get_aspect().get< ::iow::io::writer::_output_>()( *server, std::move(d) );
50 1 : };
51 1 : server->start(opt);
52 1 : sock_client.send_to( boost::asio::buffer("Привет Мир!!!"), ep );
53 1 : char result[1024]={'\0'};
54 1 : sock_client.async_receive_from(
55 : boost::asio::buffer(result, 1024),
56 : ep,
57 1 : [&result, &service](const boost::system::error_code& , std::size_t bytes_transferred)
58 : {
59 1 : result[bytes_transferred]='\0';
60 1 : service.stop();
61 1 : }
62 : );
63 1 : service.run();
64 2 : t << equal<assert, std::string>( result, "Привет Мир!!!" ) << FAS_FL;
65 1 : }
66 :
67 :
68 1 : BEGIN_SUITE(dgram_holder,"")
69 : ADD_UNIT(dgram_holder_unit)
70 7 : END_SUITE(dgram_holder)
71 :
|