thrift中的TNonblockingServer在TFramedTransport打开时崩溃

2024-10-01 11:30:13 发布

您现在位置:Python中文网/ 问答频道 /正文

<>我一直试图在C++中实现一个节省服务器与Python客户端通信。在

这是我的代码:

C++服务器:

shared_ptr<ThriftHandler> _handler (new myHandler());
shared_ptr<TProcessor> _processor (new myService(_handler));
shared_ptr<TProtocolFactory> _protocolFactory (new TBinaryProtocolFactory());
shared_ptr<ThreadManager> _threadManager = ThreadManager::newSimpleThreadManager(15);
shared_ptr<PosixThreadFactory> _threadFactory(new PosixThreadFactory());
_threadManager->threadFactory(_threadFactory);
_threadManager->start();

shared_ptr<TNonblockingServer> _server(new TNonblockingServer(_processor, _protocolFactory, 9090 ,_threadManager));;
_server->serve();

Python客户端代码:

^{pr2}$

当我启动服务器,然后启动客户端时,会得到以下结果:

在客户端(Python):

./myPythonExec.py
connection success!
socket.error: [Errno 104] Connection reset by peer

在服务器端(c++):

assertion " 0 " failed
0  0x00007ffff0942425 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
1  0x00007ffff0945b8b in __GI_abort () at abort.c:91
2  0x00007ffff093b0ee in __assert_fail_base (fmt=<optimized out>, assertion=0x7ffff1438f1a "0", 
file=0x7ffff1439298 "src/server/TNonblockingServer.cpp", line=<optimized out>, function=<optimized out>) at assert.c:94
3  0x00007ffff093b192 in __GI___assert_fail (assertion=0x7ffff1438f1a "0", file=0x7ffff1439298 "src/server/TNonblockingServer.cpp", 
line=558, function=0x7ffff1439c60 "void apache::thrift::server::TNonblockingServer::TConnection::workSocket()") at assert.c:103
4  0x00007ffff14336e4 in apache::thrift::server::TNonblockingServer::TConnection::workSocket (this=0x7fffc0004ac0)
at src/server/TNonblockingServer.cpp:558
5  0x00007ffff11ed94c in event_base_loop () from /usr/lib/libevent-2.0.so.5

我使用的是libthrift 0.8.0,其pb值与libthrift 0.9.1相同

使用C++上的TSimeServer和客户端上的TBuffeRead传输时,它工作得很好


Tags: in服务器客户端newserverassertoutat
1条回答
网友
1楼 · 发布于 2024-10-01 11:30:13

抱歉,前面没有看到,但看起来是同一个问题: Service Multiplexing using Apache Thrift

简而言之,你必须使用两边都有框,或者没有框。在

shared_ptr<TTransportFactory> _transportFactory(new TFramedTransportFactory());
shared_ptr<TNonblockingServer> _server(
   new TNonblockingServer(
     _processor, 
     _transportFactory,
     _transportFactory,
     _protocolFactory, 
     _protocolFactory, 
     9090,
     _threadManager));
_server->serve();

相关问题 更多 >