Ticket #3702: patch

File patch, 8.5 KB (added by tianhao.qiu@…, 13 years ago)
  • boost/asio/ssl/detail/openssl_stream_service.hpp

     
    2121#include <boost/asio/detail/push_options.hpp>
    2222#include <cstddef>
    2323#include <climits>
    24 #include <memory>
    2524#include <boost/config.hpp>
    2625#include <boost/noncopyable.hpp>
    2726#include <boost/function.hpp>
    2827#include <boost/bind.hpp>
     28#include <boost/shared_ptr.hpp>
    2929#include <boost/asio/detail/pop_options.hpp>
    3030
    3131#include <boost/asio/error.hpp>
     
    5757      void (const boost::system::error_code&, size_t)> func_t;
    5858
    5959    base_handler(boost::asio::io_service& io_service)
    60       : op_(NULL)
    61       , io_service_(io_service)
     60      : io_service_(io_service)
    6261      , work_(io_service)
    6362    {}
    6463   
     
    6766      func_(error, size);
    6867    }
    6968       
    70     void set_operation(openssl_operation<Stream>* op) { op_ = op; }
    7169    void set_func(func_t func) { func_ = func; }
    7270
    73     ~base_handler()
    74     {
    75       delete op_;
    76     }
    77 
    7871  private:
    7972    func_t func_;
    80     openssl_operation<Stream>* op_;
    8173    boost::asio::io_service& io_service_;
    8274    boost::asio::io_service::work work_;
    8375  };  // class base_handler
     
    10193    Handler handler_;
    10294    void handler_impl(const boost::system::error_code& error, size_t size)
    10395    {
    104       std::auto_ptr<io_handler<Stream, Handler> > this_ptr(this);
    10596      handler_(error, size);
    10697    }
    10798  };  // class io_handler
     
    125116    Handler handler_;
    126117    void handler_impl(const boost::system::error_code& error, size_t)
    127118    {
    128       std::auto_ptr<handshake_handler<Stream, Handler> > this_ptr(this);
    129119      handler_(error);
    130120    }
    131121
     
    150140    Handler handler_;
    151141    void handler_impl(const boost::system::error_code& error, size_t)
    152142    {
    153       std::auto_ptr<shutdown_handler<Stream, Handler> > this_ptr(this);
    154143      handler_(error);
    155144    }
    156145  };  // class shutdown_handler
     
    244233  {
    245234    typedef handshake_handler<Stream, Handler> connect_handler;
    246235
    247     connect_handler* local_handler =
    248       new connect_handler(handler, get_io_service());
     236    boost::shared_ptr<connect_handler> local_handler(
     237      new connect_handler(handler, get_io_service()));
    249238
    250     openssl_operation<Stream>* op = new openssl_operation<Stream>
    251     (
    252       type == stream_base::client ?
    253         &ssl_wrap<mutex_type>::SSL_connect:
    254         &ssl_wrap<mutex_type>::SSL_accept,
    255       next_layer,
    256       impl->recv_buf,
    257       impl->ssl,
    258       impl->ext_bio,
    259       boost::bind
     239    boost::shared_ptr<openssl_operation<Stream> > op(
     240      new openssl_operation<Stream>
    260241      (
    261         &base_handler<Stream>::do_func,
    262         local_handler,
    263         boost::arg<1>(),
    264         boost::arg<2>()
    265       ),
    266       strand_
     242        type == stream_base::client ?
     243          &ssl_wrap<mutex_type>::SSL_connect:
     244          &ssl_wrap<mutex_type>::SSL_accept,
     245        next_layer,
     246        impl->recv_buf,
     247        impl->ssl,
     248        impl->ext_bio,
     249        boost::bind
     250        (
     251          &base_handler<Stream>::do_func,
     252          local_handler,
     253          boost::arg<1>(),
     254          boost::arg<2>()
     255        ),
     256        strand_
     257      )
    267258    );
    268     local_handler->set_operation(op);
    269259
    270260    strand_.post(boost::bind(&openssl_operation<Stream>::start, op));
    271261  }
     
    301291  {
    302292    typedef shutdown_handler<Stream, Handler> disconnect_handler;
    303293
    304     disconnect_handler* local_handler =
    305       new disconnect_handler(handler, get_io_service());
     294    boost::shared_ptr<disconnect_handler> local_handler(
     295      new disconnect_handler(handler, get_io_service()));
    306296
    307     openssl_operation<Stream>* op = new openssl_operation<Stream>
    308     (
    309       &ssl_wrap<mutex_type>::SSL_shutdown,
    310       next_layer,
    311       impl->recv_buf,
    312       impl->ssl,
    313       impl->ext_bio,
    314       boost::bind
     297    boost::shared_ptr<openssl_operation<Stream> > op(
     298      new openssl_operation<Stream>
    315299      (
    316         &base_handler<Stream>::do_func,
    317         local_handler,
    318         boost::arg<1>(),
    319         boost::arg<2>()
    320       ),
    321       strand_
     300        &ssl_wrap<mutex_type>::SSL_shutdown,
     301        next_layer,
     302        impl->recv_buf,
     303        impl->ssl,
     304        impl->ext_bio,
     305        boost::bind
     306        (
     307          &base_handler<Stream>::do_func,
     308          local_handler,
     309          boost::arg<1>(),
     310          boost::arg<2>()
     311        ),
     312        strand_
     313      )
    322314    );
    323     local_handler->set_operation(op);
    324315
    325316    strand_.post(boost::bind(&openssl_operation<Stream>::start, op));       
    326317  }
     
    367358  {
    368359    typedef io_handler<Stream, Handler> send_handler;
    369360
    370     send_handler* local_handler = new send_handler(handler, get_io_service());
     361    boost::shared_ptr<send_handler> local_handler(
     362      new send_handler(handler, get_io_service()));
    371363
    372364    std::size_t buffer_size = boost::asio::buffer_size(*buffers.begin());
    373365    if (buffer_size > max_buffer_size)
     
    378370          boost::asio::buffer_cast<const void*>(*buffers.begin()),
    379371          static_cast<int>(buffer_size));
    380372
    381     openssl_operation<Stream>* op = new openssl_operation<Stream>
    382     (
    383       send_func,
    384       next_layer,
    385       impl->recv_buf,
    386       impl->ssl,
    387       impl->ext_bio,
    388       boost::bind
     373    boost::shared_ptr<openssl_operation<Stream> > op(
     374      new openssl_operation<Stream>
    389375      (
    390         &base_handler<Stream>::do_func,
    391         local_handler,
    392         boost::arg<1>(),
    393         boost::arg<2>()
    394       ),
    395       strand_
     376        send_func,
     377        next_layer,
     378        impl->recv_buf,
     379        impl->ssl,
     380        impl->ext_bio,
     381        boost::bind
     382        (
     383          &base_handler<Stream>::do_func,
     384          local_handler,
     385          boost::arg<1>(),
     386          boost::arg<2>()
     387        ),
     388        strand_
     389      )
    396390    );
    397     local_handler->set_operation(op);
    398391
    399392    strand_.post(boost::bind(&openssl_operation<Stream>::start, op));       
    400393  }
     
    441434  {
    442435    typedef io_handler<Stream, Handler> recv_handler;
    443436
    444     recv_handler* local_handler = new recv_handler(handler, get_io_service());
     437    boost::shared_ptr<recv_handler> local_handler(
     438      new recv_handler(handler, get_io_service()));
    445439
    446440    std::size_t buffer_size = boost::asio::buffer_size(*buffers.begin());
    447441    if (buffer_size > max_buffer_size)
     
    452446          boost::asio::buffer_cast<void*>(*buffers.begin()),
    453447          static_cast<int>(buffer_size));
    454448
    455     openssl_operation<Stream>* op = new openssl_operation<Stream>
    456     (
    457       recv_func,
    458       next_layer,
    459       impl->recv_buf,
    460       impl->ssl,
    461       impl->ext_bio,
    462       boost::bind
     449    boost::shared_ptr<openssl_operation<Stream> > op(
     450      new openssl_operation<Stream>
    463451      (
    464         &base_handler<Stream>::do_func,
    465         local_handler,
    466         boost::arg<1>(),
    467         boost::arg<2>()
    468       ),
    469       strand_
     452        recv_func,
     453        next_layer,
     454        impl->recv_buf,
     455        impl->ssl,
     456        impl->ext_bio,
     457        boost::bind
     458        (
     459          &base_handler<Stream>::do_func,
     460          local_handler,
     461          boost::arg<1>(),
     462          boost::arg<2>()
     463        ),
     464        strand_
     465      )
    470466    );
    471     local_handler->set_operation(op);
    472467
    473468    strand_.post(boost::bind(&openssl_operation<Stream>::start, op));       
    474469  }
  • boost/asio/ssl/detail/openssl_operation.hpp

     
    2222#include <boost/assert.hpp>
    2323#include <boost/bind.hpp>
    2424#include <boost/asio/detail/pop_options.hpp>
     25#include <boost/enable_shared_from_this.hpp>
    2526
    2627#include <boost/asio/buffer.hpp>
    2728#include <boost/asio/placeholders.hpp>
     
    8081//
    8182template <typename Stream>
    8283class openssl_operation
     84  : public boost::enable_shared_from_this<openssl_operation<Stream> >
    8385{
    8486public:
    8587
     
    321323            boost::bind
    322324            (
    323325              &openssl_operation::async_write_handler,
    324               this,
     326              openssl_operation::shared_from_this(),
    325327              is_operation_done,
    326328              rc,
    327329              boost::asio::placeholders::error,
     
    386388        boost::bind
    387389        (
    388390          &openssl_operation::async_read_handler,
    389           this,
     391          openssl_operation::shared_from_this(),
    390392          boost::asio::placeholders::error,
    391393          boost::asio::placeholders::bytes_transferred
    392394        )