Selaa lähdekoodia

Fix the problem that the core will be when the independent communicator
client Ctrl + C exits

ruanshudong 2 vuotta sitten
vanhempi
commit
0a708f6d55

+ 2 - 2
examples/AuthDemo/Server/HelloServer.cpp

@@ -48,11 +48,11 @@ main(int argc, char* argv[])
     }
     catch (std::exception& e)
     {
-        cerr << "std::exception:" << e.what() << std::endl;
+        LOG_CONSOLE_DEBUG << "std::exception error:" << e.what() << std::endl;
     }
     catch (...)
     {
-        cerr << "unknown exception." << std::endl;
+    	LOG_CONSOLE_DEBUG << "unknown exception." << std::endl;
     }
     return -1;
 }

+ 5 - 5
servant/libservant/Application.cpp

@@ -198,7 +198,6 @@ void Application::waitForShutdown()
 	TC_Port::unregisterTerm(_termId);
 
 	_epollServer = NULL;
-
 }
 
 void Application::waitForReady()
@@ -277,11 +276,10 @@ bool Application::cmdCloseCoreDump(const string& command, const string& params,
         tlimit.rlim_cur = tlimit.rlim_max;
     }
 
-
     ret = setrlimit(RLIMIT_CORE, &tlimit);
     if (ret != 0)
     {
-        TLOGERROR("error: "<<strerror(errno)<<endl);
+       TLOGERROR("error: "<<strerror(errno)<<endl);
        return false;
     }
 
@@ -890,10 +888,12 @@ void Application::main(const string &config)
     }
     catch (exception &ex)
     {
-	    __out__.error()  << "[main exception]:" << ex.what() << endl;
+	    __out__.error()  << "[Application]:" << ex.what() << endl;
+
+	    terminate();
 
 		NOTIFY_AND_WAIT("exit: " + string(ex.what()));
-		
+
         exit(-1);
     }
 

+ 0 - 1
servant/libservant/Communicator.cpp

@@ -80,7 +80,6 @@ Communicator::~Communicator()
 #if TARGET_PLATFORM_WINDOWS
     WSACleanup();
 #endif
-
 }
 
 bool Communicator::isTerminating()

+ 3 - 3
servant/libservant/ServantProxy.cpp

@@ -143,6 +143,7 @@ void ServantProxyThreadData::Immortal::erase(Communicator *comm)
 
 	for(auto it : _sp_list)
 	{
+		cout << "erase" << endl;
 		(*it).erase(comm);
 	}
 }
@@ -214,7 +215,7 @@ ServantProxyThreadData* ServantProxyThreadData::getData()
 
 void ServantProxyThreadData::deconstructor(Communicator *communicator)
 {
-    if(g_immortal)
+    if(g_immortal.use_count() > 0)
     {
         g_immortal->erase(communicator);
     }
@@ -915,7 +916,7 @@ void ServantProxy::invoke(ReqMessage *msg, bool bCoroAsync)
 			if(!msg->pMonitor->bMonitorFin)
 			{
 				TLOGERROR("[ServantProxy::invoke communicator terminate]" << endl);
-				return;
+				throw TarsCommunicatorException("communicator terminate");
 			}
         }
         else
@@ -967,7 +968,6 @@ void ServantProxy::invoke(ReqMessage *msg, bool bCoroAsync)
         //异常调用
         int ret = msg->response->iRet;
 
-
 		delete msg;
         msg = NULL;
 

+ 1 - 1
servant/servant/Communicator.h

@@ -524,7 +524,7 @@ protected:
      * 分发给异步线程的索引seq
      */
     size_t                 _asyncSeq = 0;
-	
+
     /**
      * 注册事件
      */

+ 4 - 0
util/src/tc_epoll_server.cpp

@@ -532,6 +532,9 @@ void TC_EpollServer::Connection::initialize(TC_Epoller *epoller, unsigned int ui
 	                         std::bind(&Connection::onOpensslCallback, this, std::placeholders::_1));
 
 	_trans->setServerAuthCallback(_pBindAdapter->_onVerifyCallback);
+
+	_trans->getRecvBuffer().setConnection(this);
+
 }
 
 bool TC_EpollServer::Connection::handleOutputImp(const shared_ptr<TC_Epoller::EpollInfo> &data)
@@ -714,6 +717,7 @@ TC_NetWorkBuffer::PACKET_TYPE TC_EpollServer::Connection::onParserCallback(TC_Ne
 		}
 	}
 
+
 	vector<char> ro;
 
 	TC_NetWorkBuffer::PACKET_TYPE ret = _pBindAdapter->getProtocol()(rbuf, ro);