Browse Source

[5189] Reverted changes in libkea-http.

Marcin Siodelski 8 years ago
parent
commit
05a38f2387
3 changed files with 16 additions and 19 deletions
  1. 8 15
      src/lib/http/connection.cc
  2. 6 0
      src/lib/http/connection.h
  3. 2 4
      src/lib/http/listener.cc

+ 8 - 15
src/lib/http/connection.cc

@@ -34,6 +34,10 @@ HttpConnection:: HttpConnection(asiolink::IOService& io_service,
     : request_timer_(io_service),
       request_timeout_(request_timeout),
       socket_(io_service),
+      socket_callback_(boost::bind(&HttpConnection::socketReadCallback, this,
+                                   _1, _2)),
+      socket_write_callback_(boost::bind(&HttpConnection::socketWriteCallback,
+                                         this, _1, _2)),
       acceptor_(acceptor),
       connection_pool_(connection_pool),
       response_creator_(response_creator),
@@ -68,7 +72,7 @@ HttpConnection::stopThisConnection() {
 void
 HttpConnection::asyncAccept() {
     HttpAcceptorCallback cb = boost::bind(&HttpConnection::acceptorCallback,
-                                          shared_from_this(), _1);
+                                          this, _1);
     try {
         acceptor_.asyncAccept(socket_, cb);
 
@@ -82,10 +86,8 @@ void
 HttpConnection::doRead() {
     try {
         TCPEndpoint endpoint;
-        SocketCallback cb(boost::bind(&HttpConnection::socketReadCallback,
-                                      shared_from_this(), _1, _2));
         socket_.asyncReceive(static_cast<void*>(buf_.data()), buf_.size(),
-                             0, &endpoint, cb);
+                             0, &endpoint, socket_callback_);
 
     } catch (const std::exception& ex) {
         stopThisConnection();
@@ -96,11 +98,9 @@ void
 HttpConnection::doWrite() {
     try {
         if (!output_buf_.empty()) {
-            SocketCallback cb(boost::bind(&HttpConnection::socketWriteCallback,
-                                          shared_from_this(), _1, _2));
             socket_.asyncSend(output_buf_.data(),
                               output_buf_.length(),
-                              cb);
+                              socket_write_callback_);
         } else {
             stopThisConnection();
         }
@@ -118,12 +118,6 @@ HttpConnection::asyncSendResponse(const ConstHttpResponsePtr& response) {
 
 void
 HttpConnection::acceptorCallback(const boost::system::error_code& ec) {
-    // Operation is aborted when the acceptor is cancelled, as a result
-    // of stopping the connection. This is not an error condition.
-    if (ec.value() == boost::asio::error::operation_aborted) {
-        return;
-    }
-
     if (!acceptor_.isOpen()) {
         return;
     }
@@ -139,8 +133,7 @@ HttpConnection::acceptorCallback(const boost::system::error_code& ec) {
                   HTTP_REQUEST_RECEIVE_START)
             .arg(getRemoteEndpointAddressAsText())
             .arg(static_cast<unsigned>(request_timeout_/1000));
-        request_timer_.setup(boost::bind(&HttpConnection::requestTimeoutCallback,
-                                         shared_from_this()),
+        request_timer_.setup(boost::bind(&HttpConnection::requestTimeoutCallback, this),
                              request_timeout_, IntervalTimer::ONE_SHOT);
         doRead();
     }

+ 6 - 0
src/lib/http/connection.h

@@ -187,6 +187,12 @@ private:
     /// @brief Socket used by this connection.
     asiolink::TCPSocket<SocketCallback> socket_;
 
+    /// @brief Callback invoked when data received over the socket.
+    SocketCallback socket_callback_;
+
+    /// @brief Callback invoked when data sent over the socket.
+    SocketCallback socket_write_callback_;
+
     /// @brief Reference to the TCP acceptor used to accept new connections.
     HttpAcceptor& acceptor_;
 

+ 2 - 4
src/lib/http/listener.cc

@@ -10,9 +10,7 @@
 #include <http/connection_pool.h>
 #include <http/http_acceptor.h>
 #include <http/listener.h>
-#include <boost/enable_shared_from_this.hpp>
 #include <boost/scoped_ptr.hpp>
-#include <iostream>
 
 using namespace isc::asiolink;
 
@@ -20,7 +18,7 @@ namespace isc {
 namespace http {
 
 /// @brief Implementation of the @ref HttpListener.
-class HttpListenerImpl : public boost::enable_shared_from_this<HttpListenerImpl> {
+class HttpListenerImpl {
 public:
 
     /// @brief Constructor.
@@ -166,7 +164,7 @@ HttpListenerImpl::accept() {
     // depends on the use case.
     HttpResponseCreatorPtr response_creator = creator_factory_->create();
     HttpAcceptorCallback acceptor_callback =
-        boost::bind(&HttpListenerImpl::acceptHandler, shared_from_this(), _1);
+        boost::bind(&HttpListenerImpl::acceptHandler, this, _1);
     HttpConnectionPtr conn(new HttpConnection(io_service_, acceptor_,
                                               connections_,
                                               response_creator,