mirror of
https://gitee.com/TarsCloud/TarsCpp.git
synced 2024-12-22 22:16:38 +08:00
fix coro bug
This commit is contained in:
parent
0df7e70485
commit
cfd4d576c7
@ -1,5 +1,5 @@
|
||||
|
||||
macro(build_tars_server MODULE)
|
||||
macro(build_tars_server MODULE DEPS)
|
||||
|
||||
include_directories(./)
|
||||
|
||||
@ -50,7 +50,7 @@ macro(build_tars_server MODULE)
|
||||
|
||||
endif (TARS_LIST)
|
||||
|
||||
add_dependencies(${MODULE} tarsservant tarsutil)
|
||||
add_dependencies(${MODULE} ${DEPS} tarsservant tarsutil)
|
||||
|
||||
target_link_libraries(${MODULE} tarsservant tarsutil)
|
||||
|
||||
|
@ -15,3 +15,8 @@ add_custom_target(run-http
|
||||
DEPENDS HttpServer HttpClient
|
||||
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/scripts/run-http.sh
|
||||
COMMENT "call run http")
|
||||
|
||||
add_custom_target(run-co
|
||||
DEPENDS CoroutineDemoAServer CoroutineDemoBServer CoroutineDemoClient testCoro testParallelCoro
|
||||
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/scripts/run-co.sh
|
||||
COMMENT "call run co")
|
||||
|
@ -193,44 +193,6 @@ namespace Test
|
||||
"testStr"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__AServant_all, __AServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __AServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testInt_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testStr_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __AServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testInt",
|
||||
"testStr"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__AServant_all, __AServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __AServant_all)
|
||||
@ -336,6 +298,44 @@ namespace Test
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __AServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testInt",
|
||||
"testStr"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__AServant_all, __AServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __AServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testInt_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testStr_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
|
@ -1 +1 @@
|
||||
build_tars_server("AServer")
|
||||
build_tars_server("CoroutineDemoAServer" "")
|
@ -1,12 +0,0 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
APP := Test
|
||||
TARGET := AServer
|
||||
CONFIG :=
|
||||
STRIP_FLAG:= N
|
||||
|
||||
INCLUDE +=
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
include /usr/local/tars/cpp/makefile/makefile.tars
|
||||
#-----------------------------------------------------------------------
|
@ -1,687 +0,0 @@
|
||||
// **********************************************************************
|
||||
// This file was generated by a TARS parser!
|
||||
// TARS version 1.4.0.
|
||||
// **********************************************************************
|
||||
|
||||
#ifndef __ASERVANT_H_
|
||||
#define __ASERVANT_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "tup/Tars.h"
|
||||
#include "tup/TarsJson.h"
|
||||
using namespace std;
|
||||
#include "servant/ServantProxy.h"
|
||||
#include "servant/Servant.h"
|
||||
|
||||
|
||||
namespace Test
|
||||
{
|
||||
|
||||
/* callback of async proxy for client */
|
||||
class AServantPrxCallback: public tars::ServantProxyCallback
|
||||
{
|
||||
public:
|
||||
virtual ~AServantPrxCallback(){}
|
||||
virtual void callback_test(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_test() override incorrect."); }
|
||||
virtual void callback_test_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_test_exception() override incorrect."); }
|
||||
|
||||
virtual void callback_testInt(tars::Int32 ret, tars::Int32 iOut)
|
||||
{ throw std::runtime_error("callback_testInt() override incorrect."); }
|
||||
virtual void callback_testInt_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_testInt_exception() override incorrect."); }
|
||||
|
||||
virtual void callback_testStr(tars::Int32 ret, const std::string& sOut)
|
||||
{ throw std::runtime_error("callback_testStr() override incorrect."); }
|
||||
virtual void callback_testStr_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_testStr_exception() override incorrect."); }
|
||||
|
||||
public:
|
||||
virtual const map<std::string, std::string> & getResponseContext() const
|
||||
{
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
if(!pCbtd->getContextValid())
|
||||
{
|
||||
throw TC_Exception("cann't get response context");
|
||||
}
|
||||
return pCbtd->getResponseContext();
|
||||
}
|
||||
|
||||
public:
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __AServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testInt",
|
||||
"testStr"
|
||||
};
|
||||
pair<string*, string*> r = equal_range(__AServant_all, __AServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __AServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testInt_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testStr_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __AServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testInt",
|
||||
"testStr"
|
||||
};
|
||||
pair<string*, string*> r = equal_range(__AServant_all, __AServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __AServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_test(_ret);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
tars::Int32 iOut;
|
||||
_is.read(iOut, 2, true);
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_testInt(_ret, iOut);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_testStr(_ret, sOut);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
};
|
||||
typedef tars::TC_AutoPtr<AServantPrxCallback> AServantPrxCallbackPtr;
|
||||
|
||||
/* callback of coroutine async proxy for client */
|
||||
class AServantCoroPrxCallback: public AServantPrxCallback
|
||||
{
|
||||
public:
|
||||
virtual ~AServantCoroPrxCallback(){}
|
||||
public:
|
||||
virtual const map<std::string, std::string> & getResponseContext() const { return _mRspContext; }
|
||||
|
||||
virtual void setResponseContext(const map<std::string, std::string> &mContext) { _mRspContext = mContext; }
|
||||
|
||||
public:
|
||||
virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __AServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testInt",
|
||||
"testStr"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__AServant_all, __AServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __AServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testInt_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testStr_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __AServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testInt",
|
||||
"testStr"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__AServant_all, __AServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __AServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_test(_ret);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_test_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_test_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
tars::Int32 iOut;
|
||||
_is.read(iOut, 2, true);
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_testInt(_ret, iOut);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_testInt_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_testInt_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_testStr(_ret, sOut);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_testStr_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_testStr_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
typedef tars::TC_AutoPtr<AServantCoroPrxCallback> AServantCoroPrxCallbackPtr;
|
||||
|
||||
/* proxy for client */
|
||||
class AServantProxy : public tars::ServantProxy
|
||||
{
|
||||
public:
|
||||
typedef map<string, string> TARS_CONTEXT;
|
||||
tars::Int32 test(const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"test", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_test(AServantPrxCallbackPtr callback,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"test", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_test(AServantCoroPrxCallbackPtr callback,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"test", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
tars::Int32 testInt(tars::Int32 iIn,tars::Int32 &iOut,const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(iIn, 1);
|
||||
_os.write(iOut, 2);
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"testInt", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
_is.read(iOut, 2, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_testInt(AServantPrxCallbackPtr callback,tars::Int32 iIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(iIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testInt", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_testInt(AServantCoroPrxCallbackPtr callback,tars::Int32 iIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(iIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testInt", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
tars::Int32 testStr(const std::string & sIn,std::string &sOut,const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
_os.write(sOut, 2);
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"testStr", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
_is.read(sOut, 2, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_testStr(AServantPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testStr", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_testStr(AServantCoroPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testStr", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
AServantProxy* tars_hash(int64_t key)
|
||||
{
|
||||
return (AServantProxy*)ServantProxy::tars_hash(key);
|
||||
}
|
||||
|
||||
AServantProxy* tars_consistent_hash(int64_t key)
|
||||
{
|
||||
return (AServantProxy*)ServantProxy::tars_consistent_hash(key);
|
||||
}
|
||||
|
||||
AServantProxy* tars_set_timeout(int msecond)
|
||||
{
|
||||
return (AServantProxy*)ServantProxy::tars_set_timeout(msecond);
|
||||
}
|
||||
|
||||
static const char* tars_prxname() { return "AServantProxy"; }
|
||||
};
|
||||
typedef tars::TC_AutoPtr<AServantProxy> AServantPrx;
|
||||
|
||||
/* servant for server */
|
||||
class AServant : public tars::Servant
|
||||
{
|
||||
public:
|
||||
virtual ~AServant(){}
|
||||
virtual tars::Int32 test(tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_test(tars::TarsCurrentPtr current, tars::Int32 _ret)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
virtual tars::Int32 testInt(tars::Int32 iIn,tars::Int32 &iOut,tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_testInt(tars::TarsCurrentPtr current, tars::Int32 _ret, tars::Int32 iOut)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("iOut", iOut);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
_os.write(iOut, 2);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
virtual tars::Int32 testStr(const std::string & sIn,std::string &sOut,tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_testStr(tars::TarsCurrentPtr current, tars::Int32 _ret, const std::string &sOut)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
_os.write(sOut, 2);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
int onDispatch(tars::TarsCurrentPtr _current, vector<char> &_sResponseBuffer)
|
||||
{
|
||||
static ::std::string __Test__AServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testInt",
|
||||
"testStr"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Test__AServant_all, __Test__AServant_all+3, _current->getFuncName());
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Test__AServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
tars::Int32 _ret = test(_current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
tars::Int32 iIn;
|
||||
tars::Int32 iOut;
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
tarsAttr.get("iIn", iIn);
|
||||
tarsAttr.getByDefault("iOut", iOut, iOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.read(iIn, 1, true);
|
||||
_is.read(iOut, 2, false);
|
||||
}
|
||||
tars::Int32 _ret = testInt(iIn,iOut, _current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("iOut", iOut);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.write(iOut, 2);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
std::string sIn;
|
||||
std::string sOut;
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
tarsAttr.get("sIn", sIn);
|
||||
tarsAttr.getByDefault("sOut", sOut, sOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.read(sIn, 1, true);
|
||||
_is.read(sOut, 2, false);
|
||||
}
|
||||
tars::Int32 _ret = testStr(sIn,sOut, _current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.write(sOut, 2);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
|
||||
module Test
|
||||
{
|
||||
|
||||
interface AServant
|
||||
{
|
||||
int test();
|
||||
|
||||
int testInt(int iIn,out int iOut);
|
||||
|
||||
int testStr(string sIn, out string sOut);
|
||||
};
|
||||
|
||||
};
|
@ -193,44 +193,6 @@ namespace Test
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testCoroParallel_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testCoroSerial_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
@ -336,6 +298,44 @@ namespace Test
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testCoroParallel_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testCoroSerial_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
|
@ -28,7 +28,7 @@ void BServantImp::initialize()
|
||||
{
|
||||
//initialize servant here:
|
||||
//...
|
||||
_pPrx = Application::getCommunicator()->stringToProxy<AServantPrx>("Test.AServer.AServantObj");
|
||||
_pPrx = Application::getCommunicator()->stringToProxy<AServantPrx>("Test.AServer.AServantObj@tcp -h 127.0.0.1 -p 9000 -t 10000");
|
||||
}
|
||||
//////////////////////////////////////////////////////
|
||||
void BServantImp::destroy()
|
||||
|
@ -1 +1 @@
|
||||
build_tars_server("BServer")
|
||||
build_tars_server("CoroutineDemoBServer" "AServer")
|
@ -1,12 +0,0 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
APP := Test
|
||||
TARGET := BServer
|
||||
CONFIG :=
|
||||
STRIP_FLAG:= N
|
||||
|
||||
INCLUDE +=
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
include /usr/local/tars/cpp/makefile/makefile.tars
|
||||
#-----------------------------------------------------------------------
|
@ -1,6 +1,10 @@
|
||||
|
||||
include_directories(AServer)
|
||||
add_subdirectory(AServer)
|
||||
|
||||
include_directories(BServer)
|
||||
add_subdirectory(BServer)
|
||||
|
||||
add_subdirectory(client)
|
||||
add_subdirectory(testCoro)
|
||||
add_subdirectory(testParallelCoro)
|
||||
|
@ -1,687 +0,0 @@
|
||||
// **********************************************************************
|
||||
// This file was generated by a TARS parser!
|
||||
// TARS version 1.4.0.
|
||||
// **********************************************************************
|
||||
|
||||
#ifndef __BSERVANT_H_
|
||||
#define __BSERVANT_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "tup/Tars.h"
|
||||
#include "tup/TarsJson.h"
|
||||
using namespace std;
|
||||
#include "servant/ServantProxy.h"
|
||||
#include "servant/Servant.h"
|
||||
|
||||
|
||||
namespace Test
|
||||
{
|
||||
|
||||
/* callback of async proxy for client */
|
||||
class BServantPrxCallback: public tars::ServantProxyCallback
|
||||
{
|
||||
public:
|
||||
virtual ~BServantPrxCallback(){}
|
||||
virtual void callback_test(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_test() override incorrect."); }
|
||||
virtual void callback_test_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_test_exception() override incorrect."); }
|
||||
|
||||
virtual void callback_testCoroParallel(tars::Int32 ret, const std::string& sOut)
|
||||
{ throw std::runtime_error("callback_testCoroParallel() override incorrect."); }
|
||||
virtual void callback_testCoroParallel_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_testCoroParallel_exception() override incorrect."); }
|
||||
|
||||
virtual void callback_testCoroSerial(tars::Int32 ret, const std::string& sOut)
|
||||
{ throw std::runtime_error("callback_testCoroSerial() override incorrect."); }
|
||||
virtual void callback_testCoroSerial_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_testCoroSerial_exception() override incorrect."); }
|
||||
|
||||
public:
|
||||
virtual const map<std::string, std::string> & getResponseContext() const
|
||||
{
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
if(!pCbtd->getContextValid())
|
||||
{
|
||||
throw TC_Exception("cann't get response context");
|
||||
}
|
||||
return pCbtd->getResponseContext();
|
||||
}
|
||||
|
||||
public:
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testCoroParallel_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testCoroSerial_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_test(_ret);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_testCoroParallel(_ret, sOut);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_testCoroSerial(_ret, sOut);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantPrxCallback> BServantPrxCallbackPtr;
|
||||
|
||||
/* callback of coroutine async proxy for client */
|
||||
class BServantCoroPrxCallback: public BServantPrxCallback
|
||||
{
|
||||
public:
|
||||
virtual ~BServantCoroPrxCallback(){}
|
||||
public:
|
||||
virtual const map<std::string, std::string> & getResponseContext() const { return _mRspContext; }
|
||||
|
||||
virtual void setResponseContext(const map<std::string, std::string> &mContext) { _mRspContext = mContext; }
|
||||
|
||||
public:
|
||||
virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testCoroParallel_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testCoroSerial_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_test(_ret);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_test_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_test_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_testCoroParallel(_ret, sOut);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_testCoroParallel_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_testCoroParallel_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_testCoroSerial(_ret, sOut);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_testCoroSerial_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_testCoroSerial_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantCoroPrxCallback> BServantCoroPrxCallbackPtr;
|
||||
|
||||
/* proxy for client */
|
||||
class BServantProxy : public tars::ServantProxy
|
||||
{
|
||||
public:
|
||||
typedef map<string, string> TARS_CONTEXT;
|
||||
tars::Int32 test(const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"test", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_test(BServantPrxCallbackPtr callback,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"test", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_test(BServantCoroPrxCallbackPtr callback,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"test", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
tars::Int32 testCoroParallel(const std::string & sIn,std::string &sOut,const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
_os.write(sOut, 2);
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"testCoroParallel", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
_is.read(sOut, 2, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_testCoroParallel(BServantPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroParallel", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_testCoroParallel(BServantCoroPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroParallel", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
tars::Int32 testCoroSerial(const std::string & sIn,std::string &sOut,const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
_os.write(sOut, 2);
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"testCoroSerial", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
_is.read(sOut, 2, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_testCoroSerial(BServantPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroSerial", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_testCoroSerial(BServantCoroPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroSerial", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
BServantProxy* tars_hash(int64_t key)
|
||||
{
|
||||
return (BServantProxy*)ServantProxy::tars_hash(key);
|
||||
}
|
||||
|
||||
BServantProxy* tars_consistent_hash(int64_t key)
|
||||
{
|
||||
return (BServantProxy*)ServantProxy::tars_consistent_hash(key);
|
||||
}
|
||||
|
||||
BServantProxy* tars_set_timeout(int msecond)
|
||||
{
|
||||
return (BServantProxy*)ServantProxy::tars_set_timeout(msecond);
|
||||
}
|
||||
|
||||
static const char* tars_prxname() { return "BServantProxy"; }
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantProxy> BServantPrx;
|
||||
|
||||
/* servant for server */
|
||||
class BServant : public tars::Servant
|
||||
{
|
||||
public:
|
||||
virtual ~BServant(){}
|
||||
virtual tars::Int32 test(tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_test(tars::TarsCurrentPtr current, tars::Int32 _ret)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
virtual tars::Int32 testCoroParallel(const std::string & sIn,std::string &sOut,tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_testCoroParallel(tars::TarsCurrentPtr current, tars::Int32 _ret, const std::string &sOut)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
_os.write(sOut, 2);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
virtual tars::Int32 testCoroSerial(const std::string & sIn,std::string &sOut,tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_testCoroSerial(tars::TarsCurrentPtr current, tars::Int32 _ret, const std::string &sOut)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
_os.write(sOut, 2);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
int onDispatch(tars::TarsCurrentPtr _current, vector<char> &_sResponseBuffer)
|
||||
{
|
||||
static ::std::string __Test__BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Test__BServant_all, __Test__BServant_all+3, _current->getFuncName());
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Test__BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
tars::Int32 _ret = test(_current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
std::string sIn;
|
||||
std::string sOut;
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
tarsAttr.get("sIn", sIn);
|
||||
tarsAttr.getByDefault("sOut", sOut, sOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.read(sIn, 1, true);
|
||||
_is.read(sOut, 2, false);
|
||||
}
|
||||
tars::Int32 _ret = testCoroParallel(sIn,sOut, _current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.write(sOut, 2);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
std::string sIn;
|
||||
std::string sOut;
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
tarsAttr.get("sIn", sIn);
|
||||
tarsAttr.getByDefault("sOut", sOut, sOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.read(sIn, 1, true);
|
||||
_is.read(sOut, 2, false);
|
||||
}
|
||||
tars::Int32 _ret = testCoroSerial(sIn,sOut, _current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.write(sOut, 2);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,15 +0,0 @@
|
||||
|
||||
module Test
|
||||
{
|
||||
|
||||
interface BServant
|
||||
{
|
||||
int test();
|
||||
|
||||
int testCoroSerial(string sIn, out string sOut);
|
||||
|
||||
int testCoroParallel(string sIn, out string sOut);
|
||||
|
||||
};
|
||||
|
||||
};
|
@ -1 +1 @@
|
||||
build_tars_server("client")
|
||||
build_tars_server("CoroutineDemoClient" "AServer BServer")
|
@ -26,7 +26,7 @@ using namespace tars;
|
||||
class Test1
|
||||
{
|
||||
public:
|
||||
Test1(const string &sStr);
|
||||
Test1();
|
||||
|
||||
~Test1();
|
||||
|
||||
@ -37,11 +37,11 @@ private:
|
||||
BServantPrx _prx;
|
||||
};
|
||||
|
||||
Test1::Test1(const string &sStr)
|
||||
Test1::Test1()
|
||||
{
|
||||
_comm.setProperty("locator", "tars.tarsregistry.QueryObj@tcp -h 10.208.139.242 -p 17890 -t 10000");
|
||||
_comm.setProperty("stat", "tars.tarsstat.StatObj");
|
||||
_comm.stringToProxy(sStr, _prx);
|
||||
// _comm.setProperty("locator", "tars.tarsregistry.QueryObj@tcp -h 10.208.139.242 -p 17890 -t 10000");
|
||||
// _comm.setProperty("stat", "tars.tarsstat.StatObj");
|
||||
_prx = _comm.stringToProxy<BServantPrx>("Test.BServer.BServantObj@tcp -h 127.0.0.1 -p 9100");
|
||||
}
|
||||
|
||||
Test1::~Test1()
|
||||
@ -54,14 +54,11 @@ void Test1::queryResult(int iFlag, int iExecuteNum)
|
||||
string sIn(10,'a');
|
||||
string sOut("");
|
||||
|
||||
tars::Int32 count = 0;
|
||||
unsigned long sum = 0;
|
||||
|
||||
time_t _iTime=TC_TimeProvider::getInstance()->getNowMs();
|
||||
time_t t = TC_Common::now2us();
|
||||
|
||||
for(int i=0; i<iExecuteNum; i++)
|
||||
{
|
||||
sOut = "";
|
||||
// sOut = "";
|
||||
try
|
||||
{
|
||||
int ret = -1;
|
||||
@ -74,59 +71,48 @@ void Test1::queryResult(int iFlag, int iExecuteNum)
|
||||
ret = _prx->testCoroParallel(sIn, sOut);
|
||||
}
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
++sum;
|
||||
++count;
|
||||
if(count == iExecuteNum)
|
||||
{
|
||||
cout << "pthread id: " << pthread_self() << " | " << TC_TimeProvider::getInstance()->getNowMs() - _iTime << endl;
|
||||
_iTime=TC_TimeProvider::getInstance()->getNowMs();
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
assert(sIn == sOut);
|
||||
// cout << ret << ", " << sIn << ", " << sOut << endl;
|
||||
}
|
||||
catch(TC_Exception &e)
|
||||
{
|
||||
cout << "pthread id: " << pthread_self() << "id: " << i << "exception: " << e.what() << endl;
|
||||
cout << "pthread id: " << std::this_thread::get_id() << "id: " << i << "exception: " << e.what() << endl;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
cout << "pthread id: " << pthread_self() << "id: " << i << "unknown exception." << endl;
|
||||
cout << "pthread id: " << std::this_thread::get_id() << "id: " << i << "unknown exception." << endl;
|
||||
}
|
||||
}
|
||||
cout << "succ:" << sum << endl;
|
||||
cout << "sOut:" << sOut << endl;
|
||||
|
||||
int64_t cost = TC_Common::now2us() - t;
|
||||
cout << "syncCall total:" << cost << "us, avg:" << 1.*cost/iExecuteNum << "us" << endl;
|
||||
}
|
||||
|
||||
int main(int argc,char ** argv)
|
||||
{
|
||||
if(argc != 5)
|
||||
if(argc != 4)
|
||||
{
|
||||
cout << "usage: " << argv[0] << " sObj ThreadNum CallTimes CallMode" << endl;
|
||||
cout << "usage: " << argv[0] << " ThreadNum CallTimes CallMode" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string s = string(argv[1]);
|
||||
|
||||
Test1 test1(s);
|
||||
Test1 test1;
|
||||
|
||||
try
|
||||
{
|
||||
tars::Int32 threads = TC_Common::strto<tars::Int32>(string(argv[2]));
|
||||
tars::Int32 threads = TC_Common::strto<tars::Int32>(string(argv[1]));
|
||||
|
||||
TC_ThreadPool tp;
|
||||
tp.init(threads);
|
||||
tp.start();
|
||||
|
||||
tars::Int32 times = TC_Common::strto<tars::Int32>(string(argv[3]));
|
||||
tars::Int32 callMode = TC_Common::strto<tars::Int32>(string(argv[4]));
|
||||
tars::Int32 times = TC_Common::strto<tars::Int32>(string(argv[2]));
|
||||
tars::Int32 callMode = TC_Common::strto<tars::Int32>(string(argv[3]));
|
||||
|
||||
for(int i = 0; i<threads; i++)
|
||||
{
|
||||
auto fw = std::bind(&Test1::queryResult, &test1, callMode, times);
|
||||
tp.exec(fw);
|
||||
cout << "********************" <<endl;
|
||||
}
|
||||
|
||||
tp.waitForAllDone();
|
||||
|
@ -1,12 +0,0 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
APP := Test
|
||||
TARGET := client
|
||||
CONFIG :=
|
||||
STRIP_FLAG:= N
|
||||
|
||||
INCLUDE +=
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
include /usr/local/tars/cpp/makefile/makefile.tars
|
||||
#-----------------------------------------------------------------------
|
@ -1,687 +0,0 @@
|
||||
// **********************************************************************
|
||||
// This file was generated by a TARS parser!
|
||||
// TARS version 1.4.0.
|
||||
// **********************************************************************
|
||||
|
||||
#ifndef __BSERVANT_H_
|
||||
#define __BSERVANT_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "tup/Tars.h"
|
||||
#include "tup/TarsJson.h"
|
||||
using namespace std;
|
||||
#include "servant/ServantProxy.h"
|
||||
#include "servant/Servant.h"
|
||||
|
||||
|
||||
namespace Test
|
||||
{
|
||||
|
||||
/* callback of async proxy for client */
|
||||
class BServantPrxCallback: public tars::ServantProxyCallback
|
||||
{
|
||||
public:
|
||||
virtual ~BServantPrxCallback(){}
|
||||
virtual void callback_test(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_test() override incorrect."); }
|
||||
virtual void callback_test_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_test_exception() override incorrect."); }
|
||||
|
||||
virtual void callback_testCoroParallel(tars::Int32 ret, const std::string& sOut)
|
||||
{ throw std::runtime_error("callback_testCoroParallel() override incorrect."); }
|
||||
virtual void callback_testCoroParallel_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_testCoroParallel_exception() override incorrect."); }
|
||||
|
||||
virtual void callback_testCoroSerial(tars::Int32 ret, const std::string& sOut)
|
||||
{ throw std::runtime_error("callback_testCoroSerial() override incorrect."); }
|
||||
virtual void callback_testCoroSerial_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_testCoroSerial_exception() override incorrect."); }
|
||||
|
||||
public:
|
||||
virtual const map<std::string, std::string> & getResponseContext() const
|
||||
{
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
if(!pCbtd->getContextValid())
|
||||
{
|
||||
throw TC_Exception("cann't get response context");
|
||||
}
|
||||
return pCbtd->getResponseContext();
|
||||
}
|
||||
|
||||
public:
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testCoroParallel_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testCoroSerial_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_test(_ret);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_testCoroParallel(_ret, sOut);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_testCoroSerial(_ret, sOut);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantPrxCallback> BServantPrxCallbackPtr;
|
||||
|
||||
/* callback of coroutine async proxy for client */
|
||||
class BServantCoroPrxCallback: public BServantPrxCallback
|
||||
{
|
||||
public:
|
||||
virtual ~BServantCoroPrxCallback(){}
|
||||
public:
|
||||
virtual const map<std::string, std::string> & getResponseContext() const { return _mRspContext; }
|
||||
|
||||
virtual void setResponseContext(const map<std::string, std::string> &mContext) { _mRspContext = mContext; }
|
||||
|
||||
public:
|
||||
virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testCoroParallel_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testCoroSerial_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_test(_ret);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_test_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_test_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_testCoroParallel(_ret, sOut);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_testCoroParallel_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_testCoroParallel_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_testCoroSerial(_ret, sOut);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_testCoroSerial_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_testCoroSerial_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantCoroPrxCallback> BServantCoroPrxCallbackPtr;
|
||||
|
||||
/* proxy for client */
|
||||
class BServantProxy : public tars::ServantProxy
|
||||
{
|
||||
public:
|
||||
typedef map<string, string> TARS_CONTEXT;
|
||||
tars::Int32 test(const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"test", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_test(BServantPrxCallbackPtr callback,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"test", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_test(BServantCoroPrxCallbackPtr callback,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"test", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
tars::Int32 testCoroParallel(const std::string & sIn,std::string &sOut,const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
_os.write(sOut, 2);
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"testCoroParallel", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
_is.read(sOut, 2, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_testCoroParallel(BServantPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroParallel", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_testCoroParallel(BServantCoroPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroParallel", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
tars::Int32 testCoroSerial(const std::string & sIn,std::string &sOut,const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
_os.write(sOut, 2);
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"testCoroSerial", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
_is.read(sOut, 2, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_testCoroSerial(BServantPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroSerial", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_testCoroSerial(BServantCoroPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroSerial", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
BServantProxy* tars_hash(int64_t key)
|
||||
{
|
||||
return (BServantProxy*)ServantProxy::tars_hash(key);
|
||||
}
|
||||
|
||||
BServantProxy* tars_consistent_hash(int64_t key)
|
||||
{
|
||||
return (BServantProxy*)ServantProxy::tars_consistent_hash(key);
|
||||
}
|
||||
|
||||
BServantProxy* tars_set_timeout(int msecond)
|
||||
{
|
||||
return (BServantProxy*)ServantProxy::tars_set_timeout(msecond);
|
||||
}
|
||||
|
||||
static const char* tars_prxname() { return "BServantProxy"; }
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantProxy> BServantPrx;
|
||||
|
||||
/* servant for server */
|
||||
class BServant : public tars::Servant
|
||||
{
|
||||
public:
|
||||
virtual ~BServant(){}
|
||||
virtual tars::Int32 test(tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_test(tars::TarsCurrentPtr current, tars::Int32 _ret)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
virtual tars::Int32 testCoroParallel(const std::string & sIn,std::string &sOut,tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_testCoroParallel(tars::TarsCurrentPtr current, tars::Int32 _ret, const std::string &sOut)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
_os.write(sOut, 2);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
virtual tars::Int32 testCoroSerial(const std::string & sIn,std::string &sOut,tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_testCoroSerial(tars::TarsCurrentPtr current, tars::Int32 _ret, const std::string &sOut)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
_os.write(sOut, 2);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
int onDispatch(tars::TarsCurrentPtr _current, vector<char> &_sResponseBuffer)
|
||||
{
|
||||
static ::std::string __Test__BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Test__BServant_all, __Test__BServant_all+3, _current->getFuncName());
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Test__BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
tars::Int32 _ret = test(_current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
std::string sIn;
|
||||
std::string sOut;
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
tarsAttr.get("sIn", sIn);
|
||||
tarsAttr.getByDefault("sOut", sOut, sOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.read(sIn, 1, true);
|
||||
_is.read(sOut, 2, false);
|
||||
}
|
||||
tars::Int32 _ret = testCoroParallel(sIn,sOut, _current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.write(sOut, 2);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
std::string sIn;
|
||||
std::string sOut;
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
tarsAttr.get("sIn", sIn);
|
||||
tarsAttr.getByDefault("sOut", sOut, sOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.read(sIn, 1, true);
|
||||
_is.read(sOut, 2, false);
|
||||
}
|
||||
tars::Int32 _ret = testCoroSerial(sIn,sOut, _current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.write(sOut, 2);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,15 +0,0 @@
|
||||
|
||||
module Test
|
||||
{
|
||||
|
||||
interface BServant
|
||||
{
|
||||
int test();
|
||||
|
||||
int testCoroSerial(string sIn, out string sOut);
|
||||
|
||||
int testCoroParallel(string sIn, out string sOut);
|
||||
|
||||
};
|
||||
|
||||
};
|
@ -1 +1 @@
|
||||
build_tars_server("testCoro")
|
||||
build_tars_server("testCoro" "AServer BServer")
|
@ -27,7 +27,7 @@ using namespace tars;
|
||||
class TestCoroutine : public Coroutine
|
||||
{
|
||||
public:
|
||||
TestCoroutine(int iNum, const string &sObj);
|
||||
TestCoroutine(int iNum);
|
||||
|
||||
~TestCoroutine() {}
|
||||
|
||||
@ -35,17 +35,16 @@ public:
|
||||
|
||||
private:
|
||||
int _num;
|
||||
string _sObj;
|
||||
Communicator _comm;
|
||||
BServantPrx _prx;
|
||||
};
|
||||
|
||||
TestCoroutine::TestCoroutine(int iNum, const string &sObj)
|
||||
TestCoroutine::TestCoroutine(int iNum)
|
||||
: _num(iNum)
|
||||
, _sObj(sObj)
|
||||
{
|
||||
_comm.setProperty("locator", "tars.tarsregistry.QueryObj@tcp -h 10.208.139.242 -p 17890 -t 10000");
|
||||
_comm.stringToProxy(_sObj, _prx);
|
||||
// _comm.setProperty("locator", "tars.tarsregistry.QueryObj@tcp -h 10.208.139.242 -p 17890 -t 10000");
|
||||
_prx = _comm.stringToProxy<BServantPrx>("Test.BServer.BServantObj@tcp -h 127.0.0.1 -p 9100");
|
||||
// _comm.stringToProxy(_sObj, _prx);
|
||||
}
|
||||
|
||||
void TestCoroutine::handle()
|
||||
@ -85,18 +84,17 @@ void TestCoroutine::handle()
|
||||
|
||||
int main(int argc,char ** argv)
|
||||
{
|
||||
if(argc != 3)
|
||||
if(argc != 2)
|
||||
{
|
||||
cout << "usage: " << argv[0] << " CallTimes sObj" << endl;
|
||||
cout << "usage: " << argv[0] << " CallTimes " << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tars::Int32 iNum = TC_Common::strto<tars::Int32>(string(argv[1]));
|
||||
|
||||
string sObj = string(argv[2]);
|
||||
|
||||
TestCoroutine testCoro(iNum, sObj);
|
||||
TestCoroutine testCoro(iNum);
|
||||
|
||||
//start 10 co
|
||||
testCoro.setCoroInfo(10, 128, 128*1024);
|
||||
|
||||
testCoro.start();
|
||||
|
@ -1,12 +0,0 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
APP := Test
|
||||
TARGET := testCoro
|
||||
CONFIG :=
|
||||
STRIP_FLAG:= N
|
||||
|
||||
INCLUDE +=
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
include /usr/local/tars/cpp/makefile/makefile.tars
|
||||
#-----------------------------------------------------------------------
|
@ -1,687 +0,0 @@
|
||||
// **********************************************************************
|
||||
// This file was generated by a TARS parser!
|
||||
// TARS version 1.4.0.
|
||||
// **********************************************************************
|
||||
|
||||
#ifndef __BSERVANT_H_
|
||||
#define __BSERVANT_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "tup/Tars.h"
|
||||
#include "tup/TarsJson.h"
|
||||
using namespace std;
|
||||
#include "servant/ServantProxy.h"
|
||||
#include "servant/Servant.h"
|
||||
|
||||
|
||||
namespace Test
|
||||
{
|
||||
|
||||
/* callback of async proxy for client */
|
||||
class BServantPrxCallback: public tars::ServantProxyCallback
|
||||
{
|
||||
public:
|
||||
virtual ~BServantPrxCallback(){}
|
||||
virtual void callback_test(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_test() override incorrect."); }
|
||||
virtual void callback_test_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_test_exception() override incorrect."); }
|
||||
|
||||
virtual void callback_testCoroParallel(tars::Int32 ret, const std::string& sOut)
|
||||
{ throw std::runtime_error("callback_testCoroParallel() override incorrect."); }
|
||||
virtual void callback_testCoroParallel_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_testCoroParallel_exception() override incorrect."); }
|
||||
|
||||
virtual void callback_testCoroSerial(tars::Int32 ret, const std::string& sOut)
|
||||
{ throw std::runtime_error("callback_testCoroSerial() override incorrect."); }
|
||||
virtual void callback_testCoroSerial_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_testCoroSerial_exception() override incorrect."); }
|
||||
|
||||
public:
|
||||
virtual const map<std::string, std::string> & getResponseContext() const
|
||||
{
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
if(!pCbtd->getContextValid())
|
||||
{
|
||||
throw TC_Exception("cann't get response context");
|
||||
}
|
||||
return pCbtd->getResponseContext();
|
||||
}
|
||||
|
||||
public:
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testCoroParallel_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testCoroSerial_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_test(_ret);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_testCoroParallel(_ret, sOut);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(response.context);
|
||||
|
||||
callback_testCoroSerial(_ret, sOut);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantPrxCallback> BServantPrxCallbackPtr;
|
||||
|
||||
/* callback of coroutine async proxy for client */
|
||||
class BServantCoroPrxCallback: public BServantPrxCallback
|
||||
{
|
||||
public:
|
||||
virtual ~BServantCoroPrxCallback(){}
|
||||
public:
|
||||
virtual const map<std::string, std::string> & getResponseContext() const { return _mRspContext; }
|
||||
|
||||
virtual void setResponseContext(const map<std::string, std::string> &mContext) { _mRspContext = mContext; }
|
||||
|
||||
public:
|
||||
virtual int onDispatchResponse(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testCoroParallel_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
callback_testCoroSerial_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__BServant_all, __BServant_all+3, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_test(_ret);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_test_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_test_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_testCoroParallel(_ret, sOut);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_testCoroParallel_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_testCoroParallel_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(response.sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sOut;
|
||||
_is.read(sOut, 2, true);
|
||||
setResponseContext(response.context);
|
||||
|
||||
callback_testCoroSerial(_ret, sOut);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_testCoroSerial_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_testCoroSerial_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantCoroPrxCallback> BServantCoroPrxCallbackPtr;
|
||||
|
||||
/* proxy for client */
|
||||
class BServantProxy : public tars::ServantProxy
|
||||
{
|
||||
public:
|
||||
typedef map<string, string> TARS_CONTEXT;
|
||||
tars::Int32 test(const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"test", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_test(BServantPrxCallbackPtr callback,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"test", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_test(BServantCoroPrxCallbackPtr callback,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"test", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
tars::Int32 testCoroParallel(const std::string & sIn,std::string &sOut,const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
_os.write(sOut, 2);
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"testCoroParallel", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
_is.read(sOut, 2, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_testCoroParallel(BServantPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroParallel", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_testCoroParallel(BServantCoroPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroParallel", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
tars::Int32 testCoroSerial(const std::string & sIn,std::string &sOut,const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
_os.write(sOut, 2);
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"testCoroSerial", _os, context, _mStatus);
|
||||
if(pResponseContext)
|
||||
{
|
||||
pResponseContext->swap(rep->context);
|
||||
}
|
||||
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(rep->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
_is.read(sOut, 2, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_testCoroSerial(BServantPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroSerial", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_testCoroSerial(BServantCoroPrxCallbackPtr callback,const std::string &sIn,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sIn, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testCoroSerial", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
BServantProxy* tars_hash(int64_t key)
|
||||
{
|
||||
return (BServantProxy*)ServantProxy::tars_hash(key);
|
||||
}
|
||||
|
||||
BServantProxy* tars_consistent_hash(int64_t key)
|
||||
{
|
||||
return (BServantProxy*)ServantProxy::tars_consistent_hash(key);
|
||||
}
|
||||
|
||||
BServantProxy* tars_set_timeout(int msecond)
|
||||
{
|
||||
return (BServantProxy*)ServantProxy::tars_set_timeout(msecond);
|
||||
}
|
||||
|
||||
static const char* tars_prxname() { return "BServantProxy"; }
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantProxy> BServantPrx;
|
||||
|
||||
/* servant for server */
|
||||
class BServant : public tars::Servant
|
||||
{
|
||||
public:
|
||||
virtual ~BServant(){}
|
||||
virtual tars::Int32 test(tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_test(tars::TarsCurrentPtr current, tars::Int32 _ret)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
virtual tars::Int32 testCoroParallel(const std::string & sIn,std::string &sOut,tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_testCoroParallel(tars::TarsCurrentPtr current, tars::Int32 _ret, const std::string &sOut)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
_os.write(sOut, 2);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
virtual tars::Int32 testCoroSerial(const std::string & sIn,std::string &sOut,tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_testCoroSerial(tars::TarsCurrentPtr current, tars::Int32 _ret, const std::string &sOut)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
_os.write(sOut, 2);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
int onDispatch(tars::TarsCurrentPtr _current, vector<char> &_sResponseBuffer)
|
||||
{
|
||||
static ::std::string __Test__BServant_all[]=
|
||||
{
|
||||
"test",
|
||||
"testCoroParallel",
|
||||
"testCoroSerial"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Test__BServant_all, __Test__BServant_all+3, _current->getFuncName());
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Test__BServant_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
tars::Int32 _ret = test(_current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
std::string sIn;
|
||||
std::string sOut;
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
tarsAttr.get("sIn", sIn);
|
||||
tarsAttr.getByDefault("sOut", sOut, sOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.read(sIn, 1, true);
|
||||
_is.read(sOut, 2, false);
|
||||
}
|
||||
tars::Int32 _ret = testCoroParallel(sIn,sOut, _current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.write(sOut, 2);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
_is.setBuffer(_current->getRequestBuffer());
|
||||
std::string sIn;
|
||||
std::string sOut;
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
tarsAttr.get("sIn", sIn);
|
||||
tarsAttr.getByDefault("sOut", sOut, sOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.read(sIn, 1, true);
|
||||
_is.read(sOut, 2, false);
|
||||
}
|
||||
tars::Int32 _ret = testCoroSerial(sIn,sOut, _current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sOut", sOut);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.write(sOut, 2);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,15 +0,0 @@
|
||||
|
||||
module Test
|
||||
{
|
||||
|
||||
interface BServant
|
||||
{
|
||||
int test();
|
||||
|
||||
int testCoroSerial(string sIn, out string sOut);
|
||||
|
||||
int testCoroParallel(string sIn, out string sOut);
|
||||
|
||||
};
|
||||
|
||||
};
|
@ -1 +1 @@
|
||||
build_tars_server("testParallelCoro")
|
||||
build_tars_server("testParallelCoro" "AServer BServer")
|
@ -57,140 +57,12 @@ public:
|
||||
};
|
||||
typedef tars::TC_AutoPtr<BServantCoroCallback> BServantCoroCallbackPtr;
|
||||
|
||||
// //自定义协程类
|
||||
// class CoroutineClass : public TC_Thread
|
||||
// {
|
||||
// public:
|
||||
// /**
|
||||
// * 构造函数
|
||||
// */
|
||||
// CoroutineClass();
|
||||
|
||||
// /**
|
||||
// * 析构函数
|
||||
// */
|
||||
// virtual ~CoroutineClass();
|
||||
|
||||
// /**
|
||||
// * 返回0,代表成功,-1,表示失败
|
||||
// */
|
||||
// int registerFunc(const vector< std::function<void ()> > &vFunc);
|
||||
|
||||
// /**
|
||||
// * 线程初始化
|
||||
// */
|
||||
// virtual void initialize() {}
|
||||
|
||||
// /**
|
||||
// * 线程处理方法
|
||||
// */
|
||||
// virtual void run();
|
||||
|
||||
// /**
|
||||
// * 停止线程
|
||||
// */
|
||||
// void terminate();
|
||||
|
||||
// protected:
|
||||
// /**
|
||||
// * 线程已经启动, 进入具体协程处理前调用
|
||||
// */
|
||||
// virtual void startCoro() {}
|
||||
|
||||
// /**
|
||||
// * 线程马上要退出时调用
|
||||
// */
|
||||
// virtual void stopCoro() {}
|
||||
|
||||
// /**
|
||||
// * 具体的处理逻辑
|
||||
// */
|
||||
// virtual void handleCoro();
|
||||
|
||||
// protected:
|
||||
// CoroutineScheduler *_coroSched;
|
||||
// uint32_t _iPoolSize;
|
||||
// size_t _iStackSize;
|
||||
// vector<std::function<void ()> > _vFunc;
|
||||
// };
|
||||
|
||||
// CoroutineClass::CoroutineClass()
|
||||
// : _coroSched(NULL)
|
||||
// , _iPoolSize(1024)
|
||||
// , _iStackSize(128*1024)
|
||||
// {
|
||||
// }
|
||||
|
||||
// CoroutineClass::~CoroutineClass()
|
||||
// {
|
||||
// if(isAlive())
|
||||
// {
|
||||
// terminate();
|
||||
|
||||
// getThreadControl().join();
|
||||
// }
|
||||
// }
|
||||
|
||||
// int CoroutineClass::registerFunc(const vector< std::function<void ()> > &vFunc)
|
||||
// {
|
||||
// if(vFunc.size() > _iPoolSize || vFunc.size() <= 0)
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// _vFunc = vFunc;
|
||||
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// void CoroutineClass::run()
|
||||
// {
|
||||
// initialize();
|
||||
|
||||
// startCoro();
|
||||
|
||||
// handleCoro();
|
||||
|
||||
// stopCoro();
|
||||
// }
|
||||
|
||||
// void CoroutineClass::terminate()
|
||||
// {
|
||||
// if(_coroSched)
|
||||
// {
|
||||
// _coroSched->terminate();
|
||||
// }
|
||||
// }
|
||||
|
||||
// void CoroutineClass::handleCoro()
|
||||
// {
|
||||
// _coroSched = new CoroutineScheduler();
|
||||
|
||||
// _coroSched->init(_iPoolSize, _iStackSize);
|
||||
|
||||
// ServantProxyThreadData * pSptd = ServantProxyThreadData::getData();
|
||||
|
||||
// assert(pSptd != NULL);
|
||||
|
||||
// pSptd->_sched = _coroSched;
|
||||
|
||||
// for(size_t i = 0; i < _vFunc.size(); ++i)
|
||||
// {
|
||||
// _coroSched->createCoroutine(_vFunc[i]);
|
||||
// }
|
||||
|
||||
// _coroSched->run();
|
||||
|
||||
// delete _coroSched;
|
||||
// _coroSched = NULL;
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////
|
||||
//继承框架的协程类
|
||||
class TestCoroutine : public Coroutine
|
||||
{
|
||||
public:
|
||||
TestCoroutine(int iNum, const string &sObj);
|
||||
TestCoroutine(int iNum);
|
||||
|
||||
~TestCoroutine() {}
|
||||
|
||||
@ -198,17 +70,16 @@ public:
|
||||
|
||||
private:
|
||||
int _num;
|
||||
string _sObj;
|
||||
Communicator _comm;
|
||||
BServantPrx _prx;
|
||||
};
|
||||
|
||||
TestCoroutine::TestCoroutine(int iNum, const string &sObj)
|
||||
TestCoroutine::TestCoroutine(int iNum)
|
||||
: _num(iNum)
|
||||
, _sObj(sObj)
|
||||
{
|
||||
_comm.setProperty("locator", "tars.tarsregistry.QueryObj@tcp -h 10.208.139.242 -p 17890 -t 10000");
|
||||
_comm.stringToProxy(_sObj, _prx);
|
||||
// _comm.setProperty("locator", "tars.tarsregistry.QueryObj@tcp -h 10.208.139.242 -p 17890 -t 10000");
|
||||
_prx = _comm.stringToProxy<BServantPrx>("Test.BServer.BServantObj@tcp -h 127.0.0.1 -p 9100");
|
||||
// _comm.stringToProxy(_sObj, _prx);
|
||||
}
|
||||
|
||||
void TestCoroutine::handle()
|
||||
@ -232,8 +103,8 @@ void TestCoroutine::handle()
|
||||
|
||||
coroWhenAll(sharedPtr);
|
||||
|
||||
cout << "ret1:" << cb1->_sOut << "|ret2:" << cb2->_sOut << endl;
|
||||
;
|
||||
// cout << "ret1:" << cb1->_sOut << "|ret2:" << cb2->_sOut << endl;
|
||||
|
||||
if(cb1->_iRet == 0 && cb2->_iRet == 0 && cb1->_iException == 0 && cb2->_iException == 0)
|
||||
{
|
||||
++sum;
|
||||
@ -254,17 +125,15 @@ void TestCoroutine::handle()
|
||||
|
||||
int main(int argc,char ** argv)
|
||||
{
|
||||
if(argc != 3)
|
||||
if(argc != 2)
|
||||
{
|
||||
cout << "usage: " << argv[0] << " CallTimes sObj" << endl;
|
||||
cout << "usage: " << argv[0] << " CallTimes " << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tars::Int32 iNum = TC_Common::strto<tars::Int32>(string(argv[1]));
|
||||
|
||||
string sObj = string(argv[2]);
|
||||
|
||||
TestCoroutine testCoro(iNum, sObj);
|
||||
TestCoroutine testCoro(iNum);
|
||||
|
||||
testCoro.setCoroInfo(10, 128, 128*1024);
|
||||
|
||||
|
@ -1,12 +0,0 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
APP := Test
|
||||
TARGET := testCoro
|
||||
CONFIG :=
|
||||
STRIP_FLAG:= N
|
||||
|
||||
INCLUDE +=
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
include /usr/local/tars/cpp/makefile/makefile.tars
|
||||
#-----------------------------------------------------------------------
|
@ -1 +1 @@
|
||||
build_tars_server("HttpClient")
|
||||
build_tars_server("HttpClient" "HttpServer")
|
@ -1 +1 @@
|
||||
build_tars_server("HttpServer")
|
||||
build_tars_server("HttpServer" "")
|
@ -1 +1 @@
|
||||
build_tars_server("PushClient")
|
||||
build_tars_server("PushClient" "PushServer")
|
@ -1,13 +0,0 @@
|
||||
APP := Test
|
||||
TARGET := TestPushClient
|
||||
MFLAGS :=
|
||||
CONFIG :=
|
||||
STRIP_FLAG := N
|
||||
TARS2CPP_FLAG:=
|
||||
|
||||
INCLUDE +=
|
||||
LIB +=
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
include /usr/local/tars/cpp/makefile/makefile.tars
|
||||
#-----------------------------------------------------------------------
|
@ -1 +1 @@
|
||||
build_tars_server("PushServer")
|
||||
build_tars_server("PushServer" "")
|
@ -1,17 +0,0 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
APP := Test
|
||||
TARGET := TestPushServer
|
||||
CONFIG :=
|
||||
STRIP_FLAG := N
|
||||
TARS2CPP_FLAG:=
|
||||
|
||||
INCLUDE +=
|
||||
LIB +=
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
include /usr/local/tars/cpp/makefile/makefile.tars
|
||||
|
||||
#-----------------------------------------------------------------------
|
@ -1 +1 @@
|
||||
build_tars_server("QuickStartDemoClient")
|
||||
build_tars_server("QuickStartDemoClient" "QuickStartDemo")
|
@ -210,25 +210,6 @@ struct TupCallback : public ServantProxyCallback
|
||||
return 0;
|
||||
}
|
||||
|
||||
// virtual int onDispatch(ReqMessagePtr msg)
|
||||
// {
|
||||
// callback_count++;
|
||||
|
||||
// TarsUniPacket<> rsp;
|
||||
|
||||
// rsp.decode(package.sBuffer.data(), package.sBuffer.size());
|
||||
|
||||
// int ret = rsp.get<int>("");
|
||||
// string sRsp = rsp.get<string>("sRsp");
|
||||
// if(cur == count-1)
|
||||
// {
|
||||
// int64_t cost = TC_Common::now2us() - start;
|
||||
// cout << "TupCallback count:" << count << ", " << cost << " us, avg:" << 1.*cost/count << "us" << endl;
|
||||
// }
|
||||
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
int64_t start;
|
||||
int cur;
|
||||
int count;
|
||||
|
@ -1 +1 @@
|
||||
build_tars_server("QuickStartDemo")
|
||||
build_tars_server("QuickStartDemo" "")
|
||||
|
@ -156,36 +156,6 @@ namespace TestApp
|
||||
"testHello"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Hello_all, __Hello_all+2, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Hello_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testHello_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __Hello_all[]=
|
||||
{
|
||||
"test",
|
||||
"testHello"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Hello_all, __Hello_all+2, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Hello_all)
|
||||
@ -258,6 +228,36 @@ namespace TestApp
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __Hello_all[]=
|
||||
{
|
||||
"test",
|
||||
"testHello"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Hello_all, __Hello_all+2, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Hello_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testHello_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
|
@ -1 +1 @@
|
||||
build_tars_server("ProxyServerClient")
|
||||
build_tars_server("ProxyServerClient" "ProxyServer")
|
@ -29,16 +29,23 @@ int main(int argc,char ** argv)
|
||||
try
|
||||
{
|
||||
ProxyPrx prx;
|
||||
comm.stringToProxy("TestApp.ProxyServer.ProxyObj@tcp -h 10.208.139.242 -p 10007" , prx);
|
||||
comm.stringToProxy("TestApp.ProxyServer.ProxyObj@tcp -h 127.0.0.1 -p 9200" , prx);
|
||||
|
||||
try
|
||||
{
|
||||
string sReq("hello");
|
||||
string sRsp("");
|
||||
int i = 1000;
|
||||
while(i-- >= 0)
|
||||
{
|
||||
string sReq("hello");
|
||||
string sRsp("");
|
||||
|
||||
int iRet = prx->testProxy(sReq, sRsp);
|
||||
int iRet = prx->testProxy(sReq, sRsp);
|
||||
|
||||
cout<<"iRet:"<<iRet<<" sReq:"<<sReq<<" sRsp:"<<sRsp<<endl;
|
||||
assert(iRet == 0);
|
||||
assert(sReq == sRsp);
|
||||
}
|
||||
|
||||
// cout<<"iRet:"<<iRet<<" sReq:"<<sReq<<" sRsp:"<<sRsp<<endl;
|
||||
|
||||
}
|
||||
catch(exception &ex)
|
||||
|
@ -1,17 +0,0 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
APP := TestApp
|
||||
TARGET := TestProxy
|
||||
CONFIG :=
|
||||
STRIP_FLAG:= N
|
||||
|
||||
INCLUDE +=
|
||||
LIB +=
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
include /home/tarsproto/TestApp/ProxyServer/ProxyServer.mk
|
||||
include /usr/local/tars/cpp/makefile/makefile.tars
|
||||
|
||||
#-----------------------------------------------------------------------
|
@ -1,3 +1,3 @@
|
||||
build_tars_server("ProxyServer")
|
||||
build_tars_server("ProxyServer" "")
|
||||
|
||||
|
||||
|
@ -156,36 +156,6 @@ namespace TestApp
|
||||
"testProxy"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Proxy_all, __Proxy_all+2, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Proxy_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testProxy_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __Proxy_all[]=
|
||||
{
|
||||
"test",
|
||||
"testProxy"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Proxy_all, __Proxy_all+2, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Proxy_all)
|
||||
@ -258,6 +228,36 @@ namespace TestApp
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __Proxy_all[]=
|
||||
{
|
||||
"test",
|
||||
"testProxy"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Proxy_all, __Proxy_all+2, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Proxy_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testProxy_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
|
@ -50,7 +50,7 @@ void ProxyImp::initialize()
|
||||
//initialize servant here:
|
||||
//...
|
||||
|
||||
_prx = Application::getCommunicator()->stringToProxy<HelloPrx>("TestApp.HelloServer.HelloObj");
|
||||
_prx = Application::getCommunicator()->stringToProxy<HelloPrx>("TestApp.HelloServer.HelloObj@tcp -h 127.0.0.1 -p 8999");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
|
@ -1,17 +0,0 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
APP := TestApp
|
||||
TARGET := ProxyServer
|
||||
CONFIG :=
|
||||
STRIP_FLAG:= N
|
||||
TARS2CPP_FLAG:=
|
||||
|
||||
INCLUDE +=
|
||||
LIB +=
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
include /home/tarsproto/TestApp/HelloServer/HelloServer.mk
|
||||
include /usr/local/tars/cpp/makefile/makefile.tars
|
||||
|
||||
#-----------------------------------------------------------------------
|
@ -1 +1 @@
|
||||
build_tars_server("TarsStressClient")
|
||||
build_tars_server("TarsStressClient" "TarsStressServer")
|
@ -1 +1 @@
|
||||
build_tars_server("TarsStressServer")
|
||||
build_tars_server("TarsStressServer" "")
|
@ -156,36 +156,6 @@ namespace Test
|
||||
"testStr"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Stress_all, __Stress_all+2, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Stress_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testStr_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __Stress_all[]=
|
||||
{
|
||||
"test",
|
||||
"testStr"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Stress_all, __Stress_all+2, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Stress_all)
|
||||
@ -258,6 +228,36 @@ namespace Test
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
virtual int onDispatchException(const tars::RequestPacket &request, const tars::ResponsePacket &response)
|
||||
{
|
||||
static ::std::string __Stress_all[]=
|
||||
{
|
||||
"test",
|
||||
"testStr"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Stress_all, __Stress_all+2, request.sFuncName);
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Stress_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
callback_test_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
callback_testStr_exception(response.iRet);
|
||||
|
||||
return response.iRet;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
|
@ -18,4 +18,6 @@ echo "client: ${WORKDIR}/../bin/HttpClient"
|
||||
|
||||
${WORKDIR}/../bin/HttpClient 2 10000
|
||||
|
||||
killall -9 HttpServer
|
||||
|
||||
|
||||
|
@ -22,4 +22,11 @@ ${WORKDIR}/../bin/QuickStartDemoClient --count=100000 --call=async --thread=2 --
|
||||
|
||||
${WORKDIR}/../bin/QuickStartDemoClient --count=100000 --call=synctup --thread=2 --buffersize=100 --netthread=2
|
||||
|
||||
${WORKDIR}/../bin/QuickStartDemoClient --count=100000 --call=asynctup --thread=2 --buffersize=100 --netthread=2
|
||||
${WORKDIR}/../bin/QuickStartDemoClient --count=100000 --call=asynctup --thread=2 --buffersize=100 --netthread=2
|
||||
|
||||
${WORKDIR}/../bin/ProxyServer --config=${WORKDIR}/../../examples/QuickStartDemo/ProxyServer/Server/config.conf &
|
||||
${WORKDIR}/../bin/ProxyServerClient
|
||||
|
||||
|
||||
killall -9 QuickStartDemo
|
||||
killall -9 ProxyServer
|
@ -232,8 +232,6 @@ void Application::waitForShutdown()
|
||||
|
||||
_epollServer->waitForShutdown();
|
||||
|
||||
// waitForQuit();
|
||||
|
||||
destroyApp();
|
||||
|
||||
TarsRemoteNotify::getInstance()->report("stop", true);
|
||||
@ -241,10 +239,6 @@ void Application::waitForShutdown()
|
||||
|
||||
void Application::terminate()
|
||||
{
|
||||
// if(_epollServer)
|
||||
// {
|
||||
// _epollServer->terminate();
|
||||
// }
|
||||
if (_epollServer && !_epollServer->isTerminate())
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复
|
||||
|
@ -25,7 +25,6 @@ namespace tars
|
||||
AsyncProcThread::AsyncProcThread(size_t iQueueCap, bool merge)
|
||||
: _terminate(false), _iQueueCap(iQueueCap), _merge(merge)
|
||||
{
|
||||
// _msgQueue = new ReqInfoQueue(iQueueCap);
|
||||
_msgQueue = new TC_CasQueue<ReqMessage*>();
|
||||
|
||||
if(!_merge)
|
||||
@ -48,7 +47,7 @@ AsyncProcThread::~AsyncProcThread()
|
||||
void AsyncProcThread::terminate()
|
||||
{
|
||||
if(!_merge) {
|
||||
Lock lock(*this);
|
||||
TC_ThreadLock::Lock lock(*this);
|
||||
|
||||
_terminate = true;
|
||||
|
||||
@ -85,19 +84,15 @@ void AsyncProcThread::run()
|
||||
{
|
||||
ReqMessage * msg;
|
||||
|
||||
//异步请求回来的响应包处理
|
||||
if(_msgQueue->empty())
|
||||
{
|
||||
TC_ThreadLock::Lock lock(*this);
|
||||
if(_msgQueue->empty()) {
|
||||
timedWait(1000);
|
||||
}
|
||||
}
|
||||
|
||||
if (_msgQueue->pop_front(msg))
|
||||
{
|
||||
callback(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
TC_ThreadLock::Lock lock(*this);
|
||||
timedWait(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,6 +271,33 @@ void Communicator::initialize()
|
||||
_clientThreadNum = MAX_CLIENT_THREAD_NUM;
|
||||
}
|
||||
|
||||
//异步线程数
|
||||
_asyncThreadNum = TC_Common::strto<size_t>(getProperty("asyncthread", "3"));
|
||||
|
||||
if(_asyncThreadNum == 0)
|
||||
{
|
||||
_asyncThreadNum = 3;
|
||||
}
|
||||
|
||||
if(_asyncThreadNum > MAX_CLIENT_ASYNCTHREAD_NUM)
|
||||
{
|
||||
_asyncThreadNum = MAX_CLIENT_ASYNCTHREAD_NUM;
|
||||
}
|
||||
|
||||
bool merge = TC_Common::strto<bool>(getProperty("mergenetasync", "0"));
|
||||
|
||||
//异步队列的大小
|
||||
size_t iAsyncQueueCap = TC_Common::strto<size_t>(getProperty("asyncqueuecap", "10-000"));
|
||||
if(iAsyncQueueCap < 10000)
|
||||
{
|
||||
iAsyncQueueCap = 10000;
|
||||
}
|
||||
|
||||
//第一个通信器才去启动回调线程
|
||||
for (size_t i = 0; i < _asyncThreadNum; ++i) {
|
||||
_asyncThread.push_back(new AsyncProcThread(iAsyncQueueCap, merge));
|
||||
}
|
||||
|
||||
//stat总是有对象, 保证getStat返回的对象总是有效
|
||||
_statReport = new StatReport(_clientThreadNum);
|
||||
|
||||
@ -280,13 +307,18 @@ void Communicator::initialize()
|
||||
_communicatorEpoll[i]->start();
|
||||
}
|
||||
|
||||
//异步队列数目上报
|
||||
string moduleName = getProperty("modulename", "");
|
||||
if(!moduleName.empty())
|
||||
{
|
||||
_reportAsyncQueue= getStatReport()->createPropertyReport(moduleName + ".asyncqueue", PropertyReport::avg());
|
||||
}
|
||||
|
||||
//初始化统计上报接口
|
||||
string statObj = getProperty("stat", "");
|
||||
|
||||
string propertyObj = getProperty("property", "");
|
||||
|
||||
string moduleName = getProperty("modulename", "");
|
||||
|
||||
int iReportInterval = TC_Common::strto<int>(getProperty("report-interval", "60000"));
|
||||
|
||||
int iReportTimeout = TC_Common::strto<int>(getProperty("report-timeout", "5000"));
|
||||
@ -333,11 +365,40 @@ vector<TC_Endpoint> Communicator::getEndpoint4All(const string & objName)
|
||||
return pServantProxy->getEndpoint4All();
|
||||
}
|
||||
|
||||
void Communicator::doStat()
|
||||
{
|
||||
if(_reportAsyncQueue)
|
||||
{
|
||||
size_t n = 0;
|
||||
for(size_t i = 0;i < _asyncThreadNum; ++i)
|
||||
{
|
||||
n = n + _asyncThread[i]->getSize();
|
||||
}
|
||||
_reportAsyncQueue->report(n);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Communicator::pushAsyncThreadQueue(ReqMessage * msg)
|
||||
{
|
||||
//先不考虑每个线程队列数目不一致的情况
|
||||
_asyncThread[_asyncSeq]->push_back(msg);
|
||||
_asyncSeq ++;
|
||||
|
||||
if(_asyncSeq == _asyncThreadNum)
|
||||
{
|
||||
_asyncSeq = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Communicator::terminate()
|
||||
{
|
||||
{
|
||||
TC_LockT<TC_ThreadRecMutex> lock(*this);
|
||||
|
||||
if (_terminating)
|
||||
return;
|
||||
|
||||
_terminating = true;
|
||||
|
||||
if(_initialized)
|
||||
@ -351,6 +412,22 @@ void Communicator::terminate()
|
||||
{
|
||||
_statReport->terminate();
|
||||
}
|
||||
|
||||
for(size_t i = 0;i < _asyncThreadNum; ++i)
|
||||
{
|
||||
if(_asyncThread[i])
|
||||
{
|
||||
if (_asyncThread[i]->isAlive())
|
||||
{
|
||||
_asyncThread[i]->terminate();
|
||||
_asyncThread[i]->getThreadControl().join();
|
||||
}
|
||||
|
||||
delete _asyncThread[i];
|
||||
_asyncThread[i] = NULL;
|
||||
}
|
||||
}
|
||||
_asyncThread.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,28 +24,19 @@ using namespace std;
|
||||
namespace tars
|
||||
{
|
||||
|
||||
vector<AsyncProcThread*> CommunicatorEpoll::_asyncThread;
|
||||
PropertyReport * CommunicatorEpoll::_reportAsyncQueue = NULL;
|
||||
|
||||
CommunicatorEpoll::CommunicatorEpoll(Communicator * pCommunicator,size_t netThreadSeq)
|
||||
: _communicator(pCommunicator)
|
||||
, _terminate(false)
|
||||
, _nextTime(0)
|
||||
, _nextStatTime(0)
|
||||
, _objectProxyFactory(NULL)
|
||||
, _asyncThreadNum(3)
|
||||
, _asyncSeq(0)
|
||||
// , _asyncThreadNum(3)
|
||||
// , _asyncSeq(0)
|
||||
, _netThreadSeq(netThreadSeq)
|
||||
// , _reportAsyncQueue(NULL)
|
||||
, _noSendQueueLimit(1000)
|
||||
// , _waitTimeout(100)
|
||||
, _timeoutCheckInterval(100)
|
||||
{
|
||||
// _ep.create(1024);
|
||||
|
||||
// _shutdown.createSocket();
|
||||
// _ep.add(_shutdown.getfd(), 0, EPOLLIN);
|
||||
|
||||
_ep.create(1024);
|
||||
|
||||
_terminateFDInfo.notify.init(&_ep);
|
||||
@ -55,19 +46,6 @@ CommunicatorEpoll::CommunicatorEpoll(Communicator * pCommunicator,size_t netThre
|
||||
//ObjectProxyFactory 对象
|
||||
_objectProxyFactory = new ObjectProxyFactory(this);
|
||||
|
||||
//异步线程数
|
||||
_asyncThreadNum = TC_Common::strto<size_t>(pCommunicator->getProperty("asyncthread", "3"));
|
||||
|
||||
if(_asyncThreadNum == 0)
|
||||
{
|
||||
_asyncThreadNum = 3;
|
||||
}
|
||||
|
||||
if(_asyncThreadNum > MAX_CLIENT_ASYNCTHREAD_NUM)
|
||||
{
|
||||
_asyncThreadNum = MAX_CLIENT_ASYNCTHREAD_NUM;
|
||||
}
|
||||
|
||||
//节点队列未发送请求的大小限制
|
||||
_noSendQueueLimit = TC_Common::strto<size_t>(pCommunicator->getProperty("nosendqueuelimit", "100000"));
|
||||
if(_noSendQueueLimit < 1000)
|
||||
@ -75,13 +53,6 @@ CommunicatorEpoll::CommunicatorEpoll(Communicator * pCommunicator,size_t netThre
|
||||
_noSendQueueLimit = 1000;
|
||||
}
|
||||
|
||||
//异步队列的大小
|
||||
size_t iAsyncQueueCap = TC_Common::strto<size_t>(pCommunicator->getProperty("asyncqueuecap", "10-000"));
|
||||
if(iAsyncQueueCap < 10000)
|
||||
{
|
||||
iAsyncQueueCap = 10000;
|
||||
}
|
||||
|
||||
// //epollwait的超时时间
|
||||
// _waitTimeout = TC_Common::strto<int64_t>(pCommunicator->getProperty("epollwaittimeout", "100"));
|
||||
// if(_waitTimeout < 1)
|
||||
@ -96,69 +67,59 @@ CommunicatorEpoll::CommunicatorEpoll(Communicator * pCommunicator,size_t netThre
|
||||
_timeoutCheckInterval = 1;
|
||||
}
|
||||
|
||||
bool merge = TC_Common::strto<bool>(pCommunicator->getProperty("mergenetasync", "0"));
|
||||
|
||||
for(size_t i = 0;i < MAX_CLIENT_NOTIFYEVENT_NUM;++i)
|
||||
{
|
||||
_notify[i] = NULL;
|
||||
}
|
||||
|
||||
if(isFirstNetThread()) {
|
||||
//第一个通信器才去启动回调线程
|
||||
for (size_t i = 0; i < _asyncThreadNum; ++i) {
|
||||
_asyncThread.push_back(new AsyncProcThread(iAsyncQueueCap, merge));
|
||||
}
|
||||
// if(isFirstNetThread()) {
|
||||
|
||||
//异步队列数目上报
|
||||
string moduleName = pCommunicator->getProperty("modulename", "");
|
||||
if(!moduleName.empty())
|
||||
{
|
||||
PropertyReportPtr asyncQueuePtr = pCommunicator->getStatReport()->createPropertyReport(moduleName + ".asyncqueue", PropertyReport::avg());
|
||||
_reportAsyncQueue = asyncQueuePtr.get();
|
||||
}
|
||||
}
|
||||
// //异步线程数
|
||||
// _asyncThreadNum = TC_Common::strto<size_t>(pCommunicator->getProperty("asyncthread", "3"));
|
||||
|
||||
// if(_asyncThreadNum == 0)
|
||||
// {
|
||||
// _asyncThreadNum = 3;
|
||||
// }
|
||||
|
||||
// //创建异步线程
|
||||
// for(size_t i = 0; i < _asyncThreadNum; ++i)
|
||||
// {
|
||||
// _asyncThread[i] = new AsyncProcThread(iAsyncQueueCap);
|
||||
// _asyncThread[i]->start();
|
||||
// if(_asyncThreadNum > MAX_CLIENT_ASYNCTHREAD_NUM)
|
||||
// {
|
||||
// _asyncThreadNum = MAX_CLIENT_ASYNCTHREAD_NUM;
|
||||
// }
|
||||
|
||||
// //第一个通信器才去启动回调线程
|
||||
// for (size_t i = 0; i < _asyncThreadNum; ++i) {
|
||||
// _asyncThread.push_back(new AsyncProcThread(iAsyncQueueCap, merge));
|
||||
// }
|
||||
|
||||
// //异步队列数目上报
|
||||
// string moduleName = pCommunicator->getProperty("modulename", "");
|
||||
// if(!moduleName.empty())
|
||||
// {
|
||||
// PropertyReportPtr asyncQueuePtr = pCommunicator->getStatReport()->createPropertyReport(moduleName + ".asyncqueue", PropertyReport::avg());
|
||||
// _reportAsyncQueue = asyncQueuePtr.get();
|
||||
// }
|
||||
// }
|
||||
|
||||
// //初始化请求的事件通知
|
||||
// for(size_t i = 0; i < MAX_CLIENT_NOTIFYEVENT_NUM; ++i)
|
||||
// {
|
||||
// _notify[i].bValid = false;
|
||||
// }
|
||||
|
||||
// //异步队列数目上报
|
||||
// string moduleName = pCommunicator->getProperty("modulename", "");
|
||||
// if(!moduleName.empty())
|
||||
// {
|
||||
// PropertyReportPtr asyncQueuePtr = pCommunicator->getStatReport()->createPropertyReport(moduleName + ".asyncqueue"+TC_Common::tostr(netThreadSeq), PropertyReport::avg());
|
||||
// _reportAsyncQueue = asyncQueuePtr.get();
|
||||
// }
|
||||
}
|
||||
|
||||
CommunicatorEpoll::~CommunicatorEpoll()
|
||||
{
|
||||
if(isFirstNetThread()) {
|
||||
for(size_t i = 0;i < _asyncThreadNum; ++i)
|
||||
{
|
||||
if(_asyncThread[i])
|
||||
{
|
||||
if (_asyncThread[i]->isAlive())
|
||||
{
|
||||
_asyncThread[i]->terminate();
|
||||
_asyncThread[i]->getThreadControl().join();
|
||||
}
|
||||
// if(isFirstNetThread()) {
|
||||
// for(size_t i = 0;i < _asyncThreadNum; ++i)
|
||||
// {
|
||||
// if(_asyncThread[i])
|
||||
// {
|
||||
// if (_asyncThread[i]->isAlive())
|
||||
// {
|
||||
// _asyncThread[i]->terminate();
|
||||
// _asyncThread[i]->getThreadControl().join();
|
||||
// }
|
||||
|
||||
delete _asyncThread[i];
|
||||
_asyncThread[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
// delete _asyncThread[i];
|
||||
// _asyncThread[i] = NULL;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
for(size_t i = 0;i < MAX_CLIENT_NOTIFYEVENT_NUM;++i)
|
||||
{
|
||||
@ -181,7 +142,6 @@ void CommunicatorEpoll::terminate()
|
||||
_terminate = true;
|
||||
//通知epoll响应
|
||||
_terminateFDInfo.notify.notify();
|
||||
// _ep.mod(_shutdown.getfd(), 0, EPOLLOUT);
|
||||
}
|
||||
|
||||
ObjectProxy * CommunicatorEpoll::getObjectProxy(const string & sObjectProxyName,const string& setName)
|
||||
@ -219,22 +179,6 @@ void CommunicatorEpoll::notify(size_t iSeq,ReqInfoQueue * msgQueue)
|
||||
}
|
||||
|
||||
_notify[iSeq]->notify.notify();
|
||||
// if(_notify[iSeq].bValid)
|
||||
// {
|
||||
// _ep.mod(_notify[iSeq].notify.getfd(),(long long)&_notify[iSeq].stFDInfo, EPOLLIN);
|
||||
// assert(_notify[iSeq].stFDInfo.p == (void*)msgQueue);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _notify[iSeq].stFDInfo.iType = FDInfo::ET_C_NOTIFY;
|
||||
// _notify[iSeq].stFDInfo.p = (void*)msgQueue;
|
||||
// _notify[iSeq].stFDInfo.fd = _notify[iSeq].eventFd;
|
||||
// _notify[iSeq].stFDInfo.iSeq = iSeq;
|
||||
// _notify[iSeq].notify.createSocket();
|
||||
// _notify[iSeq].bValid = true;
|
||||
|
||||
// _ep.add(_notify[iSeq].notify.getfd(),(long long)&_notify[iSeq].stFDInfo, EPOLLIN);
|
||||
// }
|
||||
}
|
||||
|
||||
void CommunicatorEpoll::notifyDel(size_t iSeq)
|
||||
@ -244,11 +188,6 @@ void CommunicatorEpoll::notifyDel(size_t iSeq)
|
||||
{
|
||||
_notify[iSeq]->notify.notify();
|
||||
}
|
||||
|
||||
// if(_notify[iSeq].bValid && NULL != _notify[iSeq].stFDInfo.p)
|
||||
// {
|
||||
// _ep.mod(_notify[iSeq].notify.getfd(),(long long)&_notify[iSeq].stFDInfo, EPOLLIN);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -275,16 +214,6 @@ void CommunicatorEpoll::handleInputImp(Transceiver * pTransceiver)
|
||||
}
|
||||
|
||||
pTransceiver->doResponse();
|
||||
|
||||
// list<ResponsePacket> done;
|
||||
// if(pTransceiver->doResponse(done) > 0)
|
||||
// {
|
||||
// list<ResponsePacket>::iterator it = done.begin();
|
||||
// for (; it != done.end(); ++it)
|
||||
// {
|
||||
// pTransceiver->getAdapterProxy()->finishInvoke(*it);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void CommunicatorEpoll::handleOutputImp(Transceiver * pTransceiver)
|
||||
@ -394,7 +323,6 @@ void CommunicatorEpoll::handle(FDInfo * pFDInfo, const epoll_event &ev)
|
||||
Transceiver *pTransceiver = (Transceiver*)pFDInfo->p;
|
||||
|
||||
//先收包
|
||||
// if (events & EPOLLIN)
|
||||
if(TC_Epoller::readEvent(ev))
|
||||
{
|
||||
try
|
||||
@ -412,7 +340,6 @@ void CommunicatorEpoll::handle(FDInfo * pFDInfo, const epoll_event &ev)
|
||||
}
|
||||
|
||||
//发包
|
||||
// if (events & EPOLLOUT)
|
||||
if(TC_Epoller::writeEvent(ev))
|
||||
{
|
||||
try
|
||||
@ -430,7 +357,6 @@ void CommunicatorEpoll::handle(FDInfo * pFDInfo, const epoll_event &ev)
|
||||
}
|
||||
|
||||
//连接出错 直接关闭连接
|
||||
// if(events & EPOLLERR)
|
||||
if(TC_Epoller::errorEvent(ev))
|
||||
{
|
||||
try
|
||||
@ -471,11 +397,6 @@ void CommunicatorEpoll::doTimeout()
|
||||
|
||||
for(size_t i = 0; i < _objectProxyFactory->getObjNum(); ++i)
|
||||
{
|
||||
// const vector<AdapterProxy*> & vAdapterProxy=_objectProxyFactory->getObjectProxy(i)->getAdapters();
|
||||
// for(size_t iAdapter=0;iAdapter<vAdapterProxy.size();++iAdapter)
|
||||
// {
|
||||
// vAdapterProxy[iAdapter]->doTimeout();
|
||||
// }
|
||||
_objectProxyFactory->getObjectProxy(i)->doTimeout();
|
||||
}
|
||||
}
|
||||
@ -490,16 +411,18 @@ void CommunicatorEpoll::doStat()
|
||||
_nextStatTime = iNow + 10;
|
||||
|
||||
if(isFirstNetThread()) {
|
||||
//异步队列长度上报
|
||||
if(_reportAsyncQueue)
|
||||
{
|
||||
size_t n = 0;
|
||||
for(size_t i = 0;i < _asyncThreadNum; ++i)
|
||||
{
|
||||
n = n + _asyncThread[i]->getSize();
|
||||
}
|
||||
_reportAsyncQueue->report(n);
|
||||
}
|
||||
|
||||
_communicator->doStat();
|
||||
// //异步队列长度上报
|
||||
// if(_reportAsyncQueue)
|
||||
// {
|
||||
// size_t n = 0;
|
||||
// for(size_t i = 0;i < _asyncThreadNum; ++i)
|
||||
// {
|
||||
// n = n + _asyncThread[i]->getSize();
|
||||
// }
|
||||
// _reportAsyncQueue->report(n);
|
||||
// }
|
||||
}
|
||||
|
||||
StatReport::MapStatMicMsg mStatMicMsg;
|
||||
@ -507,12 +430,6 @@ void CommunicatorEpoll::doStat()
|
||||
for(size_t i = 0;i < _objectProxyFactory->getObjNum(); ++i)
|
||||
{
|
||||
_objectProxyFactory->getObjectProxy(i)->mergeStat(mStatMicMsg);
|
||||
|
||||
// const vector<AdapterProxy*> & vAdapterProxy = _objectProxyFactory->getObjectProxy(i)->getAdapters();
|
||||
// for(size_t iAdapter = 0;iAdapter < vAdapterProxy.size(); ++iAdapter)
|
||||
// {
|
||||
// vAdapterProxy[iAdapter]->doStat(mStatMicMsg);
|
||||
// }
|
||||
}
|
||||
|
||||
//有数据才上报
|
||||
@ -525,14 +442,15 @@ void CommunicatorEpoll::doStat()
|
||||
|
||||
void CommunicatorEpoll::pushAsyncThreadQueue(ReqMessage * msg)
|
||||
{
|
||||
//先不考虑每个线程队列数目不一致的情况
|
||||
_asyncThread[_asyncSeq]->push_back(msg);
|
||||
_asyncSeq ++;
|
||||
_communicator->pushAsyncThreadQueue(msg);
|
||||
// //先不考虑每个线程队列数目不一致的情况
|
||||
// _asyncThread[_asyncSeq]->push_back(msg);
|
||||
// _asyncSeq ++;
|
||||
|
||||
if(_asyncSeq == _asyncThreadNum)
|
||||
{
|
||||
_asyncSeq = 0;
|
||||
}
|
||||
// if(_asyncSeq == _asyncThreadNum)
|
||||
// {
|
||||
// _asyncSeq = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
void CommunicatorEpoll::run()
|
||||
@ -562,7 +480,6 @@ void CommunicatorEpoll::run()
|
||||
const epoll_event& ev = _ep.get(i);
|
||||
|
||||
uint64_t data = TC_Epoller::getU64(ev);
|
||||
// uint64_t data = ev.data.u64;
|
||||
|
||||
if(data == 0)
|
||||
{
|
||||
|
@ -39,99 +39,6 @@
|
||||
namespace tars
|
||||
{
|
||||
|
||||
// ////////////////////////////////////////////////////////
|
||||
// std::size_t pagesize()
|
||||
// {
|
||||
// static std::size_t size = ::sysconf( _SC_PAGESIZE);
|
||||
// return size;
|
||||
// }
|
||||
|
||||
// rlimit stacksize_limit_()
|
||||
// {
|
||||
// rlimit limit;
|
||||
|
||||
// const int result = ::getrlimit( RLIMIT_STACK, & limit);
|
||||
// assert( 0 == result);
|
||||
|
||||
// return limit;
|
||||
// }
|
||||
|
||||
// rlimit stacksize_limit()
|
||||
// {
|
||||
// static rlimit limit = stacksize_limit_();
|
||||
// return limit;
|
||||
// }
|
||||
|
||||
// std::size_t page_count( std::size_t stacksize)
|
||||
// {
|
||||
// return static_cast< std::size_t >( std::ceil(static_cast< float >(stacksize) / pagesize() ) );
|
||||
// }
|
||||
|
||||
// bool standard_stack_allocator::is_stack_unbound()
|
||||
// {
|
||||
// return RLIM_INFINITY == stacksize_limit().rlim_max;
|
||||
// }
|
||||
|
||||
// std::size_t standard_stack_allocator::default_stacksize()
|
||||
// {
|
||||
// std::size_t size = 8 * minimum_stacksize();
|
||||
// if ( is_stack_unbound() ) return size;
|
||||
|
||||
// assert( maximum_stacksize() >= minimum_stacksize() );
|
||||
// return maximum_stacksize() == size ? size : (std::min)( size, maximum_stacksize() );
|
||||
// }
|
||||
|
||||
// std::size_t standard_stack_allocator::minimum_stacksize()
|
||||
// {
|
||||
// return 8 * 1024 + sizeof(fcontext_t) + 15;
|
||||
// }
|
||||
|
||||
// std::size_t standard_stack_allocator::maximum_stacksize()
|
||||
// {
|
||||
// assert( ! is_stack_unbound() );
|
||||
// return static_cast< std::size_t >( stacksize_limit().rlim_max);
|
||||
// }
|
||||
|
||||
// int standard_stack_allocator::allocate( stack_context & ctx, std::size_t size)
|
||||
// {
|
||||
// assert( minimum_stacksize() <= size);
|
||||
// assert( is_stack_unbound() || ( maximum_stacksize() >= size) );
|
||||
|
||||
// const std::size_t pages( page_count( size) + 1);
|
||||
// const std::size_t size_( pages * pagesize() );
|
||||
// assert( 0 < size && 0 < size_);
|
||||
|
||||
// void * limit = ::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
|
||||
// if (limit == (void *) -1)
|
||||
// {
|
||||
// TLOGERROR("[TARS][[standard_stack_allocator::allocate memory failed]" << endl);
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// std::memset( limit, '\0', size_);
|
||||
|
||||
// const int result( ::mprotect( limit, pagesize(), PROT_NONE) );
|
||||
// assert( 0 == result);
|
||||
|
||||
// ctx.size = size_;
|
||||
// ctx.sp = static_cast< char * >( limit) + ctx.size;
|
||||
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// void standard_stack_allocator::deallocate( stack_context & ctx)
|
||||
// {
|
||||
// assert( ctx.sp);
|
||||
// assert( minimum_stacksize() <= ctx.size);
|
||||
// assert( is_stack_unbound() || ( maximum_stacksize() >= ctx.size) );
|
||||
|
||||
// void * limit = static_cast< char * >( ctx.sp) - ctx.size;
|
||||
|
||||
// ::munmap( limit, ctx.size);
|
||||
// }
|
||||
|
||||
|
||||
#if TARGET_PLATFORM_WINDOWS
|
||||
|
||||
// x86_64
|
||||
|
@ -27,7 +27,7 @@ namespace tars
|
||||
/**
|
||||
* 异步回调后的处理线程
|
||||
*/
|
||||
class AsyncProcThread : public TC_Thread, public TC_HandleBase, public TC_ThreadLock
|
||||
class AsyncProcThread : public TC_Thread, public TC_ThreadLock
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@ -75,7 +75,6 @@ private:
|
||||
* 异步队列
|
||||
*/
|
||||
TC_CasQueue<ReqMessage*> * _msgQueue;
|
||||
// ReqInfoQueue * _msgQueue;
|
||||
|
||||
/**
|
||||
* 队列流量控制
|
||||
|
@ -246,6 +246,18 @@ protected:
|
||||
*/
|
||||
ServantProxy * getServantProxy(const string& objectName,const string& setName="");
|
||||
|
||||
/**
|
||||
* 数据加入到异步线程队列里面
|
||||
* @return
|
||||
*/
|
||||
void pushAsyncThreadQueue(ReqMessage * msg);
|
||||
|
||||
/**
|
||||
* 上报统计事件
|
||||
* @return
|
||||
*/
|
||||
void doStat();
|
||||
|
||||
/**
|
||||
* 框架内部需要直接访问通信器的类
|
||||
*/
|
||||
@ -309,6 +321,26 @@ protected:
|
||||
*/
|
||||
int64_t _minTimeout;
|
||||
|
||||
/*
|
||||
* 异步线程数组
|
||||
*/
|
||||
//异步线程(跨通信器共享)
|
||||
vector<AsyncProcThread*> _asyncThread;//[MAX_THREAD_NUM];
|
||||
|
||||
/*
|
||||
* 异步队列的统计上报的对象
|
||||
*/
|
||||
PropertyReportPtr _reportAsyncQueue;
|
||||
|
||||
/*
|
||||
* 异步线程数目
|
||||
*/
|
||||
size_t _asyncThreadNum;
|
||||
/*
|
||||
* 分发给异步线程的索引seq
|
||||
*/
|
||||
size_t _asyncSeq;
|
||||
|
||||
#ifdef _USE_OPENTRACKING
|
||||
public:
|
||||
struct TraceManager:public TC_HandleBase{
|
||||
|
@ -82,34 +82,6 @@ struct FDInfo
|
||||
class CommunicatorEpoll : public TC_Thread ,public TC_ThreadRecMutex
|
||||
{
|
||||
public:
|
||||
// struct NotifyInfo
|
||||
// {
|
||||
// /**
|
||||
// * 构造函数
|
||||
// */
|
||||
// NotifyInfo()
|
||||
// : eventFd(-1)
|
||||
// , bValid(false)
|
||||
// {
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 析构函数
|
||||
// */
|
||||
// ~NotifyInfo()
|
||||
// {
|
||||
// }
|
||||
|
||||
|
||||
// FDInfo stFDInfo; //通知FD信息
|
||||
|
||||
// TC_Socket notify; //通知fd
|
||||
|
||||
// int eventFd; //eventfd,目前未使用
|
||||
|
||||
// bool bValid; //是否有效
|
||||
// };
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
@ -194,14 +166,9 @@ public:
|
||||
void delFd(int fd,FDInfo * info, uint32_t events);
|
||||
|
||||
void modFd(int fd,FDInfo * info, uint32_t events);
|
||||
/**
|
||||
* 通知事件过来
|
||||
* @param fd
|
||||
*/
|
||||
// void notify(size_t iSeq,ReqInfoQueue * pReqQueue);
|
||||
|
||||
/**
|
||||
* 通知删除事件过来
|
||||
* 通知事件过来
|
||||
* @param iSeq
|
||||
*/
|
||||
void notify(size_t iSeq,ReqInfoQueue * pReqQueue);
|
||||
@ -252,19 +219,7 @@ protected:
|
||||
*/
|
||||
Communicator * _communicator;
|
||||
|
||||
// bool _notifySignal[MAX_CLIENT_NOTIFYEVENT_NUM];
|
||||
|
||||
FDInfo* _notify[MAX_CLIENT_NOTIFYEVENT_NUM];
|
||||
/*
|
||||
* 请求事件通知数组
|
||||
*/
|
||||
// NotifyInfo _notify[MAX_CLIENT_NOTIFYEVENT_NUM];
|
||||
|
||||
/*
|
||||
* 关闭线程请求的事件通知
|
||||
*/
|
||||
// TC_Socket _shutdown;
|
||||
|
||||
/*
|
||||
* 线程是否终止
|
||||
*/
|
||||
@ -292,27 +247,26 @@ protected:
|
||||
*/
|
||||
ObjectProxyFactory * _objectProxyFactory;
|
||||
|
||||
/*
|
||||
* 异步线程数组
|
||||
*/
|
||||
// AsyncProcThread * _asyncThread[MAX_CLIENT_ASYNCTHREAD_NUM];
|
||||
//异步线程(跨通信器共享)
|
||||
static vector<AsyncProcThread*> _asyncThread;//[MAX_THREAD_NUM];
|
||||
// /*
|
||||
// * 异步线程数组
|
||||
// */
|
||||
// //异步线程(跨通信器共享)
|
||||
// vector<AsyncProcThread*> _asyncThread;//[MAX_THREAD_NUM];
|
||||
|
||||
/*
|
||||
* 异步队列的统计上报的对象
|
||||
*/
|
||||
static PropertyReport * _reportAsyncQueue;
|
||||
// /*
|
||||
// * 异步队列的统计上报的对象
|
||||
// */
|
||||
// PropertyReport * _reportAsyncQueue;
|
||||
|
||||
/*
|
||||
* 异步线程数目
|
||||
*/
|
||||
size_t _asyncThreadNum;
|
||||
// /*
|
||||
// * 异步线程数目
|
||||
// */
|
||||
// size_t _asyncThreadNum;
|
||||
|
||||
/*
|
||||
* 分发给异步线程的索引seq
|
||||
*/
|
||||
size_t _asyncSeq;
|
||||
// size_t _asyncSeq;
|
||||
|
||||
/*
|
||||
* 网络线程的id号
|
||||
@ -323,12 +277,7 @@ protected:
|
||||
* 节点ip队列未发送请求的大小限制
|
||||
*/
|
||||
size_t _noSendQueueLimit;
|
||||
|
||||
/*
|
||||
* epoll wait的超时时间
|
||||
*/
|
||||
// int64_t _waitTimeout;
|
||||
|
||||
|
||||
/*
|
||||
* 超时的检查时间间隔
|
||||
*/
|
||||
|
@ -195,8 +195,7 @@ public:
|
||||
|
||||
{
|
||||
TC_LockT<TC_SpinLock> lock(_mutex);
|
||||
vRet = _vReqMessage;
|
||||
_vReqMessage.clear();
|
||||
vRet.swap(_vReqMessage);
|
||||
}
|
||||
|
||||
return vRet;
|
||||
|
@ -1217,7 +1217,7 @@ string Tars2Cpp::generateDispatchExceptionAsync(const OperationPtr& pPtr, const
|
||||
// return s.str();
|
||||
// }
|
||||
|
||||
string Tars2Cpp::generateDispatchCoroResponseAsync(const OperationPtr& pPtr, const string& cn) const
|
||||
string Tars2Cpp::generateDispatchCoroExceptionAsync(const OperationPtr& pPtr, const string& cn) const
|
||||
{
|
||||
ostringstream s;
|
||||
|
||||
@ -1232,7 +1232,7 @@ string Tars2Cpp::generateDispatchCoroResponseAsync(const OperationPtr& pPtr, con
|
||||
}
|
||||
|
||||
|
||||
string Tars2Cpp::generateDispatchCoroExceptionAsync(const OperationPtr& pPtr, const string& cn) const
|
||||
string Tars2Cpp::generateDispatchCoroResponseAsync(const OperationPtr& pPtr, const string& cn) const
|
||||
{
|
||||
ostringstream s;
|
||||
|
||||
|
@ -3075,14 +3075,14 @@ void TC_EpollServer::waitForShutdown()
|
||||
}
|
||||
|
||||
int64_t iLastCheckTime = TNOWMS;
|
||||
while (!_bTerminate)
|
||||
{
|
||||
try
|
||||
{
|
||||
// while (!_bTerminate)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
//循环监听网路连接请求
|
||||
while (!_bTerminate)
|
||||
{
|
||||
int iEvNum = _epoller.wait(300);
|
||||
int iEvNum = _epoller.wait(3000);
|
||||
|
||||
if (_bTerminate)
|
||||
break;
|
||||
@ -3136,18 +3136,22 @@ void TC_EpollServer::waitForShutdown()
|
||||
{
|
||||
error("run exception:" + string(ex.what()));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
error("run exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (exception &ex)
|
||||
{
|
||||
error(string("TC_EpollServer::waitForShutdown error : ") + ex.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
error("TC_EpollServer::waitForShutdown unknown error");
|
||||
}
|
||||
}
|
||||
// }
|
||||
// catch (exception &ex)
|
||||
// {
|
||||
// error(string("TC_EpollServer::waitForShutdown error : ") + ex.what());
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// error("TC_EpollServer::waitForShutdown unknown error");
|
||||
// }
|
||||
// }
|
||||
|
||||
for (size_t i = 0; i < _netThreads.size(); ++i)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user