我创建了客户端应用程序。当我发送单个消息 client <=> sever 时它工作正常。但是当我出于性能目的发送大量消息时,客户端会以两种不同的方式崩溃:
(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 (sig=sig@entry=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 (sig=sig@entry=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, descriptor_data=@0x7fffffffe2b8: 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, descriptor_data=@0x7fffffffe2b8: 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)
在 boost asio 套接字中似乎发生了崩溃,但我不确定发生了什么。我试图将所有 boost::asio 命令放入 try block 中,但看起来异常来自套接字线程。 这是 ma 套接字实现的一部分:
#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;
}
如有任何帮助,我将不胜感激。
=>最佳答案
socket_.close();
运行时抛出异常!
您可以使用 boost::system::error_code 来正确捕捉错误:
boost::system::error_code lErrorCode;
socket_.close(lErrorCode);
std::cout << lErrorCode.message() << std::endl;
关于c++ - 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40266238/
我正在使用这个:4.times{|i|assert_not_equal("content#{i+2}".constantize,object.first_content)}我之前声明过局部变量content1content2content3content4content5我得到的错误NameError:wrongconstantnamecontent2这个错误是什么意思?我很确定我想要content2=\ 最佳答案 你必须用一个大字母来调用ruby常量:Content2而不是content2。Aconstantnamestart
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe
我使用Nokogiri(Rubygem)css搜索寻找某些在我的html里面。看起来Nokogiri的css搜索不喜欢正则表达式。我想切换到Nokogiri的xpath搜索,因为这似乎支持搜索字符串中的正则表达式。如何在xpath搜索中实现下面提到的(伪)css搜索?require'rubygems'require'nokogiri'value=Nokogiri::HTML.parse(ABBlaCD3"HTML_END#my_blockisgivenmy_bl="1"#my_eqcorrespondstothisregexmy_eq="\/[0-9]+\/"#FIXMEThefoll
我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我
我在一个我想在formtasticGem中覆盖的方法中找到了这个。该方法如下所示:defto_htmlinput_wrappingdohidden_field_html是什么意思?在第三行做什么?我知道它对数组有什么作用,但在这里我不知道。 最佳答案 你可以这样读:hidden_field_htmllabel_with_nested_checkbox是连接到hidden_field_html末尾的参数-为了“清晰”,他们将其分成两行 关于ruby-on-rails-没有参数的`