tcp_socket.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __TCP_SOCKET_H
  15. #define __TCP_SOCKET_H 1
  16. #ifndef ASIO_HPP
  17. #error "asio.hpp must be included before including this, see asiolink.h as to why"
  18. #endif
  19. #include <asiolink/io_socket.h>
  20. namespace asiolink {
  21. /// \brief The \c TCPSocket class is a concrete derived class of
  22. /// \c IOSocket that represents a TCP socket.
  23. ///
  24. /// In the current implementation, an object of this class is always
  25. /// instantiated within the wrapper routines. Applications are expected to
  26. /// get access to the object via the abstract base class, \c IOSocket.
  27. /// This design may be changed when we generalize the wrapper interface.
  28. class TCPSocket : public IOSocket {
  29. private:
  30. TCPSocket(const TCPSocket& source);
  31. TCPSocket& operator=(const TCPSocket& source);
  32. public:
  33. /// \brief Constructor from an ASIO TCP socket.
  34. ///
  35. /// \param socket The ASIO representation of the TCP socket.
  36. TCPSocket(asio::ip::tcp::socket& socket) : socket_(socket) {}
  37. int getNative() const { return (socket_.native()); }
  38. int getProtocol() const { return (IPPROTO_TCP); }
  39. private:
  40. asio::ip::tcp::socket& socket_;
  41. };
  42. } // namespace asiolink
  43. #endif // __TCP_SOCKET_H