[Boost-bugs] [Boost C++ Libraries] #13086: Exception Throw -> { boost::asio::ip::tcp::aceptor * acceptor->open(); }

Subject: [Boost-bugs] [Boost C++ Libraries] #13086: Exception Throw -> { boost::asio::ip::tcp::aceptor * acceptor->open(); }
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-06-20 15:01:48


#13086: Exception Throw -> { boost::asio::ip::tcp::aceptor * acceptor->open(); }
---------------------------------+----------------------------
 Reporter: ya.tarakanov.ilya@… | Owner: chris_kohlhoff
     Type: Support Requests | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.63.0 | Severity: Problem
 Keywords: |
---------------------------------+----------------------------
 {{{
 asio.h
 #include "boost/asio.hpp"

 struct SNetGlobal
 {
         static boost::asio::io_service * GetStcIOService();
         static bool RunIOServiceInThreads(int nCountThr = 1);
 };

 asio.cpp
 #include "asio.h"
 #include <vector>
 #include <thread>

 static boost::asio::io_service * s_io_service = NULL;

 static std::vector<std::thread> s_thread_pool;

 io_service * SNetGlobal::GetStcIOService()
 {
         if (!s_io_service)
         {
                 s_io_service = new io_service;
         }
         return s_io_service;
 }

 bool SNetGlobal::RunIOServiceInThreads(int nCountThr)
 {
         while (nCountThr--)
         {
                 s_thread_pool.emplace_back([=] { s_io_service->run(); });
         }
         return true;
 }

 listener.h
         class CUCListener
         {
         public:
                 void Start();
                 void OnAccept(const boost::system::error_code & ec);
         private:
                 tcp::acceptor * m_pAcceptor;
                 tcp::socket * m_pSocket;
         };

 listener.cpp
 #include "asio.h"
 #include "listener.h"

 void CUCListener ::Start()
 {
 tcp::endpoint endpoint(tcp::v4(), 1974);
 m_pAcceptor = new tcp::aceptor(*SNetGlobal::GetStcIOService());
 m_pAcceptor->open(endpoint.protocol());
 m_pAcceptor->set_option(tcp::acceptor::reuse_address(true));
 m_pAcceptor->bind(endpoint);
 m_pAcceptor->listen();
 m_pAcceptor->async_accept(*m_pSocket, boost::bind(&CUCListener::OnAccept,
 this, boost::asio::placeholders::error));
 SNetGlobal::RunIOServiceInThreads();
 }

 void CUCListener::OnAccept(const boost::system::error_code & ec)
 {
         std::cout << "Accept Success" << std::endl;
 }
 }}}

 Hi, sometimes throw exception and function CUCListener::OnAccept not
 called when connected

 socket_ops.ipp

 {{{
 socket_type socket(int af, int type, int protocol,
     boost::system::error_code& ec)
 {
   clear_last_error();
 #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
   socket_type s = error_wrapper(::WSASocketW(af, type, protocol, 0, 0,
         WSA_FLAG_OVERLAPPED), ec); // Exception Throw
   if (s == invalid_socket)
     return s;
 ...
 }

 }}}

--
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13086>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-06-20 15:07:12 UTC