123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- #ifndef BOOST_ASIO_BASIC_SOCKET_IOSTREAM_HPP
- #define BOOST_ASIO_BASIC_SOCKET_IOSTREAM_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/asio/detail/config.hpp>
- #if !defined(BOOST_ASIO_NO_IOSTREAM)
- #include <istream>
- #include <ostream>
- #include <boost/asio/basic_socket_streambuf.hpp>
- #include <boost/asio/stream_socket_service.hpp>
- #if !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
- # include <boost/asio/detail/variadic_templates.hpp>
- # define BOOST_ASIO_PRIVATE_CTR_DEF(n) \
- template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \
- explicit basic_socket_iostream(BOOST_ASIO_VARIADIC_PARAMS(n)) \
- : std::basic_iostream<char>( \
- &this->detail::socket_iostream_base< \
- Protocol, StreamSocketService, Time, \
- TimeTraits, TimerService>::streambuf_) \
- { \
- this->setf(std::ios_base::unitbuf); \
- if (rdbuf()->connect(BOOST_ASIO_VARIADIC_ARGS(n)) == 0) \
- this->setstate(std::ios_base::failbit); \
- } \
-
- # define BOOST_ASIO_PRIVATE_CONNECT_DEF(n) \
- template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \
- void connect(BOOST_ASIO_VARIADIC_PARAMS(n)) \
- { \
- if (rdbuf()->connect(BOOST_ASIO_VARIADIC_ARGS(n)) == 0) \
- this->setstate(std::ios_base::failbit); \
- } \
-
- #endif
- #include <boost/asio/detail/push_options.hpp>
- namespace boost {
- namespace asio {
- namespace detail {
- template <typename Protocol, typename StreamSocketService,
- typename Time, typename TimeTraits, typename TimerService>
- class socket_iostream_base
- {
- protected:
- basic_socket_streambuf<Protocol, StreamSocketService,
- Time, TimeTraits, TimerService> streambuf_;
- };
- }
- template <typename Protocol,
- typename StreamSocketService = stream_socket_service<Protocol>,
- #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
- || defined(GENERATING_DOCUMENTATION)
- typename Time = boost::posix_time::ptime,
- typename TimeTraits = boost::asio::time_traits<Time>,
- typename TimerService = deadline_timer_service<Time, TimeTraits> >
- #else
- typename Time = steady_timer::clock_type,
- typename TimeTraits = steady_timer::traits_type,
- typename TimerService = steady_timer::service_type>
- #endif
- class basic_socket_iostream
- : private detail::socket_iostream_base<Protocol,
- StreamSocketService, Time, TimeTraits, TimerService>,
- public std::basic_iostream<char>
- {
- private:
-
-
- #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
- typedef TimeTraits traits_helper;
- #else
- typedef detail::chrono_time_traits<Time, TimeTraits> traits_helper;
- #endif
- public:
-
- typedef typename Protocol::endpoint endpoint_type;
- #if defined(GENERATING_DOCUMENTATION)
-
- typedef typename TimeTraits::time_type time_type;
-
- typedef typename TimeTraits::duration_type duration_type;
- #else
- typedef typename traits_helper::time_type time_type;
- typedef typename traits_helper::duration_type duration_type;
- #endif
-
- basic_socket_iostream()
- : std::basic_iostream<char>(
- &this->detail::socket_iostream_base<
- Protocol, StreamSocketService, Time,
- TimeTraits, TimerService>::streambuf_)
- {
- this->setf(std::ios_base::unitbuf);
- }
- #if defined(GENERATING_DOCUMENTATION)
-
-
- template <typename T1, ..., typename TN>
- explicit basic_socket_iostream(T1 t1, ..., TN tn);
- #elif defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
- template <typename... T>
- explicit basic_socket_iostream(T... x)
- : std::basic_iostream<char>(
- &this->detail::socket_iostream_base<
- Protocol, StreamSocketService, Time,
- TimeTraits, TimerService>::streambuf_)
- {
- this->setf(std::ios_base::unitbuf);
- if (rdbuf()->connect(x...) == 0)
- this->setstate(std::ios_base::failbit);
- }
- #else
- BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_CTR_DEF)
- #endif
- #if defined(GENERATING_DOCUMENTATION)
-
-
- template <typename T1, ..., typename TN>
- void connect(T1 t1, ..., TN tn);
- #elif defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
- template <typename... T>
- void connect(T... x)
- {
- if (rdbuf()->connect(x...) == 0)
- this->setstate(std::ios_base::failbit);
- }
- #else
- BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_CONNECT_DEF)
- #endif
-
- void close()
- {
- if (rdbuf()->close() == 0)
- this->setstate(std::ios_base::failbit);
- }
-
- basic_socket_streambuf<Protocol, StreamSocketService,
- Time, TimeTraits, TimerService>* rdbuf() const
- {
- return const_cast<basic_socket_streambuf<Protocol, StreamSocketService,
- Time, TimeTraits, TimerService>*>(
- &this->detail::socket_iostream_base<
- Protocol, StreamSocketService, Time,
- TimeTraits, TimerService>::streambuf_);
- }
-
-
- const boost::system::error_code& error() const
- {
- return rdbuf()->puberror();
- }
-
-
- time_type expires_at() const
- {
- return rdbuf()->expires_at();
- }
-
-
- void expires_at(const time_type& expiry_time)
- {
- rdbuf()->expires_at(expiry_time);
- }
-
-
- duration_type expires_from_now() const
- {
- return rdbuf()->expires_from_now();
- }
-
-
- void expires_from_now(const duration_type& expiry_time)
- {
- rdbuf()->expires_from_now(expiry_time);
- }
- };
- }
- }
- #include <boost/asio/detail/pop_options.hpp>
- #if !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
- # undef BOOST_ASIO_PRIVATE_CTR_DEF
- # undef BOOST_ASIO_PRIVATE_CONNECT_DEF
- #endif
- #endif
- #endif
|