服务器出现段错误
情况这样:当客户端连接数达到1152个时,服务器此时崩溃,出现段错误提示,后来用core来调试,有以下信息,不知是何原导致程序出现段错误。Reading symbols from /lib/tls/librt.so.1...done.
Loaded symbols for /lib/tls/librt.so.1
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
#00x004ab618 in ACE::record_and_set_non_blocking_mode ()
from /opt/project/dcc/ACE_wrappers/lib/libACE.so.5.5.0
(gdb) where
#00x004ab618 in ACE::record_and_set_non_blocking_mode ()
from /opt/project/dcc/ACE_wrappers/lib/libACE.so.5.5.0
#10x004cb38a in ACE::enter_recv_timedwait (handle=1153, timeout=0xb7f23c50, val=@0xb7f23bd8)
at ACE.cpp:2317
#20x004cc289 in ACE::recv (handle=1153, buf=0xb7f23c60, len=19, flags=16384, timeout=0x2)
at ACE.cpp:476
#30x0804f9ba in ACE_SOCK_IO::recv ()
#40x0804f04e in Server::handle_input ()
#50x004f197f in ACE_Dev_Poll_Reactor::dispatch_io_event (this=0xb7f24230, guard=@0xb7f24150)
at /opt/project/dcc/ACE_wrappers/ace/Dev_Poll_Reactor.inl:180
#60x004f3b06 in ACE_Dev_Poll_Reactor::dispatch (this=0xb7f24230, guard=@0xb7f24150)
at Dev_Poll_Reactor.cpp:1237
#70x004f3bf4 in ACE_Dev_Poll_Reactor::handle_events_i (this=0xb7f24230, max_wait_time=0x0,
guard=@0xb7f24150) at Dev_Poll_Reactor.cpp:1211
#80x004f3c8a in ACE_Dev_Poll_Reactor::handle_events (this=0xb7f24230, max_wait_time=0x0)
at Dev_Poll_Reactor.cpp:1166
#90x0052bc6c in ACE_Reactor::run_reactor_event_loop (this=0xb7f24220, eh=0) at Reactor.cpp:233
#10 0x0804f5f9 in server_worker ()
#11 0x0053e89e in ACE_Thread_Adapter::invoke_i (this=0x9c27688) at Thread_Adapter.cpp:151
#12 0x0053e805 in ACE_Thread_Adapter::invoke (this=0x9c27688) at Thread_Adapter.cpp:95
#13 0x004dee1b in ace_thread_adapter (args=0xffffffff) at Base_Thread_Adapter.cpp:137
#14 0x003e53cc in start_thread () from /lib/tls/libpthread.so.0
#15 0x0025ef0e in clone () from /lib/tls/libc.so.6 能贴一些代码吗? 本帖最后由 manlianmu 于 2012-10-12 08:55 编辑
winston 发表于 2012-10-11 16:43 static/image/common/back.gif
能贴一些代码吗?
可以,
int Server::handle_input(ACE_HANDLE)
{
char buffer; // Insure a trailing nul
ssize_t bytes_read = 0;
bytes_read = this->peer ().recv (buffer,20);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Received Message bytes_read = %d\n"),
bytes_read));
/*新增非阻塞处理新情况*/
if(bytes_read == -1)//出错
{
if(errno == EWOULDBLOCK)//非阻塞只需判断EWOULDBLOCK
{
return 0;
}
else
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("Server::handle_input")),
-1);
}
else if (bytes_read == 0)//连接关闭,停止接收
return -1;
return 0;
}
int Server::handle_close(ACE_HANDLE handle,
ACE_Reactor_Mask mask)
{
ACE_DEBUG ((LM_INFO,
ACE_TEXT ("(%t) Server Svc_Handler closing ")
ACE_TEXT ("handle <%d,%d> with reactor mask <0x%x>.\n"),
handle,
this->get_handle (),
mask));
this->peer ().close ();
return 0;
}
int DemoAcceptor::accept_svc_handler (Server *handler)
{
int result = this->MyAcceptor::accept_svc_handler (handler);
if (result != 0)
{
if (errno != EWOULDBLOCK)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("Unable to accept connection")));
return result;
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) Accepted connection.")
ACE_TEXT ("Stream handle: <%d>\n"),
handler->get_handle ()));
return result;
}
/*开个服务器+接收器线程工作*/
ACE_THR_FUNC_RETURN server_worker(void *p)
{
const unsigned short port = *(static_cast<unsigned short *> (p));
ACE_INET_Addr addr;
if(addr.set(port,INADDR_LOOPBACK)!=0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("server_worker - ACE_INET_Addr::set")));
return (void *) -1;
}
DemoPollReactor dp_reactor(10010);//EPOLL ,此时ET模式,//最大允许的连接数,可调整
dp_reactor.restart(1);
ACE_Reactor reactor(&dp_reactor);
DemoAcceptor server;
int flags = 0;
ACE_SET_BITS(flags,ACE_NONBLOCK);//非阻塞
if(server.open(addr,&reactor,flags)!=0)//监听
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("Unable to open server service handler")));
return (void *) -1;
}
if (reactor.run_reactor_event_loop () != 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("Error when running server ")
ACE_TEXT ("reactor event loop")));
return (void *) -1;
}
ACE_DEBUG ((LM_INFO,
ACE_TEXT ("(%t) Reactor event loop finished ")
ACE_TEXT ("successfully.\n")));
return 0;
}
int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
{
unsigned short port = 23234;
// Server server;
// server.open(0);
ACE_DEBUG((LM_DEBUG,"open after!\n"));
if(ACE_Thread_Manager::instance()->spawn(server_worker,&port)==-1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("Unable to spawn server thread")),
-1);
if (ACE_Thread_Manager::instance ()->wait () != 0)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("Error waiting for threads to complete")),
-1);
return 0;
} 问题解决了没?
recv中没有超时信息,为什么会有超时时间?
#10x004cb38a in ACE::enter_recv_timedwait (handle=1153, timeout=0xb7f23c50, val=@0xb7f23bd8)
at ACE.cpp:2317
#20x004cc289 in ACE::recv (handle=1153, buf=0xb7f23c60, len=19, flags=16384, timeout=0x2)
at ACE.cpp:476
而且timeout值还不同?
页:
[1]