Bring aboard a aternative version of Boost's TCP protocol
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 10 Jul 2011 02:33:29 +0000 (23:33 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 10 Jul 2011 02:33:29 +0000 (23:33 -0300)
- This version allows low level socket manipulation of TCP segments, whereas the SOCK_STREAM doesn't allow.

lib/boost-custom/boost/asio/ip/tcp_raw_protocol.hpp [new file with mode: 0644]

diff --git a/lib/boost-custom/boost/asio/ip/tcp_raw_protocol.hpp b/lib/boost-custom/boost/asio/ip/tcp_raw_protocol.hpp
new file mode 100644 (file)
index 0000000..68fc07c
--- /dev/null
@@ -0,0 +1,123 @@
+//
+// tcp_raw_protocol.hpp
+// ~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Modified by Guilherme M. Ferreira
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef TCP_RAW_PROTOCOL
+#define TCP_RAW_PROTOCOL
+
+#include <boost/asio/detail/config.hpp>
+#include <boost/asio/basic_socket_acceptor.hpp>
+#include <boost/asio/basic_socket_iostream.hpp>
+#include <boost/asio/basic_stream_socket.hpp>
+#include <boost/asio/detail/socket_option.hpp>
+#include <boost/asio/detail/socket_types.hpp>
+#include <boost/asio/ip/basic_endpoint.hpp>
+#include <boost/asio/ip/basic_resolver.hpp>
+#include <boost/asio/ip/basic_resolver_iterator.hpp>
+#include <boost/asio/ip/basic_resolver_query.hpp>
+
+#include <boost/asio/detail/push_options.hpp>
+
+namespace boost {
+namespace asio {
+namespace ip {
+
+class tcp_raw_protocol
+{
+public:
+    /// The type of a TCP endpoint.
+    typedef basic_endpoint< tcp_raw_protocol > endpoint;
+
+    /// (Deprecated: use resolver::query.) The type of a resolver query.
+    typedef basic_resolver_query< tcp_raw_protocol > resolver_query;
+
+    /// (Deprecated: use resolver::iterator.) The type of a resolver iterator.
+    typedef basic_resolver_iterator< tcp_raw_protocol > resolver_iterator;
+
+    /// Construct to represent the IPv4 TCP protocol.
+    static tcp_raw_protocol v4()
+    {
+        return tcp_raw_protocol( PF_INET );
+    }
+
+    /// Construct to represent the IPv6 TCP protocol.
+    static tcp_raw_protocol v6()
+    {
+        return tcp_raw_protocol( PF_INET6 );
+    }
+
+    /// Obtain an identifier for the type of the protocol.
+    /// Instead of returning the TCP's SOCK_STREAM, it returns the SOCK_RAW,
+    /// thus allowing a low level TCP management.
+    int type() const
+    {
+        return SOCK_RAW;
+    }
+
+    /// Obtain an identifier for the protocol.
+    int protocol() const
+    {
+        return IPPROTO_TCP;
+    }
+
+    /// Obtain an identifier for the protocol family.
+    int family() const
+    {
+        return family_;
+    }
+
+    /// The TCP socket type.
+    typedef basic_stream_socket< tcp_raw_protocol > socket;
+
+    /// The TCP acceptor type.
+    typedef basic_socket_acceptor< tcp_raw_protocol > acceptor;
+
+    /// The TCP resolver type.
+    typedef basic_resolver< tcp_raw_protocol > resolver;
+
+#if !defined(BOOST_NO_IOSTREAM)
+    /// The TCP iostream type.
+    typedef basic_socket_iostream< tcp_raw_protocol > iostream;
+#endif // !defined(BOOST_NO_IOSTREAM)
+    /// Socket option for disabling the Nagle algorithm.
+#if defined(GENERATING_DOCUMENTATION)
+    typedef implementation_defined no_delay;
+#else
+    typedef boost::asio::detail::socket_option::boolean< IPPROTO_TCP,
+            TCP_NODELAY > no_delay;
+#endif
+
+    /// Compare two protocols for equality.
+    friend bool operator==( const tcp_raw_protocol& p1, const tcp_raw_protocol& p2 )
+    {
+        return p1.family_ == p2.family_;
+    }
+
+    /// Compare two protocols for inequality.
+    friend bool operator!=( const tcp_raw_protocol& p1, const tcp_raw_protocol& p2 )
+    {
+        return p1.family_ != p2.family_;
+    }
+
+private:
+    // Construct with a specific family.
+    explicit tcp_raw_protocol( int family ) :
+        family_( family )
+    {
+    }
+
+    int family_;
+};
+
+} // namespace ip
+} // namespace asio
+} // namespace boost
+
+#endif /* TCP_RAW_PROTOCOL */