//---------------------------------------------------------------------------- /// \file boost-ext.hpp //---------------------------------------------------------------------------- /// \brief This file contains implementation of a timestamp supporting /// socket options. //---------------------------------------------------------------------------- // Author: Serge Aleynikov // Created: 2010-09-30 // License: The same open-source licensing terms apply as in boost::asio. //---------------------------------------------------------------------------- #ifndef _BOOST_ASIO_EXT_HPP_ #define _BOOST_ASIO_EXT_HPP_ #include #include namespace boost { namespace asio { namespace ip { namespace unicast { #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined timestamp; #else typedef boost::asio::detail::socket_option::boolean< SOL_SOCKET, SO_TIMESTAMP> timestamp; #endif #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined timestampns; #else typedef boost::asio::detail::socket_option::boolean< SOL_SOCKET, SO_TIMESTAMPNS> timestampns; #endif } // namespace unicast } // namespace ip namespace detail { namespace io_control { // Helper template for implementing SIOCGSTAMP option. class siocgstamp { public: // Default constructor. siocgstamp() { m_value.tv_sec = 0; m_value.tv_usec = 0; } siocgstamp(struct timeval* tv) { set(*tv); } const struct timeval* get() const { return &m_value; } void set(const struct timeval& tv) { m_value.tv_sec = tv.tv_sec; m_value.tv_usec = tv.tv_usec; } //const struct timeval& get() const { return m_value; } //struct timeval& get() { return m_value; } const struct timeval* operator*() const { return &m_value; } struct timeval* operator*() { return &m_value; } // Get the value for the siocgstamp timeout. double value() const { return static_cast(m_value.tv_sec) + static_cast(m_value.tv_usec) / 1000000.0; } long diff_usec(struct timeval& other) { return (m_value.tv_sec - other.tv_sec)*1000000 + (m_value.tv_usec - other.tv_usec); } // Get the name of the socket option. int name() const { return SIOCGSTAMP; } // Get the address of the siocgstamp data. detail::ioctl_arg_type* data() { return reinterpret_cast(&m_value); } // Get the address of the siocgstamp data. const detail::ioctl_arg_type* data() const { return reinterpret_cast(&m_value); } private: struct timeval m_value; }; } // namespace socket_option } // namespace detail } // namespace asio } // namespace boost #endif // _BOOST_ASIO_EXT_HPP_