Skip to content

Commit

Permalink
Optimize the initialization process of Current to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanshudong committed Oct 30, 2023
1 parent 4078485 commit 24b1dee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/PushCallbackDemo/Server/HelloImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void HelloImp::destroy()
int HelloImp::doClose(tars::TarsCurrentPtr current)
{
g_app._pushThread.delCurrent(current);
return 0;
}

int HelloImp::registerPush(tars::TarsCurrentPtr current)
Expand Down
14 changes: 10 additions & 4 deletions servant/libservant/Current.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,31 @@ void Current::initialize(const shared_ptr<TC_EpollServer::RecvContext> &data)

_data = data;

Application *application = (Application*)this->_servantHandle->getApplication();
// Application *application = (Application*)this->_servantHandle->getApplication();

_request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName());
// _request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName());

_isTars = _data->adapter()->isTarsProtocol();

if (_isTars)
{
initialize(_data->buffer());
}
else
{
_request.sServantName = this->_servantHandle->getServant()->getName();
}
}

void Current::initializeClose(const shared_ptr<TC_EpollServer::RecvContext> &data)
{
_data = data;

Application *application = (Application*)this->_servantHandle->getApplication();
// Application *application = (Application*)this->_servantHandle->getApplication();

_request.sServantName = this->_servantHandle->getServant()->getName();

_request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName());
// _request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName());
}

void Current::initialize(const vector<char>& sRecvBuffer)
Expand Down
6 changes: 5 additions & 1 deletion servant/servant/ServantHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class ServantHandle : public TC_EpollServer::Handle
*/
Application *getApplication() { return _application; }

/**
* 获取实际的servant
* @return
*/
ServantPtr getServant() { return _servant; }
protected:
/**
* 线程初始化
Expand Down Expand Up @@ -201,7 +206,6 @@ class ServantHandle : public TC_EpollServer::Handle
* 处理对象
*/
ServantPtr _servant;
// unordered_map<string, ServantPtr> _servants;


// #ifdef TARS_OPENTRACKING
Expand Down

0 comments on commit 24b1dee

Please sign in to comment.