[svn] commit: r1864 - in /branches/trac168: ./ ext/ ext/asio/ ext/asio/detail/ ext/asio/impl/ ext/asio/ip/ ext/asio/ip/detail/ ext/asio/local/ ext/asio/posix/ ext/asio/ssl/ ext/asio/ssl/detail/ ext/asio/windows/ src/bin/auth/ src/lib/cc/ src/lib/config/ src/lib/config/tests/ src/lib/xfr/

BIND 10 source code commits bind10-changes at lists.isc.org
Thu May 20 01:26:24 UTC 2010


Author: each
Date: Thu May 20 01:26:23 2010
New Revision: 1864

Log:
- added ASIO library header files (version 1.4.5, downloaded from
  http://sourceforge.net/projects/asio/files, project page
  http://think-async.com/Asio).
- removed uses of boost::asio
- removed custom TCP/UDP code

Added:
    branches/trac168/ext/asio/
    branches/trac168/ext/asio.hpp
    branches/trac168/ext/asio/basic_datagram_socket.hpp
    branches/trac168/ext/asio/basic_deadline_timer.hpp
    branches/trac168/ext/asio/basic_io_object.hpp
    branches/trac168/ext/asio/basic_raw_socket.hpp
    branches/trac168/ext/asio/basic_serial_port.hpp
    branches/trac168/ext/asio/basic_socket.hpp
    branches/trac168/ext/asio/basic_socket_acceptor.hpp
    branches/trac168/ext/asio/basic_socket_iostream.hpp
    branches/trac168/ext/asio/basic_socket_streambuf.hpp
    branches/trac168/ext/asio/basic_stream_socket.hpp
    branches/trac168/ext/asio/basic_streambuf.hpp
    branches/trac168/ext/asio/buffer.hpp
    branches/trac168/ext/asio/buffered_read_stream.hpp
    branches/trac168/ext/asio/buffered_read_stream_fwd.hpp
    branches/trac168/ext/asio/buffered_stream.hpp
    branches/trac168/ext/asio/buffered_stream_fwd.hpp
    branches/trac168/ext/asio/buffered_write_stream.hpp
    branches/trac168/ext/asio/buffered_write_stream_fwd.hpp
    branches/trac168/ext/asio/buffers_iterator.hpp
    branches/trac168/ext/asio/completion_condition.hpp
    branches/trac168/ext/asio/datagram_socket_service.hpp
    branches/trac168/ext/asio/deadline_timer.hpp
    branches/trac168/ext/asio/deadline_timer_service.hpp
    branches/trac168/ext/asio/detail/
    branches/trac168/ext/asio/detail/base_from_completion_cond.hpp
    branches/trac168/ext/asio/detail/bind_handler.hpp
    branches/trac168/ext/asio/detail/buffer_resize_guard.hpp
    branches/trac168/ext/asio/detail/buffer_sequence_adapter.hpp
    branches/trac168/ext/asio/detail/buffered_stream_storage.hpp
    branches/trac168/ext/asio/detail/call_stack.hpp
    branches/trac168/ext/asio/detail/completion_handler.hpp
    branches/trac168/ext/asio/detail/consuming_buffers.hpp
    branches/trac168/ext/asio/detail/deadline_timer_service.hpp
    branches/trac168/ext/asio/detail/descriptor_ops.hpp
    branches/trac168/ext/asio/detail/dev_poll_reactor.hpp
    branches/trac168/ext/asio/detail/dev_poll_reactor_fwd.hpp
    branches/trac168/ext/asio/detail/epoll_reactor.hpp
    branches/trac168/ext/asio/detail/epoll_reactor_fwd.hpp
    branches/trac168/ext/asio/detail/event.hpp
    branches/trac168/ext/asio/detail/eventfd_select_interrupter.hpp
    branches/trac168/ext/asio/detail/fd_set_adapter.hpp
    branches/trac168/ext/asio/detail/fenced_block.hpp
    branches/trac168/ext/asio/detail/gcc_fenced_block.hpp
    branches/trac168/ext/asio/detail/gcc_x86_fenced_block.hpp
    branches/trac168/ext/asio/detail/handler_alloc_helpers.hpp
    branches/trac168/ext/asio/detail/handler_invoke_helpers.hpp
    branches/trac168/ext/asio/detail/hash_map.hpp
    branches/trac168/ext/asio/detail/io_control.hpp
    branches/trac168/ext/asio/detail/kqueue_reactor.hpp
    branches/trac168/ext/asio/detail/kqueue_reactor_fwd.hpp
    branches/trac168/ext/asio/detail/local_free_on_block_exit.hpp
    branches/trac168/ext/asio/detail/macos_fenced_block.hpp
    branches/trac168/ext/asio/detail/mutex.hpp
    branches/trac168/ext/asio/detail/noncopyable.hpp
    branches/trac168/ext/asio/detail/null_buffers_op.hpp
    branches/trac168/ext/asio/detail/null_event.hpp
    branches/trac168/ext/asio/detail/null_fenced_block.hpp
    branches/trac168/ext/asio/detail/null_mutex.hpp
    branches/trac168/ext/asio/detail/null_signal_blocker.hpp
    branches/trac168/ext/asio/detail/null_thread.hpp
    branches/trac168/ext/asio/detail/null_tss_ptr.hpp
    branches/trac168/ext/asio/detail/old_win_sdk_compat.hpp
    branches/trac168/ext/asio/detail/op_queue.hpp
    branches/trac168/ext/asio/detail/operation.hpp
    branches/trac168/ext/asio/detail/pipe_select_interrupter.hpp
    branches/trac168/ext/asio/detail/pop_options.hpp
    branches/trac168/ext/asio/detail/posix_event.hpp
    branches/trac168/ext/asio/detail/posix_fd_set_adapter.hpp
    branches/trac168/ext/asio/detail/posix_mutex.hpp
    branches/trac168/ext/asio/detail/posix_signal_blocker.hpp
    branches/trac168/ext/asio/detail/posix_thread.hpp
    branches/trac168/ext/asio/detail/posix_tss_ptr.hpp
    branches/trac168/ext/asio/detail/push_options.hpp
    branches/trac168/ext/asio/detail/reactive_descriptor_service.hpp
    branches/trac168/ext/asio/detail/reactive_serial_port_service.hpp
    branches/trac168/ext/asio/detail/reactive_socket_service.hpp
    branches/trac168/ext/asio/detail/reactor.hpp
    branches/trac168/ext/asio/detail/reactor_fwd.hpp
    branches/trac168/ext/asio/detail/reactor_op.hpp
    branches/trac168/ext/asio/detail/reactor_op_queue.hpp
    branches/trac168/ext/asio/detail/resolver_service.hpp
    branches/trac168/ext/asio/detail/scoped_lock.hpp
    branches/trac168/ext/asio/detail/select_interrupter.hpp
    branches/trac168/ext/asio/detail/select_reactor.hpp
    branches/trac168/ext/asio/detail/select_reactor_fwd.hpp
    branches/trac168/ext/asio/detail/service_base.hpp
    branches/trac168/ext/asio/detail/service_id.hpp
    branches/trac168/ext/asio/detail/service_registry.hpp
    branches/trac168/ext/asio/detail/service_registry_fwd.hpp
    branches/trac168/ext/asio/detail/signal_blocker.hpp
    branches/trac168/ext/asio/detail/signal_init.hpp
    branches/trac168/ext/asio/detail/socket_holder.hpp
    branches/trac168/ext/asio/detail/socket_ops.hpp
    branches/trac168/ext/asio/detail/socket_option.hpp
    branches/trac168/ext/asio/detail/socket_select_interrupter.hpp
    branches/trac168/ext/asio/detail/socket_types.hpp
    branches/trac168/ext/asio/detail/solaris_fenced_block.hpp
    branches/trac168/ext/asio/detail/strand_service.hpp
    branches/trac168/ext/asio/detail/task_io_service.hpp
    branches/trac168/ext/asio/detail/task_io_service_fwd.hpp
    branches/trac168/ext/asio/detail/task_io_service_operation.hpp
    branches/trac168/ext/asio/detail/thread.hpp
    branches/trac168/ext/asio/detail/throw_error.hpp
    branches/trac168/ext/asio/detail/timer_op.hpp
    branches/trac168/ext/asio/detail/timer_queue.hpp
    branches/trac168/ext/asio/detail/timer_queue_base.hpp
    branches/trac168/ext/asio/detail/timer_queue_fwd.hpp
    branches/trac168/ext/asio/detail/timer_queue_set.hpp
    branches/trac168/ext/asio/detail/timer_scheduler.hpp
    branches/trac168/ext/asio/detail/timer_scheduler_fwd.hpp
    branches/trac168/ext/asio/detail/tss_ptr.hpp
    branches/trac168/ext/asio/detail/win_event.hpp
    branches/trac168/ext/asio/detail/win_fd_set_adapter.hpp
    branches/trac168/ext/asio/detail/win_fenced_block.hpp
    branches/trac168/ext/asio/detail/win_iocp_handle_service.hpp
    branches/trac168/ext/asio/detail/win_iocp_io_service.hpp
    branches/trac168/ext/asio/detail/win_iocp_io_service_fwd.hpp
    branches/trac168/ext/asio/detail/win_iocp_operation.hpp
    branches/trac168/ext/asio/detail/win_iocp_overlapped_ptr.hpp
    branches/trac168/ext/asio/detail/win_iocp_serial_port_service.hpp
    branches/trac168/ext/asio/detail/win_iocp_socket_service.hpp
    branches/trac168/ext/asio/detail/win_mutex.hpp
    branches/trac168/ext/asio/detail/win_signal_blocker.hpp
    branches/trac168/ext/asio/detail/win_thread.hpp
    branches/trac168/ext/asio/detail/win_tss_ptr.hpp
    branches/trac168/ext/asio/detail/wince_thread.hpp
    branches/trac168/ext/asio/detail/winsock_init.hpp
    branches/trac168/ext/asio/detail/wrapped_handler.hpp
    branches/trac168/ext/asio/error.hpp
    branches/trac168/ext/asio/error_code.hpp
    branches/trac168/ext/asio/handler_alloc_hook.hpp
    branches/trac168/ext/asio/handler_invoke_hook.hpp
    branches/trac168/ext/asio/impl/
    branches/trac168/ext/asio/impl/error_code.ipp
    branches/trac168/ext/asio/impl/io_service.ipp
    branches/trac168/ext/asio/impl/read.ipp
    branches/trac168/ext/asio/impl/read_at.ipp
    branches/trac168/ext/asio/impl/read_until.ipp
    branches/trac168/ext/asio/impl/serial_port_base.ipp
    branches/trac168/ext/asio/impl/write.ipp
    branches/trac168/ext/asio/impl/write_at.ipp
    branches/trac168/ext/asio/io_service.hpp
    branches/trac168/ext/asio/ip/
    branches/trac168/ext/asio/ip/address.hpp
    branches/trac168/ext/asio/ip/address_v4.hpp
    branches/trac168/ext/asio/ip/address_v6.hpp
    branches/trac168/ext/asio/ip/basic_endpoint.hpp
    branches/trac168/ext/asio/ip/basic_resolver.hpp
    branches/trac168/ext/asio/ip/basic_resolver_entry.hpp
    branches/trac168/ext/asio/ip/basic_resolver_iterator.hpp
    branches/trac168/ext/asio/ip/basic_resolver_query.hpp
    branches/trac168/ext/asio/ip/detail/
    branches/trac168/ext/asio/ip/detail/socket_option.hpp
    branches/trac168/ext/asio/ip/host_name.hpp
    branches/trac168/ext/asio/ip/icmp.hpp
    branches/trac168/ext/asio/ip/multicast.hpp
    branches/trac168/ext/asio/ip/resolver_query_base.hpp
    branches/trac168/ext/asio/ip/resolver_service.hpp
    branches/trac168/ext/asio/ip/tcp.hpp
    branches/trac168/ext/asio/ip/udp.hpp
    branches/trac168/ext/asio/ip/unicast.hpp
    branches/trac168/ext/asio/ip/v6_only.hpp
    branches/trac168/ext/asio/is_read_buffered.hpp
    branches/trac168/ext/asio/is_write_buffered.hpp
    branches/trac168/ext/asio/local/
    branches/trac168/ext/asio/local/basic_endpoint.hpp
    branches/trac168/ext/asio/local/connect_pair.hpp
    branches/trac168/ext/asio/local/datagram_protocol.hpp
    branches/trac168/ext/asio/local/stream_protocol.hpp
    branches/trac168/ext/asio/placeholders.hpp
    branches/trac168/ext/asio/posix/
    branches/trac168/ext/asio/posix/basic_descriptor.hpp
    branches/trac168/ext/asio/posix/basic_stream_descriptor.hpp
    branches/trac168/ext/asio/posix/descriptor_base.hpp
    branches/trac168/ext/asio/posix/stream_descriptor.hpp
    branches/trac168/ext/asio/posix/stream_descriptor_service.hpp
    branches/trac168/ext/asio/raw_socket_service.hpp
    branches/trac168/ext/asio/read.hpp
    branches/trac168/ext/asio/read_at.hpp
    branches/trac168/ext/asio/read_until.hpp
    branches/trac168/ext/asio/serial_port.hpp
    branches/trac168/ext/asio/serial_port_base.hpp
    branches/trac168/ext/asio/serial_port_service.hpp
    branches/trac168/ext/asio/socket_acceptor_service.hpp
    branches/trac168/ext/asio/socket_base.hpp
    branches/trac168/ext/asio/ssl/
    branches/trac168/ext/asio/ssl.hpp
    branches/trac168/ext/asio/ssl/basic_context.hpp   (with props)
    branches/trac168/ext/asio/ssl/context.hpp
    branches/trac168/ext/asio/ssl/context_base.hpp   (with props)
    branches/trac168/ext/asio/ssl/context_service.hpp   (with props)
    branches/trac168/ext/asio/ssl/detail/
    branches/trac168/ext/asio/ssl/detail/openssl_context_service.hpp   (with props)
    branches/trac168/ext/asio/ssl/detail/openssl_init.hpp   (with props)
    branches/trac168/ext/asio/ssl/detail/openssl_operation.hpp   (with props)
    branches/trac168/ext/asio/ssl/detail/openssl_stream_service.hpp
    branches/trac168/ext/asio/ssl/detail/openssl_types.hpp   (with props)
    branches/trac168/ext/asio/ssl/stream.hpp
    branches/trac168/ext/asio/ssl/stream_base.hpp   (with props)
    branches/trac168/ext/asio/ssl/stream_service.hpp
    branches/trac168/ext/asio/strand.hpp
    branches/trac168/ext/asio/stream_socket_service.hpp
    branches/trac168/ext/asio/streambuf.hpp
    branches/trac168/ext/asio/system_error.hpp
    branches/trac168/ext/asio/thread.hpp
    branches/trac168/ext/asio/time_traits.hpp
    branches/trac168/ext/asio/version.hpp
    branches/trac168/ext/asio/windows/
    branches/trac168/ext/asio/windows/basic_handle.hpp
    branches/trac168/ext/asio/windows/basic_random_access_handle.hpp
    branches/trac168/ext/asio/windows/basic_stream_handle.hpp
    branches/trac168/ext/asio/windows/overlapped_ptr.hpp
    branches/trac168/ext/asio/windows/random_access_handle.hpp
    branches/trac168/ext/asio/windows/random_access_handle_service.hpp
    branches/trac168/ext/asio/windows/stream_handle.hpp
    branches/trac168/ext/asio/windows/stream_handle_service.hpp
    branches/trac168/ext/asio/write.hpp
    branches/trac168/ext/asio/write_at.hpp
Modified:
    branches/trac168/README
    branches/trac168/src/bin/auth/main.cc
    branches/trac168/src/lib/cc/session.cc
    branches/trac168/src/lib/cc/session.h
    branches/trac168/src/lib/config/ccsession.cc
    branches/trac168/src/lib/config/ccsession.h
    branches/trac168/src/lib/config/tests/fake_session.cc
    branches/trac168/src/lib/config/tests/fake_session.h
    branches/trac168/src/lib/xfr/xfrout_client.cc
    branches/trac168/src/lib/xfr/xfrout_client.h

Modified: branches/trac168/README
==============================================================================
--- branches/trac168/README (original)
+++ branches/trac168/README Thu May 20 01:26:23 2010
@@ -37,9 +37,6 @@
 See the Guide for detailed installation directions.
 
 BUILDING
-
-We recommend using the Boost libraries as it provides a safer TCP
-implementation in BIND 10.
 
 Simple build instructions:
 

Modified: branches/trac168/src/bin/auth/main.cc
==============================================================================
--- branches/trac168/src/bin/auth/main.cc (original)
+++ branches/trac168/src/bin/auth/main.cc Thu May 20 01:26:23 2010
@@ -28,10 +28,8 @@
 #include <iostream>
 
 #include <boost/foreach.hpp>
-#ifdef HAVE_BOOST_SYSTEM
 #include <boost/bind.hpp>
-#include <boost/asio.hpp>
-#endif  // HAVE_BOOST_SYSTEM
+#include <asio.hpp>
 
 #include <exceptions/exceptions.h>
 
@@ -43,7 +41,7 @@
 #include <cc/data.h>
 #include <config/ccsession.h>
 
-#if defined(HAVE_BOOST_SYSTEM) && defined(HAVE_BOOST_PYTHON)
+#if defined(HAVE_BOOST_PYTHON)
 #define USE_XFROUT
 #include <xfr/xfrout_client.h>
 #endif
@@ -57,11 +55,9 @@
 using namespace isc::xfr;
 #endif
 
-#ifdef HAVE_BOOST_SYSTEM
-using namespace boost::asio;
+using namespace asio;
 using ip::udp;
 using ip::tcp;
-#endif  // HAVE_BOOST_SYSTEM
 
 using namespace isc::data;
 using namespace isc::cc;
@@ -79,13 +75,10 @@
  * todo: turn this around, and put handlers in the authserver
  * class itself? */
 AuthSrv *auth_server;
-#ifdef HAVE_BOOST_SYSTEM
+
 // TODO: this should be a property of AuthSrv, and AuthSrv needs
 // a stop() method (so the shutdown command can be handled)
-boost::asio::io_service io_service_;
-#else
-bool running;
-#endif  // HAVE_BOOST_SYSTEM
+asio::io_service io_service_;
 
 ElementPtr
 my_config_handler(ElementPtr new_config) {
@@ -101,11 +94,7 @@
         /* let's add that message to our answer as well */
         answer->get("result")->add(args);
     } else if (command == "shutdown") {
-#ifdef HAVE_BOOST_SYSTEM
         io_service_.stop();
-#else
-        running = false;
-#endif  // HAVE_BOOST_SYSTEM
     }
     
     return answer;
@@ -144,9 +133,8 @@
 }
 #endif
 
-#ifdef HAVE_BOOST_SYSTEM
 //
-// Helper classes for asynchronous I/O using boost::asio
+// Helper classes for asynchronous I/O using asio
 //
 class TCPClient {
 public:
@@ -159,7 +147,7 @@
     {}
 
     void start() {
-        async_read(socket_, boost::asio::buffer(data_, TCP_MESSAGE_LENGTHSIZE),
+        async_read(socket_, asio::buffer(data_, TCP_MESSAGE_LENGTHSIZE),
                    boost::bind(&TCPClient::headerRead, this,
                                placeholders::error,
                                placeholders::bytes_transferred));
@@ -167,14 +155,14 @@
 
     tcp::socket& getSocket() { return (socket_); }
 
-    void headerRead(const boost::system::error_code& error,
+    void headerRead(const asio::error_code& error,
                     size_t bytes_transferred)
     {
         if (!error) {
             InputBuffer dnsbuffer(data_, bytes_transferred);
 
             uint16_t msglen = dnsbuffer.readUint16();
-            async_read(socket_, boost::asio::buffer(data_, msglen),
+            async_read(socket_, asio::buffer(data_, msglen),
 
                        boost::bind(&TCPClient::requestRead, this,
                                    placeholders::error,
@@ -184,7 +172,7 @@
         }
     }
 
-    void requestRead(const boost::system::error_code& error,
+    void requestRead(const asio::error_code& error,
                      size_t bytes_transferred)
     {
         if (!error) {
@@ -200,7 +188,7 @@
                                                 response_renderer_, false)) {
                     responselen_buffer_.writeUint16(response_buffer_.getLength());
                     async_write(socket_,
-                                boost::asio::buffer(
+                                asio::buffer(
                                     responselen_buffer_.getData(),
                                     responselen_buffer_.getLength()),
                                 boost::bind(&TCPClient::responseWrite, this,
@@ -216,10 +204,10 @@
         }
     }
 
-    void responseWrite(const boost::system::error_code& error) {
+    void responseWrite(const asio::error_code& error) {
         if (!error) {
                 async_write(socket_,
-                            boost::asio::buffer(response_buffer_.getData(),
+                            asio::buffer(response_buffer_.getData(),
                                                 response_buffer_.getLength()),
                         boost::bind(&TCPClient::handleWrite, this,
                                     placeholders::error));
@@ -228,7 +216,7 @@
         }
     }
 
-    void handleWrite(const boost::system::error_code& error) {
+    void handleWrite(const asio::error_code& error) {
         if (!error) {
             start();            // handle next request, if any.
       } else {
@@ -271,7 +259,7 @@
     ~TCPServer() { delete listening_; }
 
     void handleAccept(TCPClient* new_client,
-                      const boost::system::error_code& error)
+                      const asio::error_code& error)
     {
         if (!error) {
             assert(new_client == listening_);
@@ -304,7 +292,7 @@
         // Set v6-only (we use a different instantiation for v4,
         // otherwise asio will bind to both v4 and v6
         if (af == AF_INET6) {
-            socket_.set_option(boost::asio::ip::v6_only(true));
+            socket_.set_option(asio::ip::v6_only(true));
             socket_.bind(udp::endpoint(udp::v6(), port));
         } else {
             socket_.bind(udp::endpoint(udp::v4(), port));
@@ -312,7 +300,7 @@
         startReceive();
     }
 
-    void handleRequest(const boost::system::error_code& error,
+    void handleRequest(const asio::error_code& error,
                        size_t bytes_recvd)
     {
         if (!error && bytes_recvd > 0) {
@@ -323,7 +311,7 @@
             if (auth_server->processMessage(request_buffer, dns_message_,
                                             response_renderer_, true)) {
                 socket_.async_send_to(
-                    boost::asio::buffer(response_buffer_.getData(),
+                    asio::buffer(response_buffer_.getData(),
                                         response_buffer_.getLength()),
                     sender_endpoint_,
                     boost::bind(&UDPServer::sendCompleted,
@@ -338,7 +326,7 @@
         }
     }
 
-    void sendCompleted(const boost::system::error_code& error UNUSED_PARAM,
+    void sendCompleted(const asio::error_code& error UNUSED_PARAM,
                        size_t bytes_sent UNUSED_PARAM)
     {
         // Even if error occurred there's nothing to do.  Simply handle
@@ -348,7 +336,7 @@
 private:
     void startReceive() {
         socket_.async_receive_from(
-            boost::asio::buffer(data_, MAX_LENGTH), sender_endpoint_,
+            asio::buffer(data_, MAX_LENGTH), sender_endpoint_,
             boost::bind(&UDPServer::handleRequest, this,
                         placeholders::error,
                         placeholders::bytes_transferred));
@@ -400,296 +388,6 @@
     cout << "Server started." << endl;
     io_service_.run();
 }
-#else  // !HAVE_BOOST_SYSTEM
-struct SocketSet {
-    SocketSet() : ups4(-1), tps4(-1), ups6(-1), tps6(-1) {}
-    ~SocketSet() {
-        if (ups4 >= 0) {
-            close(ups4);
-        }
-        if (tps4 >= 0) {
-            close(tps4);
-        }
-        if (ups6 >= 0) {
-            close(ups6);
-        }
-        if (tps4 >= 0) {
-            close(tps6);
-        }
-    }
-    int ups4, tps4, ups6, tps6;
-};
-
-int
-getUDPSocket(int af, const char* port) {
-    struct addrinfo hints, *res;
-
-    memset(&hints, 0, sizeof(hints));
-    hints.ai_family = af;
-    hints.ai_socktype = SOCK_DGRAM;
-    hints.ai_flags = AI_PASSIVE;
-    hints.ai_protocol = IPPROTO_UDP;
-
-    int error = getaddrinfo(NULL, port, &hints, &res);
-    if (error != 0) {
-        isc_throw(FatalError, "getaddrinfo failed: " << gai_strerror(error));
-    }
-
-    int s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
-    if (s < 0) {
-        isc_throw(FatalError, "failed to open socket");
-    }
-
-    if (af == AF_INET6) {
-        int on = 1;
-        if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) {
-            cerr << "couldn't set IPV6_V6ONLY socket option" << endl;
-            // proceed anyway
-        }
-    }
-
-    if (bind(s, res->ai_addr, res->ai_addrlen) < 0) {
-        isc_throw(FatalError, "binding socket failure");
-    }
-
-    return (s);
-}
-
-int
-getTCPSocket(int af, const char* port) {
-    struct addrinfo hints, *res;
-
-    memset(&hints, 0, sizeof(hints));
-    hints.ai_family = af;
-    hints.ai_socktype = SOCK_STREAM;
-    hints.ai_flags = AI_PASSIVE;
-    hints.ai_protocol = IPPROTO_TCP;
-
-    int error = getaddrinfo(NULL, port, &hints, &res);
-    if (error != 0) {
-        isc_throw(FatalError, "getaddrinfo failed: " << gai_strerror(error));
-    }
-
-    int s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
-    if (s < 0) {
-        isc_throw(FatalError, "failed to open socket");
-    }
-
-    int on = 1;
-    if (af == AF_INET6) {
-        if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) {
-            cerr << "couldn't set IPV6_V6ONLY socket option" << endl;
-        }
-        // proceed anyway
-    }
-
-    if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) {
-        cerr << "couldn't set SO_REUSEADDR socket option" << endl;
-    }
-
-    if (bind(s, res->ai_addr, res->ai_addrlen) < 0) {
-        isc_throw(FatalError, "binding socket failure");
-    }
-
-    if (listen(s, 100) < 0) {
-        isc_throw(FatalError, "failed to listen on a TCP socket");
-    }
-    return (s);
-}
-
-void
-processMessageUDP(const int fd, Message& dns_message,
-                  MessageRenderer& response_renderer)
-{
-    struct sockaddr_storage ss;
-    socklen_t sa_len = sizeof(ss);
-    struct sockaddr* sa = static_cast<struct sockaddr*>((void*)&ss);
-    char recvbuf[4096];
-    int cc;
-
-    dns_message.clear(Message::PARSE);
-    response_renderer.clear();
-    if ((cc = recvfrom(fd, recvbuf, sizeof(recvbuf), 0, sa, &sa_len)) > 0) {
-        InputBuffer buffer(recvbuf, cc);
-        if (auth_server->processMessage(buffer, dns_message, response_renderer,
-                                        true)) {
-            cc = sendto(fd, response_renderer.getData(),
-                        response_renderer.getLength(), 0, sa, sa_len);
-            if (cc != response_renderer.getLength()) {
-                cerr << "UDP send error" << endl;
-            }
-        }
-    } else if (verbose_mode) {
-        cerr << "UDP receive error" << endl;
-    }
-}
-
-// XXX: this function does not handle partial reads or partial writes,
-//      and is VERY UNSAFE - will probably be removed or rewritten
-void
-processMessageTCP(const int fd, Message& dns_message,
-                  MessageRenderer& response_renderer)
-{
-    struct sockaddr_storage ss;
-    socklen_t sa_len = sizeof(ss);
-    struct sockaddr* sa = static_cast<struct sockaddr*>((void*)&ss);
-    char sizebuf[2];
-    int cc;
-
-    int ts = accept(fd, sa, &sa_len);
-    if (ts < 0) {
-        if (verbose_mode) {
-            cerr << "[XX] TCP accept failure:" << endl;
-            return;
-        }
-    }
-
-    if (verbose_mode) {
-        cerr << "[XX] process TCP" << endl;
-    }
-    cc = recv(ts, sizebuf, 2, 0);
-    if (cc < 0) {
-        if (verbose_mode) {
-            cerr << "[XX] TCP recv failure:" << endl;
-        }
-        close(ts);
-        return;
-    }
-    if (verbose_mode) {
-        cerr << "[XX] got: " << cc << endl;
-    }
-    uint16_t size, size_n;
-    memcpy(&size_n, sizebuf, 2);
-    size = ntohs(size_n);
-    if (verbose_mode) {
-        cerr << "[XX] got: " << size << endl;
-    }
-
-    vector<char> message_buffer;
-    message_buffer.reserve(size);
-    cc = 0;
-    while (cc < size) {
-        if (verbose_mode) {
-            cerr << "[XX] cc now: " << cc << " of " << size << endl;
-        }
-        const int cc0 = recv(ts, &message_buffer[0] + cc, size - cc, 0);
-        if (cc0 < 0) {
-            if (verbose_mode) {
-                cerr << "TCP receive error" << endl;
-                close(ts);
-                return;
-            }
-        }
-        if (cc0 == 0) {
-            // client closed connection
-            close(ts);
-            return;
-        }
-        cc += cc0;
-    }
-
-    InputBuffer buffer(&message_buffer[0], size);
-    dns_message.clear(Message::PARSE);
-    response_renderer.clear();
-    if (auth_server->processMessage(buffer, dns_message, response_renderer,
-                                    false)) {
-        size = response_renderer.getLength();
-        size_n = htons(size);
-        if (send(ts, &size_n, 2, 0) == 2) {
-            cc = send(ts, response_renderer.getData(),
-                      response_renderer.getLength(), 0);
-            if (cc == -1) {
-                if (verbose_mode) {
-                    cerr << "[AuthSrv] error in sending TCP response message" <<
-                        endl;
-                }
-            } else {
-                if (verbose_mode) {
-                    cerr << "[XX] sent TCP response: " << cc << " bytes"
-                         << endl;
-                }
-            }
-        } else {
-            if (verbose_mode) {
-                cerr << "TCP send error" << endl;
-            }
-        }
-    }
- 
-   // TODO: we don't check for more queries on the stream atm
-    close(ts);
-}
-
-void
-run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
-           AuthSrv* srv)
-{
-    SocketSet socket_set;
-    fd_set fds_base;
-    int nfds = -1;
-
-    FD_ZERO(&fds_base);
-    if (use_ipv4) {
-        socket_set.ups4 = getUDPSocket(AF_INET, port);
-        FD_SET(socket_set.ups4, &fds_base);
-        nfds = max(nfds, socket_set.ups4);
-        socket_set.tps4 = getTCPSocket(AF_INET, port);
-        FD_SET(socket_set.tps4, &fds_base);
-        nfds = max(nfds, socket_set.tps4);
-    }
-    if (use_ipv6) {
-        socket_set.ups6 = getUDPSocket(AF_INET6, port);
-        FD_SET(socket_set.ups6, &fds_base);
-        nfds = max(nfds, socket_set.ups6);
-        socket_set.tps6 = getTCPSocket(AF_INET6, port);
-        FD_SET(socket_set.tps6, &fds_base);
-        nfds = max(nfds, socket_set.tps6);
-    }
-    ++nfds;
-
-    cout << "Server started." << endl;
-    
-    if (srv->configSession() == NULL) {
-        isc_throw(FatalError, "Config session not initalized");
-    }
-
-    int ss = srv->configSession()->getSocket();
-    Message dns_message(Message::PARSE);
-    OutputBuffer resonse_buffer(0);
-    MessageRenderer response_renderer(resonse_buffer);
-
-    running = true;
-    while (running) {
-        fd_set fds = fds_base;
-        FD_SET(ss, &fds);
-        ++nfds;
-
-        int n = select(nfds, &fds, NULL, NULL, NULL);
-        if (n < 0) {
-            if (errno != EINTR) {
-                isc_throw(FatalError, "select error");
-            }
-            continue;
-        }
-
-        if (socket_set.ups4 >= 0 && FD_ISSET(socket_set.ups4, &fds)) {
-            processMessageUDP(socket_set.ups4, dns_message, response_renderer);
-        }
-        if (socket_set.ups6 >= 0 && FD_ISSET(socket_set.ups6, &fds)) {
-            processMessageUDP(socket_set.ups6, dns_message, response_renderer);
-        }
-        if (socket_set.tps4 >= 0 && FD_ISSET(socket_set.tps4, &fds)) {
-            processMessageTCP(socket_set.tps4, dns_message, response_renderer);
-        }
-        if (socket_set.tps6 >= 0 && FD_ISSET(socket_set.tps6, &fds)) {
-            processMessageTCP(socket_set.tps6, dns_message, response_renderer);
-        }
-        if (FD_ISSET(ss, &fds)) {
-            srv->configSession()->checkCommand();
-        }
-    }
-}
-#endif // HAVE_BOOST_SYSTEM
 
 void
 usage() {
@@ -752,12 +450,7 @@
         auth_server = new AuthSrv;
         auth_server->setVerbose(verbose_mode);
 
-#ifdef HAVE_BOOST_SYSTEM
-        ModuleCCSession cs(specfile, io_service_, my_config_handler,
-                           my_command_handler);
-#else
         ModuleCCSession cs(specfile, my_config_handler, my_command_handler);
-#endif
 
         auth_server->setConfigSession(&cs);
         auth_server->updateConfig(ElementPtr());

Modified: branches/trac168/src/lib/cc/session.cc
==============================================================================
--- branches/trac168/src/lib/cc/session.cc (original)
+++ branches/trac168/src/lib/cc/session.cc Thu May 20 01:26:23 2010
@@ -23,11 +23,12 @@
 #include <iostream>
 #include <sstream>
 
-#ifdef HAVE_BOOST_SYSTEM
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
-#include <boost/asio.hpp>
-#endif
+
+#include <asio.hpp>
+#include <asio/error_code.hpp>
+#include <asio/system_error.hpp>
 
 #include <exceptions/exceptions.h>
 
@@ -38,12 +39,10 @@
 using namespace isc::cc;
 using namespace isc::data;
 
-#ifdef HAVE_BOOST_SYSTEM
-// some of the boost::asio names conflict with socket API system calls
+// some of the asio names conflict with socket API system calls
 // (e.g. write(2)) so we don't import the entire boost::asio namespace.
-using boost::asio::io_service;
-using boost::asio::ip::tcp;
-#endif
+using asio::io_service;
+using asio::ip::tcp;
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -68,7 +67,6 @@
     std::string lname_;
 };
 
-#ifdef HAVE_BOOST_SYSTEM
 class ASIOSession : public SessionImpl {
 public:
     ASIOSession(io_service& io_service) :
@@ -82,7 +80,7 @@
     virtual void readData(void* data, size_t datalen);
     virtual void startRead(boost::function<void()> user_handler);
 private:
-    void internalRead(const boost::system::error_code& error,
+    void internalRead(const asio::error_code& error,
                       size_t bytes_transferred);
 
 private:
@@ -90,12 +88,12 @@
     tcp::socket socket_;
     uint32_t data_length_;
     boost::function<void()> user_handler_;
-    boost::system::error_code error_;
+    asio::error_code error_;
 };
 
 void
 ASIOSession::establish() {
-    socket_.connect(tcp::endpoint(boost::asio::ip::address_v4::loopback(),
+    socket_.connect(tcp::endpoint(asio::ip::address_v4::loopback(),
                                   9912), error_);
     if (error_) {
         isc_throw(SessionError, "Unable to connect to message queue");
@@ -111,8 +109,8 @@
 void
 ASIOSession::writeData(const void* data, size_t datalen) {
     try {
-        boost::asio::write(socket_, boost::asio::buffer(data, datalen));
-    } catch (const boost::system::system_error& boost_ex) {
+        asio::write(socket_, asio::buffer(data, datalen));
+    } catch (const asio::system_error& boost_ex) {
         isc_throw(SessionError, "ASIO write failed: " << boost_ex.what());
     }
 }
@@ -136,8 +134,8 @@
 void
 ASIOSession::readData(void* data, size_t datalen) {
     try {
-        boost::asio::read(socket_, boost::asio::buffer(data, datalen));
-    } catch (const boost::system::system_error& boost_ex) {
+        asio::read(socket_, asio::buffer(data, datalen));
+    } catch (const asio::system_error& boost_ex) {
         // to hide boost specific exceptions, we catch them explicitly
         // and convert it to SessionError.
         isc_throw(SessionError, "ASIO read failed: " << boost_ex.what());
@@ -148,15 +146,15 @@
 ASIOSession::startRead(boost::function<void()> user_handler) {
     data_length_ = 0;
     user_handler_ = user_handler;
-    async_read(socket_, boost::asio::buffer(&data_length_,
+    async_read(socket_, asio::buffer(&data_length_,
                                             sizeof(data_length_)),
                boost::bind(&ASIOSession::internalRead, this,
-                           boost::asio::placeholders::error,
-                           boost::asio::placeholders::bytes_transferred));
-}
-
-void
-ASIOSession::internalRead(const boost::system::error_code& error,
+                           asio::placeholders::error,
+                           asio::placeholders::bytes_transferred));
+}
+
+void
+ASIOSession::internalRead(const asio::error_code& error,
                           size_t bytes_transferred)
 {
     if (!error) {
@@ -170,7 +168,6 @@
         isc_throw(SessionError, "asynchronous read failed");
     }
 }
-#endif
 
 class SocketSession : public SessionImpl {
 public:
@@ -270,10 +267,8 @@
 Session::Session() : impl_(new SocketSession)
 {}
 
-#ifdef HAVE_BOOST_SYSTEM
 Session::Session(io_service& io_service) : impl_(new ASIOSession(io_service))
 {}
-#endif
 
 Session::~Session() {
     delete impl_;

Modified: branches/trac168/src/lib/cc/session.h
==============================================================================
--- branches/trac168/src/lib/cc/session.h (original)
+++ branches/trac168/src/lib/cc/session.h Thu May 20 01:26:23 2010
@@ -25,10 +25,8 @@
 
 #include "data.h"
 
-namespace boost {
 namespace asio {
 class io_service;
-}
 }
 
 namespace isc {
@@ -51,7 +49,7 @@
 
         public:
             Session();
-            Session(boost::asio::io_service& ioservice);
+            Session(asio::io_service& ioservice);
             ~Session();
 
             // XXX: quick hack to allow the user to watch the socket directly.

Modified: branches/trac168/src/lib/config/ccsession.cc
==============================================================================
--- branches/trac168/src/lib/config/ccsession.cc (original)
+++ branches/trac168/src/lib/config/ccsession.cc Thu May 20 01:26:23 2010
@@ -32,9 +32,7 @@
 #include <sstream>
 #include <cerrno>
 
-#ifdef HAVE_BOOST_SYSTEM
 #include <boost/bind.hpp>
-#endif
 #include <boost/foreach.hpp>
 
 #include <cc/data.h>
@@ -188,7 +186,6 @@
     return module_spec;
 }
 
-#ifdef HAVE_BOOST_SYSTEM
 void
 ModuleCCSession::startCheck() {
     // data available on the command channel.  process it in the synchronous
@@ -201,7 +198,7 @@
 
 ModuleCCSession::ModuleCCSession(
     std::string spec_file_name,
-    boost::asio::io_service& io_service,
+    asio::io_service& io_service,
     isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config),
     isc::data::ElementPtr(*command_handler)(
         const std::string& command, const isc::data::ElementPtr args)
@@ -213,7 +210,6 @@
     // register callback for asynchronous read
     session_.startRead(boost::bind(&ModuleCCSession::startCheck, this));
 }
-#endif
 
 ModuleCCSession::ModuleCCSession(
     std::string spec_file_name,

Modified: branches/trac168/src/lib/config/ccsession.h
==============================================================================
--- branches/trac168/src/lib/config/ccsession.h (original)
+++ branches/trac168/src/lib/config/ccsession.h Thu May 20 01:26:23 2010
@@ -24,10 +24,8 @@
 #include <cc/session.h>
 #include <cc/data.h>
 
-namespace boost {
 namespace asio {
 class io_service;
-}
 }
 
 namespace isc {
@@ -133,7 +131,7 @@
                     isc::data::ElementPtr(*command_handler)(const std::string& command, const isc::data::ElementPtr args) = NULL
                     ) throw (isc::cc::SessionError);
     ModuleCCSession(std::string spec_file_name,
-                    boost::asio::io_service& io_service,
+                    asio::io_service& io_service,
                     isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config) = NULL,
                     isc::data::ElementPtr(*command_handler)(const std::string& command, const isc::data::ElementPtr args) = NULL
                     ) throw (isc::cc::SessionError);

Modified: branches/trac168/src/lib/config/tests/fake_session.cc
==============================================================================
--- branches/trac168/src/lib/config/tests/fake_session.cc (original)
+++ branches/trac168/src/lib/config/tests/fake_session.cc Thu May 20 01:26:23 2010
@@ -23,12 +23,10 @@
 #include <iostream>
 #include <sstream>
 
-#ifdef HAVE_BOOST_SYSTEM
+#include <asio.hpp>
+
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
-#include <boost/asio.hpp>
-#endif
-
 #include <boost/foreach.hpp>
 
 #include <exceptions/exceptions.h>
@@ -40,12 +38,10 @@
 using namespace isc::cc;
 using namespace isc::data;
 
-#ifdef HAVE_BOOST_SYSTEM
-// some of the boost::asio names conflict with socket API system calls
-// (e.g. write(2)) so we don't import the entire boost::asio namespace.
-using boost::asio::io_service;
-using boost::asio::ip::tcp;
-#endif
+// some of the asio names conflict with socket API system calls
+// (e.g. write(2)) so we don't import the entire asio namespace.
+using asio::io_service;
+using asio::ip::tcp;
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -144,11 +140,9 @@
 {
 }
 
-#ifdef HAVE_BOOST_SYSTEM
 Session::Session(io_service& io_service UNUSED_PARAM)
 {
 }
-#endif
 
 Session::~Session() {
 }

Modified: branches/trac168/src/lib/config/tests/fake_session.h
==============================================================================
--- branches/trac168/src/lib/config/tests/fake_session.h (original)
+++ branches/trac168/src/lib/config/tests/fake_session.h Thu May 20 01:26:23 2010
@@ -25,10 +25,8 @@
 
 #include <cc/data.h>
 
-namespace boost {
 namespace asio {
 class io_service;
-}
 }
 
 // global variables so tests can insert
@@ -65,7 +63,7 @@
             // public so tests can inspect them
         
             Session();
-            Session(boost::asio::io_service& ioservice);
+            Session(asio::io_service& ioservice);
             ~Session();
 
             // XXX: quick hack to allow the user to watch the socket directly.

Modified: branches/trac168/src/lib/xfr/xfrout_client.cc
==============================================================================
--- branches/trac168/src/lib/xfr/xfrout_client.cc (original)
+++ branches/trac168/src/lib/xfr/xfrout_client.cc Thu May 20 01:26:23 2010
@@ -20,7 +20,7 @@
 #include "fd_share.h"
 #include "xfrout_client.h"
 
-using boost::asio::local::stream_protocol;
+using asio::local::stream_protocol;
 
 namespace isc {
 namespace xfr {

Modified: branches/trac168/src/lib/xfr/xfrout_client.h
==============================================================================
--- branches/trac168/src/lib/xfr/xfrout_client.h (original)
+++ branches/trac168/src/lib/xfr/xfrout_client.h Thu May 20 01:26:23 2010
@@ -19,7 +19,7 @@
 
 #include <string>
 
-#include <boost/asio.hpp>
+#include <asio.hpp>
 #include <exceptions/exceptions.h>
 
 namespace isc {
@@ -31,7 +31,7 @@
         isc::Exception(file, line, what) {}
 };
 
-using boost::asio::local::stream_protocol;
+using asio::local::stream_protocol;
 class XfroutClient {
 public:
     XfroutClient(const std::string& file):
@@ -43,7 +43,7 @@
                               uint16_t msg_len);
 
 private:
-    boost::asio::io_service io_service_;
+    asio::io_service io_service_;
     // The socket used to communicate with the xfrout server.
     stream_protocol::socket socket_;
     const std::string file_path_;




More information about the bind10-changes mailing list