⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 api.cpp

📁 udt.sdk.4.1.tar.gz更新包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
         u->m_pSndQueue = i->m_pSndQueue;         u->m_pRcvQueue = i->m_pRcvQueue;         return;      }   }}#ifndef WIN32   void* CUDTUnited::garbageCollect(void* p)#else   DWORD WINAPI CUDTUnited::garbageCollect(LPVOID p)#endif{   CUDTUnited* self = (CUDTUnited*)p;   while (!self->m_bClosing)   {      self->checkBrokenSockets();      #ifndef WIN32         sleep(1);      #else         Sleep(1);      #endif   }   #ifndef WIN32      return NULL;   #else      return 0;   #endif   }////////////////////////////////////////////////////////////////////////////////UDTSOCKET CUDT::socket(int af, int type, int){   try   {      return s_UDTUnited.newSocket(af, type);   }   catch (CUDTException& e)   {      s_UDTUnited.setError(new CUDTException(e));      return INVALID_SOCK;   }   catch (bad_alloc&)   {      s_UDTUnited.setError(new CUDTException(3, 2, 0));      return INVALID_SOCK;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return INVALID_SOCK;   }}int CUDT::bind(UDTSOCKET u, const sockaddr* name, int namelen){   try   {      return s_UDTUnited.bind(u, name, namelen);   }   catch (CUDTException& e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (bad_alloc&)   {      s_UDTUnited.setError(new CUDTException(3, 2, 0));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::listen(UDTSOCKET u, int backlog){   try   {      return s_UDTUnited.listen(u, backlog);   }   catch (CUDTException& e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (bad_alloc&)   {      s_UDTUnited.setError(new CUDTException(3, 2, 0));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}UDTSOCKET CUDT::accept(UDTSOCKET u, sockaddr* addr, int* addrlen){   try   {      return s_UDTUnited.accept(u, addr, addrlen);   }   catch (CUDTException& e)   {      s_UDTUnited.setError(new CUDTException(e));      return INVALID_SOCK;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return INVALID_SOCK;   }}int CUDT::connect(UDTSOCKET u, const sockaddr* name, int namelen){   try   {      return s_UDTUnited.connect(u, name, namelen);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (bad_alloc&)   {      s_UDTUnited.setError(new CUDTException(3, 2, 0));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::close(UDTSOCKET u){   try   {      return s_UDTUnited.close(u);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::getpeername(UDTSOCKET u, sockaddr* name, int* namelen){   try   {      return s_UDTUnited.getpeername(u, name, namelen);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::getsockname(UDTSOCKET u, sockaddr* name, int* namelen){   try   {      return s_UDTUnited.getsockname(u, name, namelen);;   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::getsockopt(UDTSOCKET u, int, UDTOpt optname, void* optval, int* optlen){   try   {      CUDT* udt = s_UDTUnited.lookup(u);      udt->getOpt(optname, optval, *optlen);      return 0;   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::setsockopt(UDTSOCKET u, int, UDTOpt optname, const void* optval, int optlen){   try   {      CUDT* udt = s_UDTUnited.lookup(u);      udt->setOpt(optname, optval, optlen);      return 0;   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::send(UDTSOCKET u, const char* buf, int len, int){   if (CUDTSocket::BROKEN == s_UDTUnited.getStatus(u))   {      s_UDTUnited.setError(new CUDTException(2, 1, 0));      return ERROR;   }   try   {      CUDT* udt = s_UDTUnited.lookup(u);      return udt->send((char*)buf, len);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (bad_alloc&)   {      s_UDTUnited.setError(new CUDTException(3, 2, 0));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::recv(UDTSOCKET u, char* buf, int len, int){   if (CUDTSocket::BROKEN == s_UDTUnited.getStatus(u))   {      s_UDTUnited.setError(new CUDTException(2, 1, 0));      return ERROR;   }   try   {      CUDT* udt = s_UDTUnited.lookup(u);      return udt->recv(buf, len);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::sendmsg(UDTSOCKET u, const char* buf, int len, int ttl, bool inorder){   if (CUDTSocket::BROKEN == s_UDTUnited.getStatus(u))   {      s_UDTUnited.setError(new CUDTException(2, 1, 0));      return ERROR;   }   try   {      CUDT* udt = s_UDTUnited.lookup(u);      return udt->sendmsg((char*)buf, len, ttl, inorder);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (bad_alloc&)   {      s_UDTUnited.setError(new CUDTException(3, 2, 0));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::recvmsg(UDTSOCKET u, char* buf, int len){   if (CUDTSocket::BROKEN == s_UDTUnited.getStatus(u))   {      s_UDTUnited.setError(new CUDTException(2, 1, 0));      return ERROR;   }   try   {      CUDT* udt = s_UDTUnited.lookup(u);      return udt->recvmsg(buf, len);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int64_t CUDT::sendfile(UDTSOCKET u, ifstream& ifs, const int64_t& offset, const int64_t& size, const int& block){   if (CUDTSocket::BROKEN == s_UDTUnited.getStatus(u))   {      s_UDTUnited.setError(new CUDTException(2, 1, 0));      return ERROR;   }   try   {      CUDT* udt = s_UDTUnited.lookup(u);      return udt->sendfile(ifs, offset, size, block);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (bad_alloc&)   {      s_UDTUnited.setError(new CUDTException(3, 2, 0));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int64_t CUDT::recvfile(UDTSOCKET u, ofstream& ofs, const int64_t& offset, const int64_t& size, const int& block){   if (CUDTSocket::BROKEN == s_UDTUnited.getStatus(u))   {      s_UDTUnited.setError(new CUDTException(2, 1, 0));      return ERROR;   }   try   {      CUDT* udt = s_UDTUnited.lookup(u);      return udt->recvfile(ofs, offset, size, block);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}int CUDT::select(int, ud_set* readfds, ud_set* writefds, ud_set* exceptfds, const timeval* timeout){   if ((NULL == readfds) && (NULL == writefds) && (NULL == exceptfds))   {      s_UDTUnited.setError(new CUDTException(5, 3, 0));      return ERROR;   }   try   {      return s_UDTUnited.select(readfds, writefds, exceptfds, timeout);   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (bad_alloc&)   {      s_UDTUnited.setError(new CUDTException(3, 2, 0));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}CUDTException& CUDT::getlasterror(){   return *s_UDTUnited.getError();}int CUDT::perfmon(UDTSOCKET u, CPerfMon* perf, bool clear){   if (CUDTSocket::BROKEN == s_UDTUnited.getStatus(u))   {      s_UDTUnited.setError(new CUDTException(2, 1, 0));      return ERROR;   }   try   {      CUDT* udt = s_UDTUnited.lookup(u);      udt->sample(perf, clear);      return 0;   }   catch (CUDTException e)   {      s_UDTUnited.setError(new CUDTException(e));      return ERROR;   }   catch (...)   {      s_UDTUnited.setError(new CUDTException(-1, 0, 0));      return ERROR;   }}CUDT* CUDT::getUDTHandle(UDTSOCKET u){   return s_UDTUnited.lookup(u);}////////////////////////////////////////////////////////////////////////////////namespace UDT{UDTSOCKET socket(int af, int type, int protocol){   return CUDT::socket(af, type, protocol);}int bind(UDTSOCKET u, const struct sockaddr* name, int namelen){   return CUDT::bind(u, name, namelen);}int listen(UDTSOCKET u, int backlog){   return CUDT::listen(u, backlog);}UDTSOCKET accept(UDTSOCKET u, struct sockaddr* addr, int* addrlen){   return CUDT::accept(u, addr, addrlen);}int connect(UDTSOCKET u, const struct sockaddr* name, int namelen){   return CUDT::connect(u, name, namelen);}int close(UDTSOCKET u){   return CUDT::close(u);}int getpeername(UDTSOCKET u, struct sockaddr* name, int* namelen){   return CUDT::getpeername(u, name, namelen);}int getsockname(UDTSOCKET u, struct sockaddr* name, int* namelen){   return CUDT::getsockname(u, name, namelen);}int getsockopt(UDTSOCKET u, int level, SOCKOPT optname, void* optval, int* optlen){   return CUDT::getsockopt(u, level, optname, optval, optlen);}int setsockopt(UDTSOCKET u, int level, SOCKOPT optname, const void* optval, int optlen){   return CUDT::setsockopt(u, level, optname, optval, optlen);}int send(UDTSOCKET u, const char* buf, int len, int flags){   return CUDT::send(u, buf, len, flags);}int recv(UDTSOCKET u, char* buf, int len, int flags){   return CUDT::recv(u, buf, len, flags);}int sendmsg(UDTSOCKET u, const char* buf, int len, int ttl, bool inorder){   return CUDT::sendmsg(u, buf, len, ttl, inorder);}int recvmsg(UDTSOCKET u, char* buf, int len){   return CUDT::recvmsg(u, buf, len);}int64_t sendfile(UDTSOCKET u, ifstream& ifs, int64_t offset, int64_t size, int block){   return CUDT::sendfile(u, ifs, offset, size, block);}int64_t recvfile(UDTSOCKET u, ofstream& ofs, int64_t offset, int64_t size, int block){   return CUDT::recvfile(u, ofs, offset, size, block);}int select(int nfds, UDSET* readfds, UDSET* writefds, UDSET* exceptfds, const struct timeval* timeout){   return CUDT::select(nfds, readfds, writefds, exceptfds, timeout);}ERRORINFO& getlasterror(){   return CUDT::getlasterror();}int perfmon(UDTSOCKET u, TRACEINFO* perf, bool clear){   return CUDT::perfmon(u, perf, clear);}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -