|
| 1 | + |
| 2 | +// --- stub library headers --- |
| 3 | + |
| 4 | +namespace std { |
| 5 | + typedef unsigned long size_t; |
| 6 | + #define SIZE_MAX 0xFFFFFFFF |
| 7 | + |
| 8 | + template <class T> class allocator { |
| 9 | + }; |
| 10 | + |
| 11 | + template<class charT> struct char_traits { |
| 12 | + }; |
| 13 | + |
| 14 | + template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
| 15 | + class basic_string { |
| 16 | + public: |
| 17 | + basic_string(const charT* s, const Allocator& a = Allocator()); |
| 18 | + }; |
| 19 | + |
| 20 | + typedef basic_string<char> string; |
| 21 | +}; |
| 22 | + |
| 23 | +namespace boost { |
| 24 | + namespace system { |
| 25 | + class error_code { |
| 26 | + public: |
| 27 | + operator bool() const; |
| 28 | + }; |
| 29 | + }; |
| 30 | + |
| 31 | + namespace asio { |
| 32 | + template<typename Protocol/*, typename Executor*/> |
| 33 | + class basic_stream_socket /*: public basic_socket<Protocol, Executor>*/ { |
| 34 | + }; |
| 35 | + |
| 36 | + namespace ip { |
| 37 | + class tcp { |
| 38 | + public: |
| 39 | + typedef basic_stream_socket<tcp> socket; |
| 40 | + }; |
| 41 | + }; |
| 42 | + |
| 43 | + template<typename Allocator = std::allocator<char>> class basic_streambuf { |
| 44 | + public: |
| 45 | + basic_streambuf( |
| 46 | + std::size_t maximum_size = SIZE_MAX, |
| 47 | + const Allocator &allocator = Allocator()); |
| 48 | + }; |
| 49 | + |
| 50 | + typedef basic_streambuf<> streambuf; |
| 51 | + |
| 52 | + class mutable_buffer { |
| 53 | + }; |
| 54 | + |
| 55 | + template<typename Elem, typename Traits, typename Allocator> |
| 56 | + mutable_buffer buffer(std::basic_string<Elem, Traits, Allocator> & data); |
| 57 | + |
| 58 | + template<typename SyncReadStream, typename Allocator> std::size_t read_until( |
| 59 | + SyncReadStream &s, |
| 60 | + asio::basic_streambuf<Allocator> &b, |
| 61 | + char delim, |
| 62 | + boost::system::error_code &ec); |
| 63 | + |
| 64 | + template<typename SyncWriteStream, typename ConstBufferSequence> std::size_t write( |
| 65 | + SyncWriteStream &s, |
| 66 | + const ConstBufferSequence &buffers, |
| 67 | + boost::system::error_code &ec, |
| 68 | + int constraint = 0); // simplified |
| 69 | + }; |
| 70 | +}; |
| 71 | + |
| 72 | +// --- test code --- |
| 73 | + |
| 74 | +void test(boost::asio::ip::tcp::socket &socket) { |
| 75 | + boost::asio::streambuf recv_buffer; |
| 76 | + boost::system::error_code error; |
| 77 | + |
| 78 | + boost::asio::read_until(socket, recv_buffer, '\0', error); // $ MISSING: remote_source |
| 79 | + if (error) { |
| 80 | + // ... |
| 81 | + } |
| 82 | + |
| 83 | + std::string send_str = std::string("message"); |
| 84 | + boost::asio::mutable_buffer send_buffer = boost::asio::buffer(send_str); |
| 85 | + boost::asio::write(socket, send_buffer, error); // $ MISSING: remote_sink |
| 86 | + if (error) { |
| 87 | + // ... |
| 88 | + } |
| 89 | +} |
0 commit comments