TAF->TARS

This commit is contained in:
jarodruan 2020-01-29 21:04:15 +08:00
parent 2401420e78
commit 91f768f512
8 changed files with 51 additions and 51 deletions

View File

@ -72,7 +72,7 @@ void NetworkUtil::closeSocketNoThrow(int fd)
// else if (!TC_Socket::isInProgress()) // else if (!TC_Socket::isInProgress())
// { // {
// closeSocketNoThrow(fd); // closeSocketNoThrow(fd);
// TAF_THROW_EXCEPTION_SYSCODE(TafNetConnectException, "NetworkUtil::doConnect error"); // TARS_THROW_EXCEPTION_SYSCODE(TafNetConnectException, "NetworkUtil::doConnect error");
// } // }
// //
// return bConnected; // return bConnected;
@ -91,7 +91,7 @@ bool NetworkUtil::doConnect(int fd, const struct sockaddr *addr, socklen_t len)
else if (!TC_Socket::isInProgress()) else if (!TC_Socket::isInProgress())
{ {
closeSocketNoThrow(fd); closeSocketNoThrow(fd);
TAF_THROW_EXCEPTION_SYSCODE(TarsNetConnectException, "NetworkUtil::doConnect error"); TARS_THROW_EXCEPTION_SYSCODE(TarsNetConnectException, "NetworkUtil::doConnect error");
} }
return bConnected; return bConnected;

View File

@ -104,8 +104,8 @@ private:
//为了避免windows平台GetLastError()获取不对的问题, 因为抛异常, throw TC_Exception("xxxx", TC_Exception::getSystemCode())时 //为了避免windows平台GetLastError()获取不对的问题, 因为抛异常, throw TC_Exception("xxxx", TC_Exception::getSystemCode())时
//回调用系统函数分配内存, 导致错误码被改写, 因此专门定义宏来抛出异常 //回调用系统函数分配内存, 导致错误码被改写, 因此专门定义宏来抛出异常
//先获取到错误码, 再throw //先获取到错误码, 再throw
#define TAF_THROW_EXCEPTION(EX_CLASS, buffer) throw EX_CLASS(buffer) #define TARS_THROW_EXCEPTION(EX_CLASS, buffer) throw EX_CLASS(buffer)
#define TAF_THROW_EXCEPTION_SYSCODE(EX_CLASS, buffer) \ #define TARS_THROW_EXCEPTION_SYSCODE(EX_CLASS, buffer) \
{ \ { \
int ret = TC_Exception::getSystemCode(); \ int ret = TC_Exception::getSystemCode(); \
throw EX_CLASS(buffer, ret); \ throw EX_CLASS(buffer, ret); \

View File

@ -1231,7 +1231,7 @@ namespace tars
//抛异常前继续进入_t 以便打远程日志 //抛异常前继续进入_t 以便打远程日志
_t(_of, buffer); _t(_of, buffer);
TAF_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName); TARS_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
// throw TC_Logger_Exception("[TC_RollBySize::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode()); // throw TC_Logger_Exception("[TC_RollBySize::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode());
} }
} }
@ -1281,7 +1281,7 @@ namespace tars
_of.open(sLogFileName.c_str(), ios::app); _of.open(sLogFileName.c_str(), ios::app);
if (!_of) if (!_of)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName); TARS_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollBySize::roll]:fopen fail: " + sLogFileName);
// throw TC_Logger_Exception("[TC_RollBySize::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode()); // throw TC_Logger_Exception("[TC_RollBySize::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode());
} }
} }
@ -1692,7 +1692,7 @@ namespace tars
{ {
//抛异常前继续进入_t 以便打远程日志 //抛异常前继续进入_t 以便打远程日志
_t(_of, buffer); _t(_of, buffer);
TAF_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollByTime::roll]:fopen fail: " + sLogFileName); TARS_THROW_EXCEPTION_SYSCODE(TC_Logger_Exception, "[TC_RollByTime::roll]:fopen fail: " + sLogFileName);
// throw TC_Logger_Exception("[TC_RollByTime::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode()); // throw TC_Logger_Exception("[TC_RollByTime::roll]:fopen fail: " + sLogFileName, TC_Exception::getSystemCode());
} }
} }

View File

@ -152,7 +152,7 @@ string TC_Encoder::gbk2utf8(const string &sIn)
cd = iconv_open("UTF-8","GBK"); cd = iconv_open("UTF-8","GBK");
if (cd == (iconv_t)-1) if (cd == (iconv_t)-1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Encoder_Exception, "[TC_Encoder::gbk2utf8] iconv_open error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Encoder_Exception, "[TC_Encoder::gbk2utf8] iconv_open error");
// throw TC_Encoder_Exception("[TC_Encoder::gbk2utf8] iconv_open error", TC_Exception::getSystemCode()); // throw TC_Encoder_Exception("[TC_Encoder::gbk2utf8] iconv_open error", TC_Exception::getSystemCode());
} }
@ -212,7 +212,7 @@ void TC_Encoder::gbk2utf8(const string &sIn, vector<string> &vtStr)
cd = iconv_open("UTF-8","GBK"); cd = iconv_open("UTF-8","GBK");
if (cd == (iconv_t)-1) if (cd == (iconv_t)-1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Encoder_Exception, "[TC_Encoder::gbk2utf8] iconv_open error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Encoder_Exception, "[TC_Encoder::gbk2utf8] iconv_open error");
// throw TC_Encoder_Exception("[TC_Encoder::gbk2utf8] iconv_open error", TC_Exception::getSystemCode()); // throw TC_Encoder_Exception("[TC_Encoder::gbk2utf8] iconv_open error", TC_Exception::getSystemCode());
} }
@ -321,7 +321,7 @@ void TC_Encoder::utf82gbk(char *sOut, int &iMaxOutLen, const char *sIn, int iInL
cd = iconv_open("GBK","UTF-8"); cd = iconv_open("GBK","UTF-8");
if (cd == (iconv_t)-1) if (cd == (iconv_t)-1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Encoder_Exception, "[TC_Encoder::utf82gbk] iconv_open error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Encoder_Exception, "[TC_Encoder::utf82gbk] iconv_open error");
// throw TC_Encoder_Exception("[TC_Encoder::utf82gbk] iconv_open error", TC_Exception::getSystemCode()); // throw TC_Encoder_Exception("[TC_Encoder::utf82gbk] iconv_open error", TC_Exception::getSystemCode());
} }
@ -335,7 +335,7 @@ void TC_Encoder::utf82gbk(char *sOut, int &iMaxOutLen, const char *sIn, int iInL
{ {
iMaxOutLen = 0; iMaxOutLen = 0;
iconv_close(cd); iconv_close(cd);
TAF_THROW_EXCEPTION_SYSCODE(TC_Encoder_Exception, "[TC_Encoder::utf82gbk] iconv error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Encoder_Exception, "[TC_Encoder::utf82gbk] iconv error");
// throw TC_Encoder_Exception("[TC_Encoder::utf82gbk] iconv error", TC_Exception::getSystemCode()); // throw TC_Encoder_Exception("[TC_Encoder::utf82gbk] iconv error", TC_Exception::getSystemCode());
return; return;
} }

View File

@ -183,7 +183,7 @@ string TC_File::getExePath()
if ( count < 0 ) if ( count < 0 )
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_File_Exception, "[TC_File::getExePath] could not get exe path error"); TARS_THROW_EXCEPTION_SYSCODE(TC_File_Exception, "[TC_File::getExePath] could not get exe path error");
// throw TC_File_Exception("[TC_File::getExePath] could not get exe path error", TC_Exception::getSystemCode()); // throw TC_File_Exception("[TC_File::getExePath] could not get exe path error", TC_Exception::getSystemCode());
} }
@ -733,12 +733,12 @@ void TC_File::copyFile(const string &sExistFile, const string &sNewFile,bool bRe
std::ifstream fin(sExistFile.c_str(), ios::binary); std::ifstream fin(sExistFile.c_str(), ios::binary);
if(!fin) if(!fin)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_File_Exception, "[TC_File::copyFile] error: "+sExistFile); TARS_THROW_EXCEPTION_SYSCODE(TC_File_Exception, "[TC_File::copyFile] error: "+sExistFile);
} }
std::ofstream fout(sNewFile.c_str(), ios::binary); std::ofstream fout(sNewFile.c_str(), ios::binary);
if(!fout ) if(!fout )
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_File_Exception, "[TC_File::copyFile] error: "+sNewFile); TARS_THROW_EXCEPTION_SYSCODE(TC_File_Exception, "[TC_File::copyFile] error: "+sNewFile);
} }
fout << fin.rdbuf(); fout << fin.rdbuf();
@ -748,7 +748,7 @@ void TC_File::copyFile(const string &sExistFile, const string &sNewFile,bool bRe
TC_Port::stat_t f_stat; TC_Port::stat_t f_stat;
if (TC_Port::lstat(sExistFile.c_str(), &f_stat) == -1) if (TC_Port::lstat(sExistFile.c_str(), &f_stat) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_File_Exception, "[TC_File::copyFile] error: "+sExistFile); TARS_THROW_EXCEPTION_SYSCODE(TC_File_Exception, "[TC_File::copyFile] error: "+sExistFile);
} }
TC_Port::chmod(sNewFile.c_str(),f_stat.st_mode); TC_Port::chmod(sNewFile.c_str(),f_stat.st_mode);

View File

@ -70,7 +70,7 @@ void TC_Mmap::mmap(const char *file, size_t length)
_hFile = CreateFile(file, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ| FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN|FILE_FLAG_WRITE_THROUGH|FILE_FLAG_NO_BUFFERING, NULL); _hFile = CreateFile(file, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ| FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN|FILE_FLAG_WRITE_THROUGH|FILE_FLAG_NO_BUFFERING, NULL);
if(_hFile == INVALID_HANDLE_VALUE) if(_hFile == INVALID_HANDLE_VALUE)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error");
} }
_hMap = CreateFileMapping(_hFile, NULL, PAGE_READWRITE, 0, length, NULL); _hMap = CreateFileMapping(_hFile, NULL, PAGE_READWRITE, 0, length, NULL);
@ -84,7 +84,7 @@ void TC_Mmap::mmap(const char *file, size_t length)
} }
else else
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error");
} }
_pAddr = (char*)MapViewOfFile(_hMap, FILE_MAP_ALL_ACCESS, 0, 0, length); _pAddr = (char*)MapViewOfFile(_hMap, FILE_MAP_ALL_ACCESS, 0, 0, length);
@ -94,7 +94,7 @@ void TC_Mmap::mmap(const char *file, size_t length)
{ {
CloseHandle(_hFile); CloseHandle(_hFile);
CloseHandle(_hMap); CloseHandle(_hMap);
TAF_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error");
} }
#else #else
//注意_bCreate的赋值位置:保证多线程用一个对象的时候也不会有问题 //注意_bCreate的赋值位置:保证多线程用一个对象的时候也不会有问题
@ -103,14 +103,14 @@ void TC_Mmap::mmap(const char *file, size_t length)
{ {
if(errno != EEXIST) if(errno != EEXIST)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error");
} }
else else
{ {
fd = open(file, O_CREAT|O_RDWR, 0666); fd = open(file, O_CREAT|O_RDWR, 0666);
if(fd == -1) if(fd == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] fopen file '" + string(file) + "' error");
} }
_bCreate = false; _bCreate = false;
} }
@ -132,7 +132,7 @@ void TC_Mmap::mmap(const char *file, size_t length)
{ {
_pAddr = NULL; _pAddr = NULL;
close(fd); close(fd);
TAF_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] mmap file '" + string(file) + "' error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::mmap] mmap file '" + string(file) + "' error");
} }
if(fd != -1) if(fd != -1)
{ {
@ -159,7 +159,7 @@ void TC_Mmap::munmap()
BOOL ret = FlushViewOfFile(_pAddr, 0); BOOL ret = FlushViewOfFile(_pAddr, 0);
if(!ret) if(!ret)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::munmap] munmap error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::munmap] munmap error");
} }
UnmapViewOfFile(_pAddr); UnmapViewOfFile(_pAddr);
@ -172,7 +172,7 @@ void TC_Mmap::munmap()
int ret = ::munmap(_pAddr, _iLength); int ret = ::munmap(_pAddr, _iLength);
if(ret == -1) if(ret == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::munmap] munmap error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::munmap] munmap error");
} }
#endif #endif
_pAddr = NULL; _pAddr = NULL;
@ -197,7 +197,7 @@ void TC_Mmap::msync(bool bSync)
#endif #endif
if(ret != 0) if(ret != 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::msync] msync error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Mmap_Exception, "[TC_Mmap::msync] msync error");
} }
} }

View File

@ -66,7 +66,7 @@ void TC_Shm::init(size_t iShmSize, key_t iKey, bool bOwner)
//有可能是已经存在同样的key_shm,则试图连接 //有可能是已经存在同样的key_shm,则试图连接
if ((_shemID = shmget(iKey, iShmSize, 0666)) < 0) if ((_shemID = shmget(iKey, iShmSize, 0666)) < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Shm_Exception, "[TC_Shm::init()] shmget error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Shm_Exception, "[TC_Shm::init()] shmget error");
// throw TC_Shm_Exception("[TC_Shm::init()] shmget error", TC_Exception::getSystemCode()); // throw TC_Shm_Exception("[TC_Shm::init()] shmget error", TC_Exception::getSystemCode());
} }
} }
@ -78,7 +78,7 @@ void TC_Shm::init(size_t iShmSize, key_t iKey, bool bOwner)
//try to access shm //try to access shm
if ((_pshm = shmat(_shemID, NULL, 0)) == (char *) - 1) if ((_pshm = shmat(_shemID, NULL, 0)) == (char *) - 1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Shm_Exception, "[TC_Shm::init()] shmat error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Shm_Exception, "[TC_Shm::init()] shmat error");
// throw TC_Shm_Exception("[TC_Shm::init()] shmat error", TC_Exception::getSystemCode()); // throw TC_Shm_Exception("[TC_Shm::init()] shmat error", TC_Exception::getSystemCode());
} }

View File

@ -80,7 +80,7 @@ void TC_Socket::createSocket(int iSocketType, int iDomain)
if(_sock < 0) if(_sock < 0)
{ {
_sock = INVALID_SOCKET; _sock = INVALID_SOCKET;
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::createSocket] create socket error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::createSocket] create socket error");
// throw TC_Socket_Exception("[TC_Socket::createSocket] create socket error! :" + string(strerror(errno))); // throw TC_Socket_Exception("[TC_Socket::createSocket] create socket error! :" + string(strerror(errno)));
} }
else else
@ -152,7 +152,7 @@ void TC_Socket::connect(const char *sPathName)
int ret = connectNoThrow(sPathName); int ret = connectNoThrow(sPathName);
if(ret < 0) if(ret < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_SocketConnect_Exception, "[TC_Socket::connect] connect error"); TARS_THROW_EXCEPTION_SYSCODE(TC_SocketConnect_Exception, "[TC_Socket::connect] connect error");
} }
} }
@ -174,7 +174,7 @@ void TC_Socket::getPeerName(struct sockaddr *pstPeerAddr, socklen_t &iPeerLen) c
{ {
if(getpeername(_sock, pstPeerAddr, &iPeerLen) < 0) if(getpeername(_sock, pstPeerAddr, &iPeerLen) < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::getPeerName] getpeername error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::getPeerName] getpeername error");
} }
} }
@ -199,7 +199,7 @@ void TC_Socket::getSockName(struct sockaddr *pstSockAddr, socklen_t &iSockLen) c
{ {
if(getsockname(_sock, pstSockAddr, &iSockLen) < 0) if(getsockname(_sock, pstSockAddr, &iSockLen) < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::getSockName] getsockname error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::getSockName] getsockname error");
} }
} }
@ -222,7 +222,7 @@ void TC_Socket::parseAddr(const string &sAddr, struct in_addr &stSinAddr)
int iRet = inet_pton(AF_INET, sAddr.c_str(), &stSinAddr); int iRet = inet_pton(AF_INET, sAddr.c_str(), &stSinAddr);
if(iRet < 0) if(iRet < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::parseAddr] inet_pton(" + sAddr + ") error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::parseAddr] inet_pton(" + sAddr + ") error");
} }
#if TARGET_PLATFORM_LINUX #if TARGET_PLATFORM_LINUX
else if (iRet == 0) else if (iRet == 0)
@ -236,7 +236,7 @@ void TC_Socket::parseAddr(const string &sAddr, struct in_addr &stSinAddr)
if (pstHostent == NULL) if (pstHostent == NULL)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::parseAddr] gethostbyname_r(" + sAddr + ") error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::parseAddr] gethostbyname_r(" + sAddr + ") error");
// throw TC_Socket_Exception("[TC_Socket::parseAddr] gethostbyname_r(" + sAddr + ") error", TC_Exception::getSystemCode()); // throw TC_Socket_Exception("[TC_Socket::parseAddr] gethostbyname_r(" + sAddr + ") error", TC_Exception::getSystemCode());
} }
@ -256,7 +256,7 @@ void TC_Socket::parseAddr(const string &sAddr, struct in_addr &stSinAddr)
int err = getaddrinfo(sAddr.c_str(), NULL, &hints, &ailist); int err = getaddrinfo(sAddr.c_str(), NULL, &hints, &ailist);
if (err != 0) if (err != 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::parseAddr] getaddrinfo(" + sAddr + ") error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::parseAddr] getaddrinfo(" + sAddr + ") error");
} }
else else
{ {
@ -278,7 +278,7 @@ void TC_Socket::parseAddr(const string &host, struct in6_addr &stSinAddr)
int iRet = inet_pton(AF_INET6, host.c_str(), &stSinAddr); int iRet = inet_pton(AF_INET6, host.c_str(), &stSinAddr);
if(iRet < 0) if(iRet < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::parseAddr] inet_pton(" + host + ") error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::parseAddr] inet_pton(" + host + ") error");
} }
else if(iRet == 0) else if(iRet == 0)
{ {
@ -381,7 +381,7 @@ void TC_Socket::bind(struct sockaddr *pstBindAddr, socklen_t iAddrLen)
if(::bind(_sock, pstBindAddr, iAddrLen) < 0) if(::bind(_sock, pstBindAddr, iAddrLen) < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::bind] bind error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::bind] bind error");
} }
} }
@ -440,7 +440,7 @@ void TC_Socket::connect(const string &sServerAddr, uint16_t port)
if(ret < 0) if(ret < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_SocketConnect_Exception, "[TC_Socket::connect] connect error"); TARS_THROW_EXCEPTION_SYSCODE(TC_SocketConnect_Exception, "[TC_Socket::connect] connect error");
} }
} }
@ -455,7 +455,7 @@ void TC_Socket::listen(int iConnBackLog)
{ {
if (::listen(_sock, iConnBackLog) < 0) if (::listen(_sock, iConnBackLog) < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::listen] listen error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::listen] listen error");
} }
} }
@ -544,7 +544,7 @@ void TC_Socket::shutdown(int iHow)
{ {
if (::shutdown(_sock, iHow) < 0) if (::shutdown(_sock, iHow) < 0)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::shutdown] shutdown error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::shutdown] shutdown error");
} }
} }
@ -573,7 +573,7 @@ void TC_Socket::setNoCloseWait()
if(setSockOpt(SO_LINGER, (const void *)&stLinger, sizeof(linger), SOL_SOCKET) == -1) if(setSockOpt(SO_LINGER, (const void *)&stLinger, sizeof(linger), SOL_SOCKET) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setNoCloseWait] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setNoCloseWait] error");
} }
} }
@ -597,7 +597,7 @@ void TC_Socket::setCloseWaitDefault()
if(setSockOpt(SO_LINGER, (const void *)&stLinger, sizeof(linger), SOL_SOCKET) == -1) if(setSockOpt(SO_LINGER, (const void *)&stLinger, sizeof(linger), SOL_SOCKET) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setCloseWait] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setCloseWait] error");
} }
} }
@ -607,7 +607,7 @@ void TC_Socket::setTcpNoDelay()
if(setSockOpt(TCP_NODELAY, (char*)&flag, int(sizeof(int)), IPPROTO_TCP) == -1) if(setSockOpt(TCP_NODELAY, (char*)&flag, int(sizeof(int)), IPPROTO_TCP) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setTcpNoDelay] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setTcpNoDelay] error");
} }
} }
@ -616,7 +616,7 @@ void TC_Socket::setKeepAlive()
int flag = 1; int flag = 1;
if(setSockOpt(SO_KEEPALIVE, (char*)&flag, int(sizeof(int)), SOL_SOCKET) == -1) if(setSockOpt(SO_KEEPALIVE, (char*)&flag, int(sizeof(int)), SOL_SOCKET) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setKeepAlive] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setKeepAlive] error");
} }
} }
@ -624,7 +624,7 @@ void TC_Socket::setSendBufferSize(int sz)
{ {
if(setSockOpt(SO_SNDBUF, (char*)&sz, int(sizeof(int)), SOL_SOCKET) == -1) if(setSockOpt(SO_SNDBUF, (char*)&sz, int(sizeof(int)), SOL_SOCKET) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setKeepsetSendBufferSizeAlive] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setKeepsetSendBufferSizeAlive] error");
} }
} }
@ -634,7 +634,7 @@ int TC_Socket::getSendBufferSize()
socklen_t len = sizeof(sz); socklen_t len = sizeof(sz);
if(getSockOpt(SO_SNDBUF, (void*)&sz, len, SOL_SOCKET) == -1 || len != sizeof(sz)) if(getSockOpt(SO_SNDBUF, (void*)&sz, len, SOL_SOCKET) == -1 || len != sizeof(sz))
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::getSendBufferSize] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::getSendBufferSize] error");
} }
return sz; return sz;
@ -644,7 +644,7 @@ void TC_Socket::setRecvBufferSize(int sz)
{ {
if(setSockOpt(SO_RCVBUF, (char*)&sz, int(sizeof(int)), SOL_SOCKET) == -1) if(setSockOpt(SO_RCVBUF, (char*)&sz, int(sizeof(int)), SOL_SOCKET) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setRecvBufferSize] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setRecvBufferSize] error");
} }
} }
@ -654,7 +654,7 @@ int TC_Socket::getRecvBufferSize()
socklen_t len = sizeof(sz); socklen_t len = sizeof(sz);
if(getSockOpt(SO_RCVBUF, (void*)&sz, len, SOL_SOCKET) == -1 || len != sizeof(sz)) if(getSockOpt(SO_RCVBUF, (void*)&sz, len, SOL_SOCKET) == -1 || len != sizeof(sz))
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::getRecvBufferSize] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::getRecvBufferSize] error");
} }
return sz; return sz;
@ -667,7 +667,7 @@ void TC_Socket::ignoreSigPipe() {
if (setSockOpt(SO_NOSIGPIPE, (char*)&set, int(sizeof(int)), SOL_SOCKET) == -1) if (setSockOpt(SO_NOSIGPIPE, (char*)&set, int(sizeof(int)), SOL_SOCKET) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::ignoreSigPipe] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::ignoreSigPipe] error");
} }
#endif #endif
} }
@ -680,7 +680,7 @@ void TC_Socket::setblock(int fd, bool bBlock)
if ((val = fcntl(fd, F_GETFL, 0)) == -1) if ((val = fcntl(fd, F_GETFL, 0)) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setblock] fcntl [F_GETFL] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setblock] fcntl [F_GETFL] error");
// throw TC_Socket_Exception("[TC_Socket::setblock] fcntl [F_GETFL] error", TC_Exception::getSystemCode()); // throw TC_Socket_Exception("[TC_Socket::setblock] fcntl [F_GETFL] error", TC_Exception::getSystemCode());
} }
@ -695,7 +695,7 @@ void TC_Socket::setblock(int fd, bool bBlock)
if (fcntl(fd, F_SETFL, val) == -1) if (fcntl(fd, F_SETFL, val) == -1)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setblock] fcntl [F_SETFL] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setblock] fcntl [F_SETFL] error");
} }
#else #else
unsigned long ul = 1; unsigned long ul = 1;
@ -704,7 +704,7 @@ void TC_Socket::setblock(int fd, bool bBlock)
ret = ioctlsocket(fd, FIONBIO, (unsigned long *)&ul); ret = ioctlsocket(fd, FIONBIO, (unsigned long *)&ul);
if (ret == SOCKET_ERROR) if (ret == SOCKET_ERROR)
{ {
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setblock] ioctlsocket [FIONBIO] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::setblock] ioctlsocket [FIONBIO] error");
} }
#endif #endif
@ -785,7 +785,7 @@ clean:
// #if TARGET_PLATFORM_LINUX||TARGET_PLATFORM_IOS // #if TARGET_PLATFORM_LINUX||TARGET_PLATFORM_IOS
// #undef closesocket // #undef closesocket
// #endif // #endif
TAF_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::createPipe] error"); TARS_THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::createPipe] error");
} }
#if TARGET_PLATFORM_LINUX #if TARGET_PLATFORM_LINUX