mirror of
https://gitee.com/TarsCloud/TarsCpp.git
synced 2024-12-22 22:16:38 +08:00
fix tc_file get ext bug, add cmake_tars_server.bat for windows
This commit is contained in:
parent
030eb7ad8f
commit
121adade0d
@ -1,471 +0,0 @@
|
||||
// **********************************************************************
|
||||
// This file was generated by a TARS parser!
|
||||
// TARS version 2.0.0.
|
||||
// **********************************************************************
|
||||
|
||||
#ifndef __HELLO_H_
|
||||
#define __HELLO_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 TestApp
|
||||
{
|
||||
|
||||
/* callback of async proxy for client */
|
||||
class HelloPrxCallback: public tars::ServantProxyCallback
|
||||
{
|
||||
public:
|
||||
virtual ~HelloPrxCallback(){}
|
||||
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_testHello(tars::Int32 ret, const std::string& sRsp)
|
||||
{ throw std::runtime_error("callback_testHello() override incorrect."); }
|
||||
virtual void callback_testHello_exception(tars::Int32 ret)
|
||||
{ throw std::runtime_error("callback_testHello_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 onDispatch(tars::ReqMessagePtr msg)
|
||||
{
|
||||
static ::std::string __Hello_all[]=
|
||||
{
|
||||
"test",
|
||||
"testHello"
|
||||
};
|
||||
pair<string*, string*> r = equal_range(__Hello_all, __Hello_all+2, string(msg->request.sFuncName));
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Hello_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (msg->response->iRet != tars::TARSSERVERSUCCESS)
|
||||
{
|
||||
callback_test_exception(msg->response->iRet);
|
||||
|
||||
return msg->response->iRet;
|
||||
}
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(msg->response->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(msg->response->context);
|
||||
|
||||
callback_test(_ret);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if (msg->response->iRet != tars::TARSSERVERSUCCESS)
|
||||
{
|
||||
callback_testHello_exception(msg->response->iRet);
|
||||
|
||||
return msg->response->iRet;
|
||||
}
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(msg->response->sBuffer);
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sRsp;
|
||||
_is.read(sRsp, 2, true);
|
||||
CallbackThreadData * pCbtd = CallbackThreadData::getData();
|
||||
assert(pCbtd != NULL);
|
||||
|
||||
pCbtd->setResponseContext(msg->response->context);
|
||||
|
||||
callback_testHello(_ret, sRsp);
|
||||
|
||||
pCbtd->delResponseContext();
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
};
|
||||
typedef tars::TC_AutoPtr<HelloPrxCallback> HelloPrxCallbackPtr;
|
||||
|
||||
/* callback of coroutine async proxy for client */
|
||||
class HelloCoroPrxCallback: public HelloPrxCallback
|
||||
{
|
||||
public:
|
||||
virtual ~HelloCoroPrxCallback(){}
|
||||
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:
|
||||
int onDispatch(tars::ReqMessagePtr msg)
|
||||
{
|
||||
static ::std::string __Hello_all[]=
|
||||
{
|
||||
"test",
|
||||
"testHello"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__Hello_all, __Hello_all+2, string(msg->request.sFuncName));
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __Hello_all)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (msg->response->iRet != tars::TARSSERVERSUCCESS)
|
||||
{
|
||||
callback_test_exception(msg->response->iRet);
|
||||
|
||||
return msg->response->iRet;
|
||||
}
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(msg->response->sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
setResponseContext(msg->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:
|
||||
{
|
||||
if (msg->response->iRet != tars::TARSSERVERSUCCESS)
|
||||
{
|
||||
callback_testHello_exception(msg->response->iRet);
|
||||
|
||||
return msg->response->iRet;
|
||||
}
|
||||
tars::TarsInputStream<tars::BufferReader> _is;
|
||||
|
||||
_is.setBuffer(msg->response->sBuffer);
|
||||
try
|
||||
{
|
||||
tars::Int32 _ret;
|
||||
_is.read(_ret, 0, true);
|
||||
|
||||
std::string sRsp;
|
||||
_is.read(sRsp, 2, true);
|
||||
setResponseContext(msg->response->context);
|
||||
|
||||
callback_testHello(_ret, sRsp);
|
||||
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
callback_testHello_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
callback_testHello_exception(tars::TARSCLIENTDECODEERR);
|
||||
|
||||
return tars::TARSCLIENTDECODEERR;
|
||||
}
|
||||
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
|
||||
protected:
|
||||
map<std::string, std::string> _mRspContext;
|
||||
};
|
||||
typedef tars::TC_AutoPtr<HelloCoroPrxCallback> HelloCoroPrxCallbackPtr;
|
||||
|
||||
/* proxy for client */
|
||||
class HelloProxy : 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(HelloPrxCallbackPtr 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(HelloCoroPrxCallbackPtr 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 testHello(const std::string & sReq,std::string &sRsp,const map<string, string> &context = TARS_CONTEXT(),map<string, string> * pResponseContext = NULL)
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sReq, 1);
|
||||
_os.write(sRsp, 2);
|
||||
std::map<string, string> _mStatus;
|
||||
shared_ptr<tars::ResponsePacket> rep = tars_invoke(tars::TARSNORMAL,"testHello", _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(sRsp, 2, true);
|
||||
return _ret;
|
||||
}
|
||||
|
||||
void async_testHello(HelloPrxCallbackPtr callback,const std::string &sReq,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sReq, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testHello", _os, context, _mStatus, callback);
|
||||
}
|
||||
|
||||
void coro_testHello(HelloCoroPrxCallbackPtr callback,const std::string &sReq,const map<string, string>& context = TARS_CONTEXT())
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(sReq, 1);
|
||||
std::map<string, string> _mStatus;
|
||||
tars_invoke_async(tars::TARSNORMAL,"testHello", _os, context, _mStatus, callback, true);
|
||||
}
|
||||
|
||||
HelloProxy* tars_hash(int64_t key)
|
||||
{
|
||||
return (HelloProxy*)ServantProxy::tars_hash(key);
|
||||
}
|
||||
|
||||
HelloProxy* tars_consistent_hash(int64_t key)
|
||||
{
|
||||
return (HelloProxy*)ServantProxy::tars_consistent_hash(key);
|
||||
}
|
||||
|
||||
HelloProxy* tars_set_timeout(int msecond)
|
||||
{
|
||||
return (HelloProxy*)ServantProxy::tars_set_timeout(msecond);
|
||||
}
|
||||
|
||||
static const char* tars_prxname() { return "HelloProxy"; }
|
||||
};
|
||||
typedef tars::TC_AutoPtr<HelloProxy> HelloPrx;
|
||||
|
||||
/* servant for server */
|
||||
class Hello : public tars::Servant
|
||||
{
|
||||
public:
|
||||
virtual ~Hello(){}
|
||||
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 testHello(const std::string & sReq,std::string &sRsp,tars::TarsCurrentPtr current) = 0;
|
||||
static void async_response_testHello(tars::TarsCurrentPtr current, tars::Int32 _ret, const std::string &sRsp)
|
||||
{
|
||||
if (current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sRsp", sRsp);
|
||||
|
||||
vector<char> sTupResponseBuffer;
|
||||
tarsAttr.encode(sTupResponseBuffer);
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
|
||||
_os.write(sRsp, 2);
|
||||
|
||||
current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
int onDispatch(tars::TarsCurrentPtr _current, vector<char> &_sResponseBuffer)
|
||||
{
|
||||
static ::std::string __TestApp__Hello_all[]=
|
||||
{
|
||||
"test",
|
||||
"testHello"
|
||||
};
|
||||
|
||||
pair<string*, string*> r = equal_range(__TestApp__Hello_all, __TestApp__Hello_all+2, _current->getFuncName());
|
||||
if(r.first == r.second) return tars::TARSSERVERNOFUNCERR;
|
||||
switch(r.first - __TestApp__Hello_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 sReq;
|
||||
std::string sRsp;
|
||||
if (_current->getRequestVersion() == TUPVERSION)
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.decode(_current->getRequestBuffer());
|
||||
tarsAttr.get("sReq", sReq);
|
||||
tarsAttr.getByDefault("sRsp", sRsp, sRsp);
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.read(sReq, 1, true);
|
||||
_is.read(sRsp, 2, false);
|
||||
}
|
||||
tars::Int32 _ret = testHello(sReq,sRsp, _current);
|
||||
if(_current->isResponse())
|
||||
{
|
||||
if (_current->getRequestVersion() == TUPVERSION )
|
||||
{
|
||||
UniAttribute<tars::BufferWriterVector, tars::BufferReader> tarsAttr;
|
||||
tarsAttr.setVersion(_current->getRequestVersion());
|
||||
tarsAttr.put("", _ret);
|
||||
tarsAttr.put("sRsp", sRsp);
|
||||
tarsAttr.encode(_sResponseBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
tars::TarsOutputStream<tars::BufferWriterVector> _os;
|
||||
_os.write(_ret, 0);
|
||||
_os.write(sRsp, 2);
|
||||
_os.swap(_sResponseBuffer);
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERSUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
return tars::TARSSERVERNOFUNCERR;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Created by jarod on 2020/2/20.
|
||||
//
|
||||
|
||||
@ -56,7 +56,38 @@ void Test_TC_File::test()
|
||||
|
||||
cout << "simplifyDirectory:" << TC_File::simplifyDirectory("/.") << endl;
|
||||
cout << "simplifyDirectory:" << TC_File::simplifyDirectory("/./ab/tt//t///t//../tt/") << endl;
|
||||
assert(TC_File::simplifyDirectory("/./ab/tt//t///t//../tt/") == "ab\\tt\\t\\tt");
|
||||
#if TARGET_PLATFORM_WINDOWS
|
||||
cout << "simplifyDirectory:" << TC_File::simplifyDirectory("c:/ab/tt//t///t//../tt/") << endl;
|
||||
assert(TC_File::simplifyDirectory("c:/ab/tt//t///t//../tt/") == "c:\\ab\\tt\\t\\tt");
|
||||
#endif
|
||||
|
||||
assert(TC_File::extractFileExt("/usr/local/app/bin.exe") == "exe");
|
||||
assert(TC_File::extractFileExt("/usr/local/app/bin") == "");
|
||||
assert(TC_File::extractFileExt("/usr/local/app.dir/bin.exe") == "exe");
|
||||
assert(TC_File::extractFileExt("c:\\usr\\local\\app.dir\\bin.exe") == "exe");
|
||||
assert(TC_File::extractFileExt("c:\\usr\\local\\app.dir\\bin") == "");
|
||||
|
||||
assert(TC_File::extractFileName("/usr/local/app/bin.exe") == "bin.exe");
|
||||
assert(TC_File::extractFileName("/usr/local/app/bin") == "bin");
|
||||
assert(TC_File::extractFileName("/usr/local/app.dir/bin.exe") == "bin.exe");
|
||||
assert(TC_File::extractFileName("c:\\usr\\local\\app.dir\\bin.exe") == "bin.exe");
|
||||
assert(TC_File::extractFileName("c:\\usr\\local\\app.dir\\bin") == "bin");
|
||||
assert(TC_File::extractFileName("bin.exe") == "bin.exe");
|
||||
|
||||
assert(TC_File::extractFilePath("/usr/local/app/bin.exe") == "/usr/local/app/");
|
||||
assert(TC_File::extractFilePath("/usr/local/app/bin") == "/usr/local/app/");
|
||||
assert(TC_File::extractFilePath("/usr/local/app.dir/bin.exe") == "/usr/local/app.dir/");
|
||||
assert(TC_File::extractFilePath("c:\\usr\\local\\app.dir\\bin.exe") == "c:\\usr\\local\\app.dir\\");
|
||||
assert(TC_File::extractFilePath("c:\\usr\\local\\app.dir\\bin") == "c:\\usr\\local\\app.dir\\");
|
||||
assert(TC_File::extractFilePath("temp.gif") == string(".") + FILE_SEP);
|
||||
|
||||
assert(TC_File::excludeFileExt("/usr/local/app/bin.exe") == "/usr/local/app/bin");
|
||||
|
||||
assert(TC_File::excludeFileExt("/usr/local/app/bin") == "/usr/local/app/bin");
|
||||
assert(TC_File::excludeFileExt("/usr/local/app.dir/bin.exe") == "/usr/local/app.dir/bin");
|
||||
assert(TC_File::excludeFileExt("c:\\usr\\local\\app.dir\\bin.exe") == "c:\\usr\\local\\app.dir\\bin");
|
||||
assert(TC_File::excludeFileExt("c:\\usr\\local\\app.dir\\bin") == "c:\\usr\\local\\app.dir\\bin");
|
||||
assert(TC_File::excludeFileExt("temp.gif") == "temp");
|
||||
|
||||
}
|
||||
|
1
servant/script/cmake_http_server.bat
Normal file
1
servant/script/cmake_http_server.bat
Normal file
@ -0,0 +1 @@
|
||||
c:\\tars\\cpp\\script\\busybox.exe bash c:\\tars\\cpp\\script\\cmake_http_server.sh %1 %2 %3 c:/tars
|
1
servant/script/cmake_tars_server.bat
Normal file
1
servant/script/cmake_tars_server.bat
Normal file
@ -0,0 +1 @@
|
||||
c:\\tars\\cpp\\script\\busybox.exe bash c:\\tars\\cpp\\script\\cmake_tars_server.sh %1 %2 %3 c:/tars
|
@ -1965,4 +1965,4 @@ namespace tars
|
||||
#include "tup/TarsDisplayer.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
@ -8,7 +8,7 @@
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <string.h>
|
||||
|
||||
#include "tup/TarsType.h"
|
||||
#include "util/tc_json.h"
|
||||
#include "util/tc_common.h"
|
||||
|
||||
@ -17,7 +17,7 @@ namespace tars
|
||||
class JsonInput
|
||||
{
|
||||
public:
|
||||
static void readJson(Bool& b, const JsonValuePtr & p, bool isRequire = true)
|
||||
static void readJson(tars::Bool& b, const JsonValuePtr & p, bool isRequire = true)
|
||||
{
|
||||
if(NULL != p.get() && p->getType() == eJsonTypeBoolean)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
* Tencent is pleased to support the open source community by making Tars available.
|
||||
*
|
||||
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
|
||||
@ -43,6 +43,7 @@ typedef short Short;
|
||||
typedef float Float;
|
||||
typedef double Double;
|
||||
typedef int Int32;
|
||||
struct TarsStructBase;
|
||||
|
||||
typedef unsigned char UInt8;
|
||||
typedef unsigned short UInt16;
|
||||
|
@ -62,6 +62,10 @@ public:
|
||||
static int closeSocket(int fd);
|
||||
|
||||
static int64_t getpid();
|
||||
|
||||
static std::string getEnv(const std::string &name);
|
||||
|
||||
static void setEnv(const std::string &name, const std::string &value);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ string TC_Exception::parseError(int err)
|
||||
|
||||
FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
NULL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
|
||||
(LPTSTR) & lpMsgBuf, 0, NULL);
|
||||
|
||||
// errMsg = Unicode2ANSI((LPCWSTR)lpMsgBuf);
|
||||
|
@ -292,26 +292,28 @@ string TC_File::simplifyDirectory(const string& path)
|
||||
result = TC_Common::replace(result, "\\", "/");
|
||||
#endif
|
||||
|
||||
string sep(FILE_SEP);
|
||||
|
||||
string::size_type pos;
|
||||
|
||||
pos = 0;
|
||||
while((pos = result.find(string(FILE_SEP) + FILE_SEP, pos)) != string::npos)
|
||||
while((pos = result.find(sep + FILE_SEP, pos)) != string::npos)
|
||||
{
|
||||
result.erase(pos, 1);
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
while((pos = result.find(string(FILE_SEP) + "." + FILE_SEP, pos)) != string::npos)
|
||||
while((pos = result.find(sep+ "." + FILE_SEP, pos)) != string::npos)
|
||||
{
|
||||
result.erase(pos, 2);
|
||||
}
|
||||
|
||||
while(result.substr(0, 4) == string(FILE_SEP) + ".." + FILE_SEP)
|
||||
while(result.substr(0, 4) == sep + ".." + FILE_SEP)
|
||||
{
|
||||
result.erase(0, 3);
|
||||
}
|
||||
|
||||
if(result.find(string(FILE_SEP) + ".." + FILE_SEP) != string::npos)
|
||||
if(result.find(sep + ".." + FILE_SEP) != string::npos)
|
||||
{
|
||||
bool ab = TC_File::isAbsolute(result);
|
||||
|
||||
@ -350,12 +352,12 @@ string TC_File::simplifyDirectory(const string& path)
|
||||
#endif
|
||||
}
|
||||
|
||||
if(result == string(FILE_SEP) + ".")
|
||||
if(result == sep + ".")
|
||||
{
|
||||
return result.substr(0, result.size() - 1);
|
||||
}
|
||||
|
||||
if(result.size() >= 2 && result.substr(result.size() - 2, 2) == string(FILE_SEP) + ".")
|
||||
if(result.size() >= 2 && result.substr(result.size() - 2, 2) == sep + ".")
|
||||
{
|
||||
result.erase(result.size() - 2, 2);
|
||||
}
|
||||
@ -370,7 +372,7 @@ string TC_File::simplifyDirectory(const string& path)
|
||||
result.erase(result.size() - 1);
|
||||
}
|
||||
|
||||
if(result == string(FILE_SEP) + "..")
|
||||
if(result == sep + "..")
|
||||
{
|
||||
result = FILE_SEP;
|
||||
}
|
||||
@ -458,61 +460,97 @@ string TC_File::extractFileName(const string &sFullFileName)
|
||||
return "";
|
||||
}
|
||||
|
||||
string::size_type pos = sFullFileName.rfind(FILE_SEP);
|
||||
if(pos == string::npos)
|
||||
string::size_type found = sFullFileName.find_last_of("/\\");
|
||||
|
||||
// string::size_type pos = sFullFileName.rfind(FILE_SEP);
|
||||
if(found == string::npos)
|
||||
{
|
||||
return sFullFileName;
|
||||
}
|
||||
|
||||
return sFullFileName.substr(pos + 1);
|
||||
return sFullFileName.substr(found + 1);
|
||||
}
|
||||
|
||||
string TC_File::extractFilePath(const string &sFullFileName)
|
||||
{
|
||||
#if TARGET_PLATFORM_WINDOWS
|
||||
string sFullFileNameTmp = TC_Common::replace(sFullFileName, "/", "\\");
|
||||
#else
|
||||
string sFullFileNameTmp = TC_Common::replace(sFullFileName, "\\", "/");
|
||||
#endif
|
||||
// #if TARGET_PLATFORM_WINDOWS
|
||||
// string sFullFileNameTmp = TC_Common::replace(sFullFileName, "/", "\\");
|
||||
// #else
|
||||
// string sFullFileNameTmp = TC_Common::replace(sFullFileName, "\\", "/");
|
||||
// #endif
|
||||
|
||||
if (sFullFileNameTmp.length() <= 0)
|
||||
if (sFullFileName.length() <= 0)
|
||||
{
|
||||
return string(".") + FILE_SEP;
|
||||
}
|
||||
|
||||
string::size_type pos = 0;
|
||||
|
||||
for (pos = sFullFileNameTmp.length(); pos != 0; --pos)
|
||||
string::size_type found = sFullFileName.find_last_of("/\\");
|
||||
if(found == string::npos)
|
||||
{
|
||||
if (sFullFileNameTmp[pos - 1] == FILE_SEP[0])
|
||||
{
|
||||
return sFullFileNameTmp.substr(0, pos);
|
||||
}
|
||||
return string(".") + FILE_SEP;
|
||||
}
|
||||
|
||||
return string(".") + FILE_SEP;
|
||||
return sFullFileName.substr(0, found+1);
|
||||
|
||||
// string::size_type pos = 0;
|
||||
|
||||
// for (pos = sFullFileNameTmp.length(); pos != 0; --pos)
|
||||
// {
|
||||
// if (sFullFileNameTmp[pos - 1] == FILE_SEP[0])
|
||||
// {
|
||||
// return sFullFileNameTmp.substr(0, pos);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return string(".") + FILE_SEP;
|
||||
}
|
||||
|
||||
string TC_File::extractFileExt(const string &sFullFileName)
|
||||
{
|
||||
string::size_type pos;
|
||||
if ((pos = sFullFileName.rfind('.')) == string::npos)
|
||||
string::size_type found = sFullFileName.find_last_of("/\\");
|
||||
if(found == string::npos)
|
||||
{
|
||||
return string("");
|
||||
}
|
||||
if ((found = sFullFileName.rfind('.')) == string::npos)
|
||||
{
|
||||
return string("");
|
||||
}
|
||||
|
||||
return sFullFileName.substr(pos+1);
|
||||
return sFullFileName.substr(found+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(string::size_type i = sFullFileName.size()-1; i > found; i--)
|
||||
{
|
||||
if(sFullFileName[i] == '.')
|
||||
{
|
||||
return sFullFileName.substr(i+1);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
string TC_File::excludeFileExt(const string &sFullFileName)
|
||||
{
|
||||
string::size_type pos;
|
||||
if ((pos = sFullFileName.rfind('.')) == string::npos)
|
||||
string::size_type found = sFullFileName.find_last_of("./\\");
|
||||
if(found != string::npos)
|
||||
{
|
||||
return sFullFileName;
|
||||
if(sFullFileName[found] == '.')
|
||||
{
|
||||
return sFullFileName.substr(0, found);
|
||||
}
|
||||
}
|
||||
|
||||
return sFullFileName.substr(0, pos);
|
||||
return sFullFileName;
|
||||
|
||||
// string::size_type pos;
|
||||
// if ((pos = sFullFileName.rfind('.')) == string::npos)
|
||||
// {
|
||||
// return sFullFileName;
|
||||
// }
|
||||
|
||||
// return sFullFileName.substr(0, pos);
|
||||
}
|
||||
|
||||
string TC_File::replaceFileExt(const string &sFullFileName, const string &sExt)
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "util/tc_strptime.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace tars
|
||||
{
|
||||
int TC_Port::strcasecmp(const char *s1, const char *s2)
|
||||
@ -171,4 +173,20 @@ int64_t TC_Port::getpid()
|
||||
return pid;
|
||||
}
|
||||
|
||||
string TC_Port::getEnv(const string &name)
|
||||
{
|
||||
char* p = getenv(name.c_str());
|
||||
string str = p ? string(p) : "";
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void TC_Port::setEnv(const string &name, const string &value)
|
||||
{
|
||||
#if TARGET_PLATFORM_WINDOWS
|
||||
SetEnvironmentVariable(name.c_str(), value.c_str());
|
||||
#else
|
||||
setenv(name.c_str(), value.c_str(), true);
|
||||
#endif
|
||||
}
|
||||
}
|
@ -209,7 +209,11 @@ SOCKET_TYPE TC_Socket::accept(TC_Socket &tcSock, struct sockaddr *pstSockAddr, S
|
||||
|
||||
SOCKET_TYPE ifd;
|
||||
|
||||
#if TARGET_PLATFORM_WINDOWS
|
||||
ifd = ::accept(_sock, pstSockAddr, &iSockLen);
|
||||
#else
|
||||
while ((ifd = ::accept(_sock, pstSockAddr, &iSockLen)) < 0 && errno == EINTR);
|
||||
#endif
|
||||
|
||||
tcSock._sock = ifd;
|
||||
tcSock._iDomain = _iDomain;
|
||||
|
Loading…
Reference in New Issue
Block a user