|
| 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 | +char *source(); |
| 75 | +void sink(char *); |
| 76 | +void sink(std::string); |
| 77 | +void sink(boost::asio::streambuf); |
| 78 | +void sink(boost::asio::mutable_buffer); |
| 79 | + |
| 80 | +char *getenv(const char *name); |
| 81 | +int send(int, const void*, int, int); |
| 82 | + |
| 83 | +void test(boost::asio::ip::tcp::socket &socket) { |
| 84 | + boost::asio::streambuf recv_buffer; |
| 85 | + boost::system::error_code error; |
| 86 | + |
| 87 | + boost::asio::read_until(socket, recv_buffer, '\0', error); |
| 88 | + if (error) { |
| 89 | + // ... |
| 90 | + } |
| 91 | + sink(recv_buffer); // $ MISSING: ir |
| 92 | + |
| 93 | + boost::asio::write(socket, recv_buffer, error); // $ MISSING: ir |
| 94 | + |
| 95 | + // --- |
| 96 | + |
| 97 | + std::string send_str = std::string(source()); |
| 98 | + sink(send_str); // $ ir |
| 99 | + |
| 100 | + boost::asio::mutable_buffer send_buffer = boost::asio::buffer(send_str); |
| 101 | + sink(send_buffer); // $ MISSING: ir |
| 102 | + |
| 103 | + boost::asio::write(socket, send_buffer, error); // $ MISSING: ir |
| 104 | + if (error) { |
| 105 | + // ... |
| 106 | + } |
| 107 | +} |
0 commit comments