📄 common.cpp
字号:
//CUDTException::CUDTException(int major, int minor, int err):m_iMajor(major),m_iMinor(minor){ if (-1 == err) #ifndef WIN32 m_iErrno = errno; #else m_iErrno = GetLastError(); #endif else m_iErrno = err;}CUDTException::CUDTException(const CUDTException& e):m_iMajor(e.m_iMajor),m_iMinor(e.m_iMinor),m_iErrno(e.m_iErrno){}CUDTException::~CUDTException(){}const char* CUDTException::getErrorMessage(){ // translate "Major:Minor" code into text message. switch (m_iMajor) { case 0: m_strMsg = "Success"; break; case 1: m_strMsg = "Connection setup failure"; switch (m_iMinor) { case 1: m_strMsg += ": connection time out"; break; case 2: m_strMsg += ": connection rejected"; break; case 3: m_strMsg += ": unable to create/configure UDP socket"; break; case 4: m_strMsg += ": abort for security reasons"; break; default: break; } break; case 2: switch (m_iMinor) { case 1: m_strMsg = "Connection was broken"; break; case 2: m_strMsg = "Connection does not exist"; break; default: break; } break; case 3: m_strMsg = "System resource failure"; switch (m_iMinor) { case 1: m_strMsg += ": unable to create new threads"; break; case 2: m_strMsg += ": unable to allocate buffers"; break; default: break; } break; case 4: m_strMsg = "File system failure"; switch (m_iMinor) { case 1: m_strMsg += ": cannot seek read position"; break; case 2: m_strMsg += ": failure in read"; break; case 3: m_strMsg += ": cannot seek write position"; break; case 4: m_strMsg += ": failure in write"; break; default: break; } break; case 5: m_strMsg = "Operation not supported"; switch (m_iMinor) { case 1: m_strMsg += ": Cannot do this operation on a BOUND socket"; break; case 2: m_strMsg += ": Cannot do this operation on a CONNECTED socket"; break; case 3: m_strMsg += ": Bad parameters"; break; case 4: m_strMsg += ": Invalid socket ID"; break; case 5: m_strMsg += ": Cannot do this operation on an UNBOUND socket"; break; case 6: m_strMsg += ": Socket is not in listening state"; break; case 7: m_strMsg += ": Listen/accept is not supported in rendezous connection setup"; break; case 8: m_strMsg += ": Cannot call connect on UNBOUND socket in rendezvous connection setup"; break; case 9: m_strMsg += ": This operation is not supported in SOCK_STREAM mode"; break; case 10: m_strMsg += ": This operation is not supported in SOCK_DGRAM mode"; break; case 11: m_strMsg += ": Another socket is already listening on the same port"; break; case 12: m_strMsg += ": Message is too large to send (it must be less than the UDT send buffer size)"; break; default: break; } break; case 6: m_strMsg = "Non-blocking call failure"; switch (m_iMinor) { case 1: m_strMsg += ": no buffer available for sending"; break; case 2: m_strMsg += ": no data available for reading"; break; default: break; } break; default: m_strMsg = "Unknown error"; } // Adding "errno" information if (0 < m_iErrno) { m_strMsg += ": "; #ifndef WIN32 m_strMsg += strerror(m_iErrno); #else LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, m_iErrno, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL); m_strMsg += (char*)lpMsgBuf; LocalFree(lpMsgBuf); #endif } // period #ifndef WIN32 m_strMsg += "."; #endif return m_strMsg.c_str();}const int CUDTException::getErrorCode() const{ return m_iMajor * 1000 + m_iMinor;}void CUDTException::clear(){ m_iMajor = 0; m_iMinor = 0; m_iErrno = 0;}const int CUDTException::SUCCESS = 0;const int CUDTException::ECONNSETUP = 1000;const int CUDTException::ENOSERVER = 1001;const int CUDTException::ECONNREJ = 1002;const int CUDTException::ESOCKFAIL = 1003;const int CUDTException::ESECFAIL = 1004;const int CUDTException::ECONNFAIL = 2000;const int CUDTException::ECONNLOST = 2001;const int CUDTException::ENOCONN = 2002;const int CUDTException::ERESOURCE = 3000;const int CUDTException::ETHREAD = 3001;const int CUDTException::ENOBUF = 3002;const int CUDTException::EFILE = 4000;const int CUDTException::EINVRDOFF = 4001;const int CUDTException::ERDPERM = 4002;const int CUDTException::EINVWROFF = 4003;const int CUDTException::EWRPERM = 4004;const int CUDTException::EINVOP = 5000;const int CUDTException::EBOUNDSOCK = 5001;const int CUDTException::ECONNSOCK = 5002;const int CUDTException::EINVPARAM = 5003;const int CUDTException::EINVSOCK = 5004;const int CUDTException::EUNBOUNDSOCK = 5005;const int CUDTException::ENOLISTEN = 5006;const int CUDTException::ERDVNOSERV = 5007;const int CUDTException::ERDVUNBOUND = 5008;const int CUDTException::ESTREAMILL = 5009;const int CUDTException::EDGRAMILL = 5010;const int CUDTException::EDUPLISTEN = 5011;const int CUDTException::ELARGEMSG = 5012;const int CUDTException::EASYNCFAIL = 6000;const int CUDTException::EASYNCSND = 6001;const int CUDTException::EASYNCRCV = 6002;const int CUDTException::EUNKNOWN = -1;//bool CIPAddress::ipcmp(const sockaddr* addr1, const sockaddr* addr2, const int& ver){ if (AF_INET == ver) { sockaddr_in* a1 = (sockaddr_in*)addr1; sockaddr_in* a2 = (sockaddr_in*)addr2; if ((a1->sin_port == a2->sin_port) && (a1->sin_addr.s_addr == a2->sin_addr.s_addr)) return true; } else { sockaddr_in6* a1 = (sockaddr_in6*)addr1; sockaddr_in6* a2 = (sockaddr_in6*)addr2; if (a1->sin6_port == a2->sin6_port) { for (int i = 0; i < 16; ++ i) if (*((char*)&(a1->sin6_addr) + i) != *((char*)&(a2->sin6_addr) + i)) return false; return true; } } return false;}//void CMD5::compute(const char* input, unsigned char result[16]){ md5_state_t state; md5_init(&state); md5_append(&state, (const md5_byte_t *)input, strlen(input)); md5_finish(&state, result);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -