2016-10-26 184 views
2

我創建了客戶端應用程序。它在我發送單個消息客戶端< =>服務器時正常工作。但是,當我送了很多用於提高性能的目的客戶端崩潰的消息有兩種不同的方式:'boost :: exception_detail :: clone_impl <boost :: exception_detail :: error_info_injector <boost :: system :: system_error>>

(gdb) run 
Starting program: /home/x64joxer/workerGenerators/Worker2/worker -t -i 192.168.0.6 -p 6000 -d 5 -l //home/x64joxer/workerGenerators/Worker2/ 
[Thread debugging using libthread_db enabled] 
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >' 
    what(): set_option: Bad file descriptor 
[New Thread 0x7fffe77fe700 (LWP 19310)] 
[New Thread 0x7ffff4f24700 (LWP 18720)] 
[New Thread 0x7fffe7fff700 (LWP 18148)] 
[New Thread 0x7ffff5725700 (LWP 17582)] 
[New Thread 0x7ffff5f26700 (LWP 16613)] 
[New Thread 0x7ffff6727700 (LWP 16612)] 

Program received signal SIGABRT, Aborted. 
[Switching to Thread 0x7ffff5f26700 (LWP 16613)] 
0x00007ffff6965267 in __GI_raise ([email protected]=6) at ../sysdeps/unix/sysv/linux/raise.c:55 
55  ../sysdeps/unix/sysv/linux/raise.c: Nie ma takiego pliku ani katalogu. 
(gdb) bt 
#0 0x00007ffff6965267 in __GI_raise ([email protected]=6) at ../sysdeps/unix/sysv/linux/raise.c:55 
#1 0x00007ffff6966eca in __GI_abort() at abort.c:89 
#2 0x00007ffff749706d in __gnu_cxx::__verbose_terminate_handler()() from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 
#3 0x00007ffff7494ee6 in ??() from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 
#4 0x00007ffff7494f31 in std::terminate()() from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 
#5 0x00007ffff74f0ec1 in ??() from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 
#6 0x00007ffff6d016aa in start_thread (arg=0x7ffff5f26700) at pthread_create.c:333 
#7 0x00007ffff6a36eed in clone() at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109 





(gdb) run 
Starting program: /home/x64joxer/workerGenerators/Worker4/worker -t -i 192.168.0.6 -p 6000 -d 5 -l //home/x64joxer/workerGenerators/Worker4/ 
[Thread debugging using libthread_db enabled] 
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 
[New Thread 0x7ffff4f24700 (LWP 17302)] 
[New Thread 0x7ffff5f26700 (LWP 16583)] 
[New Thread 0x7ffff6727700 (LWP 16582)] 

Program received signal SIGSEGV, Segmentation fault. 
[Switching to Thread 0x7ffff6727700 (LWP 16582)] 
0x000000000044b902 in boost::asio::detail::epoll_reactor::deregister_descriptor (this=0x6a1a10, descriptor=6, [email protected]: 0x6a0d20, closing=true) at /usr/include/boost/asio/detail/impl/epoll_reactor.ipp:309 
309  /usr/include/boost/asio/detail/impl/epoll_reactor.ipp: Nie ma takiego pliku ani katalogu. 
(gdb) by 
Undefined command: "by". Try "help". 
(gdb) bt 
#0 0x000000000044b902 in boost::asio::detail::epoll_reactor::deregister_descriptor (this=0x6a1a10, descriptor=6, [email protected]: 0x6a0d20, closing=true) at /usr/include/boost/asio/detail/impl/epoll_reactor.ipp:309 
#1 0x000000000044ecc0 in boost::asio::detail::reactive_socket_service_base::close (this=0x6a11f8, impl=..., ec=...) at /usr/include/boost/asio/detail/impl/reactive_socket_service_base.ipp:104 
#2 0x000000000045476e in boost::asio::stream_socket_service<boost::asio::ip::tcp>::close (this=0x6a11d0, impl=..., ec=...) at /usr/include/boost/asio/stream_socket_service.hpp:170 
#3 0x0000000000452d60 in boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >::close (this=0x7fffffffe2b0) at /usr/include/boost/asio/basic_socket.hpp:356 
#4 0x0000000000449556 in TCPSocketBody::DoClose (this=0x7fffffffe260) at TCP/TCPSocketBody.cpp:158 
#5 0x000000000045afbd in boost::_mfi::mf0<void, TCPSocketBody>::operator() (this=0x7ffff6726be0, p=0x7fffffffe260) at /usr/include/boost/bind/mem_fn_template.hpp:49 
#6 0x000000000045a77a in boost::_bi::list1<boost::_bi::value<TCPSocketBody*> >::operator()<boost::_mfi::mf0<void, TCPSocketBody>, boost::_bi::list0> (this=0x7ffff6726bf0, f=..., a=...) at /usr/include/boost/bind/bind.hpp:253 
#7 0x0000000000459986 in boost::_bi::bind_t<void, boost::_mfi::mf0<void, TCPSocketBody>, boost::_bi::list1<boost::_bi::value<TCPSocketBody*> > >::operator() (this=0x7ffff6726be0) at /usr/include/boost/bind/bind_template.hpp:20 
#8 0x0000000000458bef in boost::asio::asio_handler_invoke<boost::_bi::bind_t<void, boost::_mfi::mf0<void, TCPSocketBody>, boost::_bi::list1<boost::_bi::value<TCPSocketBody*> > > > (function=...) 
    at /usr/include/boost/asio/handler_invoke_hook.hpp:69 
#9 0x0000000000457b77 in boost_asio_handler_invoke_helpers::invoke<boost::_bi::bind_t<void, boost::_mfi::mf0<void, TCPSocketBody>, boost::_bi::list1<boost::_bi::value<TCPSocketBody*> > >, boost::_bi::bind_t<void, boost::_mfi::mf0<void, TCPSocketBody>, boost::_bi::list1<boost::_bi::value<TCPSocketBody*> > > > (function=..., context=...) at /usr/include/boost/asio/detail/handler_invoke_helpers.hpp:37 
#10 0x0000000000456747 in boost::asio::detail::completion_handler<boost::_bi::bind_t<void, boost::_mfi::mf0<void, TCPSocketBody>, boost::_bi::list1<boost::_bi::value<TCPSocketBody*> > > >::do_complete (owner=0x6a1960, 
    base=0x7fffe8001c70) at /usr/include/boost/asio/detail/completion_handler.hpp:68 
#11 0x000000000044a744 in boost::asio::detail::task_io_service_operation::complete (this=0x7fffe8001c70, owner=..., ec=..., bytes_transferred=0) at /usr/include/boost/asio/detail/task_io_service_operation.hpp:38 
#12 0x000000000044d102 in boost::asio::detail::task_io_service::do_run_one (this=0x6a1960, lock=..., this_thread=..., ec=...) at /usr/include/boost/asio/detail/impl/task_io_service.ipp:384 
#13 0x000000000044cb23 in boost::asio::detail::task_io_service::run (this=0x6a1960, ec=...) at /usr/include/boost/asio/detail/impl/task_io_service.ipp:153 
#14 0x000000000044d4d4 in boost::asio::io_service::run (this=0x7fffffffe2a0) at /usr/include/boost/asio/impl/io_service.ipp:59 
#15 0x000000000045c575 in boost::_mfi::mf0<unsigned long, boost::asio::io_service>::operator() (this=0x6a1008, p=0x7fffffffe2a0) at /usr/include/boost/bind/mem_fn_template.hpp:49 
#16 0x000000000045c4bb in boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> >::operator()<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list0> (this=0x6a1018, f=..., a=...) 
    at /usr/include/boost/bind/bind.hpp:243 
#17 0x000000000045c2aa in boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >::operator() (this=0x6a1008) 
    at /usr/include/boost/bind/bind_template.hpp:20 
#18 0x000000000045bf84 in boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::run (this=0x6a0e50) 
    at /usr/include/boost/thread/detail/thread.hpp:117 
#19 0x00007ffff79c809a in ??() from /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.55.0 
#20 0x00007ffff6d016aa in start_thread (arg=0x7ffff6727700) at pthread_create.c:333 
#21 0x00007ffff6a36eed in clone() at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109 
(gdb) 

它看起來像是在升壓ASIO插座崩潰,但我不知道發生了什麼。我嘗試將所有boost :: asio命令放入try塊中,但它看起來像是從套接字線程中出現異常。 這裏是馬雲套接字實現的一部分:

#include "TCPSocketBody.h" 

TCPSocketBody::TCPSocketBody() : socket_(io_service_global), 
           resolver(io_service_global), 
           connected(false), 
           expectedMessage(0) 
{ 
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: TCPSocketBody::TCPSocketBody(const std::string &adress, const std::string &port)"; 

    data_to_read = new char[MessageCoder::MaxMessageSize()]; 
} 

void TCPSocketBody::Close() 
{ 
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: void TCPSocketBody::Close()"; 

    io_service_global.post(boost::bind(&TCPSocketBody::DoClose, this)); 
} 

void TCPSocketBody::Connect(const std::string &adress, const std::string &port) 
{ 
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: void TCPSocketBody::Connect(const std::string &adress, const std::string &port)"; 

    io_service_global.reset(); 

    iterator = resolver.resolve({adress, port}); 

    boost::asio::async_connect(socket_, iterator, 
      boost::bind(&TCPSocketBody::HandleConnect, this, 
      boost::asio::placeholders::error));  

    socket_.set_option(boost::asio::ip::tcp::no_delay(true)); 
    socket_.set_option(boost::asio::socket_base::send_buffer_size(65536)); 
    socket_.set_option(boost::asio::socket_base::receive_buffer_size(65536)); 

    boost::thread(boost::bind(&boost::asio::io_service::run, &io_service_global)); 
} 

void TCPSocketBody::HandleConnect(const boost::system::error_code& error) 
{ 
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: void TCPSocketBody::HandleConnect(const boost::system::error_code& error)"; 

    if (!error) 
    {   
     connected = true; 

     Message tempMessage; 
     char *buffer = new char[MessageCoder::MaxMessageConnectedSize()]; 
     MessageCoder::ClearChar(buffer, MessageCoder::MaxMessageConnectedSize()); 
     MessageCoder::CreateConnectedMessage(buffer); 
     tempMessage.CopyWsk(meWsk, buffer); 
     messageQueue->PushBack(tempMessage); 

     TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: Sending Connected message to queue: " << buffer; 

     boost::asio::async_read(socket_, 
     boost::asio::buffer(data_to_read, MessageCoder::BufferSize()), boost::asio::transfer_all(), 
     boost::bind(&TCPSocketBody::HandleReadHeader, this, 
      boost::asio::placeholders::error)); 

    } else 
    { 
     Traces() << "\n" << "ERR: Connection error!"; 
     Close(); 
    } 
} 

void TCPSocketBody::HandleReadHeader(const boost::system::error_code& error) 
{ 
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: void TCPSocketBody::HandleReadHeader(const boost::system::error_code& error)"; 

    expectedMessage = MessageCoder::HeaderToVal(data_to_read);  

    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: Expecting message with lenn: " << expectedMessage; 

    if (expectedMessage > MessageCoder::MaxMessageSize()) 
    { 
     //TO_DO Traces() << "\n" << "ERR: Protocol error. Message too long:" << std::string(data_to_read); 
     //TO_DO expectedMessage = 0; 
     //TO_DO Close(); 
     expectedMessage = 0; 

     boost::asio::async_read(socket_, 
      boost::asio::buffer(data_to_read, MessageCoder::BufferSize()), boost::asio::transfer_all(), 
      boost::bind(&TCPSocketBody::HandleReadHeader, this, 
      boost::asio::placeholders::error)); 
    } else 
    { 
     boost::asio::async_read(socket_, 
      boost::asio::buffer(data_to_read, expectedMessage), boost::asio::transfer_all(), 
      boost::bind(&TCPSocketBody::HandleReadMessage, this, 
      boost::asio::placeholders::error)); 
    } 
} 

void TCPSocketBody::HandleReadMessage(const boost::system::error_code& error) 
{ 
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: void TCPSocketBody::HandleReadMessage(const boost::system::error_code& error)"; 

    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: Message received: " << std::string(data_to_read); 

    Message tempMessage; 
    tempMessage.CopyData(meWsk, data_to_read); 
    messageQueue->PushBack(tempMessage); 
    expectedMessage = 0;   

    boost::asio::async_read(socket_, 
     boost::asio::buffer(data_to_read, MessageCoder::BufferSize()), boost::asio::transfer_all(), 
     boost::bind(&TCPSocketBody::HandleReadHeader, this, 
     boost::asio::placeholders::error)); 
} 

void TCPSocketBody::WriteMessage(char *dataToSend) 
{ 
    io_service_global.post(boost::bind(&TCPSocketBody::Write, this, dataToSend)); 
} 

void TCPSocketBody::Write(char *dataToSend) 
{ 
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: void TCPSocketBody::Write(char *dataToSend)"; 

    writeMutex.lock(); 
    data = dataToSend; 

    boost::asio::async_write(socket_, 
     boost::asio::buffer(data, std::strlen(data)), 
     boost::bind(&TCPSocketBody::HandleWrite, this, 
      boost::asio::placeholders::error)); 

} 

void TCPSocketBody::HandleWrite(const boost::system::error_code& error) 
{ 
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: void TCPSocketBody::HandleWrite(const boost::system::error_code& error)"; 

    writeMutex.unlock(); 

    if (!error) 
    { 

     /*boost::asio::async_write(socket_, 
      boost::asio::buffer(data, 
      std::strlen(data)), 
      boost::bind(&TCPSocketBody::HandleWrite, this, 
      boost::asio::placeholders::error));*/ 
    } 
    else 
    { 
     Traces() << "\n" << "ERR: Write error!"; 
     Close(); 
    } 
} 

void TCPSocketBody::DoClose() 
{ 
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() << "\n" << "LOG: void TCPSocketBody::DoClose()"; 

    socket_.close(); 
    connected = false; 
    Message tempMessage; 
    char *buffer = new char[MessageCoder::MaxMessageConnectionCloseSize()]; 
    MessageCoder::ClearChar(buffer, MessageCoder::MaxMessageConnectionCloseSize()); 
    MessageCoder::CreateCloseConnectionMessage(buffer); 
    tempMessage.CopyWsk(meWsk, buffer); 
    messageQueue->PushBack(tempMessage); 

} 

TCPSocketBody::~TCPSocketBody() 
{ 
    delete [] data_to_read; 
} 

我會感謝任何幫助。

回答

相關問題