#ifndef INC_SRT_UDT_H
#define INC_SRT_UDT_H
#include "srt.h"
#if defined(SRT_ENABLE_THREADCHECK)
#include <threadcheck.h>
#else
#define THREAD_STATE_INIT(name)
#define THREAD_EXIT()
#define THREAD_PAUSED()
#define THREAD_RESUMED()
#define INCREMENT_THREAD_ITERATIONS()
#endif
#ifndef __MINGW__
#if defined(__MINGW32__) || defined(__MINGW64__)
#define __MINGW__ 1
#endif
#endif
#ifdef __cplusplus
#include <fstream>
#include <set>
#include <string>
#include <vector>
#endif
struct CPerfMon
{
int64_t msTimeStamp; int64_t pktSentTotal; int64_t pktRecvTotal; int pktSndLossTotal; int pktRcvLossTotal; int pktRetransTotal; int pktRcvRetransTotal; int pktSentACKTotal; int pktRecvACKTotal; int pktSentNAKTotal; int pktRecvNAKTotal; int64_t usSndDurationTotal;
int64_t pktSent; int64_t pktRecv; int pktSndLoss; int pktRcvLoss; int pktRetrans; int pktRcvRetrans; int pktSentACK; int pktRecvACK; int pktSentNAK; int pktRecvNAK; double mbpsSendRate; double mbpsRecvRate; int64_t usSndDuration; int pktReorderDistance; double pktRcvAvgBelatedTime; int64_t pktRcvBelated;
double usPktSndPeriod; int pktFlowWindow; int pktCongestionWindow; int pktFlightSize; double msRTT; double mbpsBandwidth; int byteAvailSndBuf; int byteAvailRcvBuf; };
typedef SRTSOCKET UDTSOCKET;
#ifdef __cplusplus
class CUDTException;
namespace UDT
{
typedef CUDTException ERRORINFO;
typedef CPerfMon TRACEINFO;
typedef std::set<SRTSOCKET> UDSET;
#define UD_CLR(u, uset) ((uset)->erase(u))
#define UD_ISSET(u, uset) ((uset)->find(u) != (uset)->end())
#define UD_SET(u, uset) ((uset)->insert(u))
#define UD_ZERO(uset) ((uset)->clear())
SRT_API extern const SRTSOCKET INVALID_SOCK;
#undef ERROR
SRT_API extern const int ERROR;
SRT_API int startup();
SRT_API int cleanup();
SRT_API SRTSOCKET socket();
inline SRTSOCKET socket(int , int , int ) { return socket(); }
SRT_API int bind(SRTSOCKET u, const struct sockaddr* name, int namelen);
SRT_API int bind2(SRTSOCKET u, UDPSOCKET udpsock);
SRT_API int listen(SRTSOCKET u, int backlog);
SRT_API SRTSOCKET accept(SRTSOCKET u, struct sockaddr* addr, int* addrlen);
SRT_API int connect(SRTSOCKET u, const struct sockaddr* name, int namelen);
SRT_API int close(SRTSOCKET u);
SRT_API int getpeername(SRTSOCKET u, struct sockaddr* name, int* namelen);
SRT_API int getsockname(SRTSOCKET u, struct sockaddr* name, int* namelen);
SRT_API int getsockopt(SRTSOCKET u, int level, SRT_SOCKOPT optname, void* optval, int* optlen);
SRT_API int setsockopt(SRTSOCKET u, int level, SRT_SOCKOPT optname, const void* optval, int optlen);
SRT_API int send(SRTSOCKET u, const char* buf, int len, int flags);
SRT_API int recv(SRTSOCKET u, char* buf, int len, int flags);
SRT_API int sendmsg(SRTSOCKET u, const char* buf, int len, int ttl = -1, bool inorder = false, int64_t srctime = 0);
SRT_API int recvmsg(SRTSOCKET u, char* buf, int len, uint64_t& srctime);
SRT_API int recvmsg(SRTSOCKET u, char* buf, int len);
SRT_API int64_t sendfile(SRTSOCKET u, std::fstream& ifs, int64_t& offset, int64_t size, int block = 364000);
SRT_API int64_t recvfile(SRTSOCKET u, std::fstream& ofs, int64_t& offset, int64_t size, int block = 7280000);
SRT_API int64_t sendfile2(SRTSOCKET u, const char* path, int64_t* offset, int64_t size, int block = 364000);
SRT_API int64_t recvfile2(SRTSOCKET u, const char* path, int64_t* offset, int64_t size, int block = 7280000);
SRT_API int select(int nfds, UDSET* readfds, UDSET* writefds, UDSET* exceptfds, const struct timeval* timeout);
SRT_API int selectEx(const std::vector<SRTSOCKET>& fds, std::vector<SRTSOCKET>* readfds,
std::vector<SRTSOCKET>* writefds, std::vector<SRTSOCKET>* exceptfds, int64_t msTimeOut);
SRT_API int epoll_create();
SRT_API int epoll_add_usock(int eid, SRTSOCKET u, const int* events = NULL);
SRT_API int epoll_add_ssock(int eid, SYSSOCKET s, const int* events = NULL);
SRT_API int epoll_remove_usock(int eid, SRTSOCKET u);
SRT_API int epoll_remove_ssock(int eid, SYSSOCKET s);
SRT_API int epoll_update_usock(int eid, SRTSOCKET u, const int* events = NULL);
SRT_API int epoll_update_ssock(int eid, SYSSOCKET s, const int* events = NULL);
SRT_API int epoll_wait(int eid, std::set<SRTSOCKET>* readfds, std::set<SRTSOCKET>* writefds, int64_t msTimeOut,
std::set<SYSSOCKET>* lrfds = NULL, std::set<SYSSOCKET>* wrfds = NULL);
SRT_API int epoll_wait2(int eid, SRTSOCKET* readfds, int* rnum, SRTSOCKET* writefds, int* wnum, int64_t msTimeOut,
SYSSOCKET* lrfds = NULL, int* lrnum = NULL, SYSSOCKET* lwfds = NULL, int* lwnum = NULL);
SRT_API int epoll_uwait(const int eid, SRT_EPOLL_EVENT* fdsSet, int fdsSize, int64_t msTimeOut);
SRT_API int epoll_release(int eid);
SRT_API ERRORINFO& getlasterror();
SRT_API int getlasterror_code();
SRT_API const char* getlasterror_desc();
SRT_API int bstats(SRTSOCKET u, SRT_TRACEBSTATS* perf, bool clear = true);
SRT_API SRT_SOCKSTATUS getsockstate(SRTSOCKET u);
}
namespace srt_logging { struct LogConfig; }
SRT_API extern srt_logging::LogConfig srt_logger_config;
namespace srt
{
SRT_API void setloglevel(srt_logging::LogLevel::type ll);
SRT_API void addlogfa(srt_logging::LogFA fa);
SRT_API void dellogfa(srt_logging::LogFA fa);
SRT_API void resetlogfa(std::set<srt_logging::LogFA> fas);
SRT_API void resetlogfa(const int* fara, size_t fara_size);
SRT_API void setlogstream(std::ostream& stream);
SRT_API void setloghandler(void* opaque, SRT_LOG_HANDLER_FN* handler);
SRT_API void setlogflags(int flags);
SRT_API bool setstreamid(SRTSOCKET u, const std::string& sid);
SRT_API std::string getstreamid(SRTSOCKET u);
namespace logging {
using namespace srt_logging;
}
}
namespace UDT
{
using srt::setloglevel;
using srt::addlogfa;
using srt::dellogfa;
using srt::resetlogfa;
using srt::setlogstream;
using srt::setloghandler;
using srt::setlogflags;
using srt::setstreamid;
using srt::getstreamid;
}
#endif
#endif