📄 core.h
字号:
/*****************************************************************************Copyright (c) 2001 - 2007, The Board of Trustees of the University of Illinois.All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet:* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.* Neither the name of the University of Illinois nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "ASIS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER ORCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDINGNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*****************************************************************************//*****************************************************************************written by Yunhong Gu, last updated 11/30/2007*****************************************************************************/#ifndef __UDT_CORE_H__#define __UDT_CORE_H__#include "udt.h"#include "common.h"#include "list.h"#include "buffer.h"#include "window.h"#include "packet.h"#include "channel.h"#include "api.h"#include "ccc.h"#include "control.h"#include "queue.h"enum UDTSockType {UDT_STREAM = 1, UDT_DGRAM};class CUDT{friend struct CUDTSocket;friend class CUDTUnited;friend class CCC;friend struct CUDTComp;friend class CControl;friend class CSndQueue;friend class CRcvQueue;friend class CSndUList;friend class CRcvUList;private: // constructor and desctructor CUDT(); CUDT(const CUDT& ancestor); const CUDT& operator=(const CUDT&) {return *this;} ~CUDT();public: //API static UDTSOCKET socket(int af, int type = SOCK_STREAM, int protocol = 0); static int bind(UDTSOCKET u, const sockaddr* name, int namelen); static int listen(UDTSOCKET u, int backlog); static UDTSOCKET accept(UDTSOCKET u, sockaddr* addr, int* addrlen); static int connect(UDTSOCKET u, const sockaddr* name, int namelen); static int close(UDTSOCKET u); static int getpeername(UDTSOCKET u, sockaddr* name, int* namelen); static int getsockname(UDTSOCKET u, sockaddr* name, int* namelen); static int getsockopt(UDTSOCKET u, int level, UDTOpt optname, void* optval, int* optlen); static int setsockopt(UDTSOCKET u, int level, UDTOpt optname, const void* optval, int optlen); static int send(UDTSOCKET u, const char* buf, int len, int flags); static int recv(UDTSOCKET u, char* buf, int len, int flags); static int sendmsg(UDTSOCKET u, const char* buf, int len, int ttl = -1, bool inorder = false); static int recvmsg(UDTSOCKET u, char* buf, int len); static int64_t sendfile(UDTSOCKET u, std::ifstream& ifs, const int64_t& offset, const int64_t& size, const int& block = 364000); static int64_t recvfile(UDTSOCKET u, std::ofstream& ofs, const int64_t& offset, const int64_t& size, const int& block = 7280000); static int select(int nfds, ud_set* readfds, ud_set* writefds, ud_set* exceptfds, const timeval* timeout); static CUDTException& getlasterror(); static int perfmon(UDTSOCKET u, CPerfMon* perf, bool clear = true);public: // internal API static CUDT* getUDTHandle(UDTSOCKET u);private: // Functionality: // initialize a UDT entity and bind to a local address. // Parameters: // None. // Returned value: // None. void open(); // Functionality: // Start listening to any connection request. // Parameters: // None. // Returned value: // None. void listen(); // Functionality: // Connect to a UDT entity listening at address "peer". // Parameters: // 0) [in] peer: The address of the listening UDT entity. // Returned value: // None. void connect(const sockaddr* peer); // Functionality: // Connect to a UDT entity listening at address "peer", which has sent "hs" request. // Parameters: // 0) [in] peer: The address of the listening UDT entity. // 1) [in/out] hs: The handshake information sent by the peer side (in), negotiated value (out). // Returned value: // None. void connect(const sockaddr* peer, CHandShake* hs); // Functionality: // Close the opened UDT entity. // Parameters: // None. // Returned value: // None. void close(); // Functionality: // Request UDT to send out a data block "data" with size of "len". // Parameters: // 0) [in] data: The address of the application data to be sent. // 1) [in] len: The size of the data block. // Returned value: // Actual size of data sent. int send(const char* data, const int& len); // Functionality: // Request UDT to receive data to a memory block "data" with size of "len". // Parameters: // 0) [out] data: data received. // 1) [in] len: The desired size of data to be received. // Returned value: // Actual size of data received. int recv(char* data, const int& len); // Functionality: // send a message of a memory block "data" with size of "len". // Parameters: // 0) [out] data: data received. // 1) [in] len: The desired size of data to be received. // 2) [in] ttl: the time-to-live of the message. // 3) [in] inorder: if the message should be delivered in order. // Returned value: // Actual size of data sent. int sendmsg(const char* data, const int& len, const int& ttl, const bool& inorder); // Functionality: // Receive a message to buffer "data". // Parameters: // 0) [out] data: data received. // 1) [in] len: size of the buffer. // Returned value: // Actual size of data received. int recvmsg(char* data, const int& len); // Functionality: // Request UDT to send out a file described as "fd", starting from "offset", with size of "size". // Parameters: // 0) [in] ifs: The input file stream. // 1) [in] offset: From where to read and send data; // 2) [in] size: How many data to be sent. // 3) [in] block: size of block per read from disk // Returned value: // Actual size of data sent. int64_t sendfile(std::ifstream& ifs, const int64_t& offset, const int64_t& size, const int& block = 366000); // Functionality: // Request UDT to receive data into a file described as "fd", starting from "offset", with expected size of "size". // Parameters: // 0) [out] ofs: The output file stream. // 1) [in] offset: From where to write data; // 2) [in] size: How many data to be received.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -