?? udt.pas
字號:
{*****************************************************************************
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 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 12/02/2007
translated by
Zhengcheng Zhang, last updated 10/10/2008
*****************************************************************************}
Unit udt;
Interface
{$INCLUDE mcompile.inc}
Uses
SysUtils, Classes,
{$IFDEF DELPHI}
Windows, Winsock, JwaWinsock2, JwaWS2tcpip,
{$ENDIF}
{$IFDEF KYLIX}
Libc,
{$ENDIF}
StrUtils
;
Const
ERROR = -1;
INVALID_SOCK = -1;
{$IFDEF DELPHI}
UDTLIB = 'udt.dll';
{$ENDIF}
{$IFDEF KYLIX}
UDTLIB = 'libudt.so';
{$ENDIF}
Type
{$IFDEF KYLIX}
pAddrInfo = pAddressInfo;
{$ENDIF}
UDTSOCKET = Integer;
pInteger = ^Integer;
pUDTSOCKET = ^UDTSOCKET;
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
);
CPerfMon = Record
// global measurements
msTimeStamp: Int64; // time since the UDT entity is started, in milliseconds
pktSentTotal: Int64; // total number of sent data packets, including retransmissions
pktRecvTotal: Int64; // total number of received packets
pktSndLossTotal: Integer; // total number of lost packets (sender side)
pktRcvLossTotal: Integer; // total number of lost packets (receiver side)
pktRetransTotal: Integer; // total number of retransmitted packets
pktSentACKTotal: Integer; // total number of sent ACK packets
pktRecvACKTotal: Integer; // total number of received ACK packets
pktSentNAKTotal: Integer; // total number of sent NAK packets
pktRecvNAKTotal: Integer; // total number of received NAK packets
// local measurements
pktSent: Int64; // number of sent data packets, including retransmissions
pktRecv: Int64; // number of received packets
pktSndLoss: Integer; // number of lost packets (sender side)
pktRcvLoss: Integer; // number of lost packets (receiverer side)
pktRetrans: Integer; // number of retransmitted packets
pktSentACK: Integer; // number of sent ACK packets
pktRecvACK: Integer; // number of received ACK packets
pktSentNAK: Integer; // number of sent NAK packets
pktRecvNAK: Integer; // number of received NAK packets
mbpsSendRate: Double; // sending rate in Mb/s
mbpsRecvRate: Double; // receiving rate in Mb/s
// instant measurements
usPktSndPeriod: Double; // packet sending period, in microseconds
pktFlowWindow: Integer; // flow window size, in number of packets
pktCongestionWindow: Integer; // congestion window size, in number of packets
pktFlightSize: Integer; // number of packets on flight
msRTT: Double; // RTT, in milliseconds
mbpsBandwidth: Double; // estimated bandwidth, in Mb/s
byteAvailSndBuf: Integer; // available UDT sender buffer size
byteAvailRcvBuf: Integer; // available UDT receiver buffer size
End;
timeval = Record
tv_sec: LongInt;
tv_usec: LongInt;
End;
SOCKOPT = UDTOpt;
TRACEINFO = CPerfMon;
pTRACEINFO = ^TRACEINFO;
pTimeVal = ^TimeVal;
pUDSET = Pointer;
Function socket(af, type_, protocol: Integer): UDTSOCKET; Cdecl; External UDTLIB Name 'udt_socket';
Function bind(u: UDTSOCKET; Const name: pSockAddr; namelen: Integer): Integer; Cdecl; External UDTLIB Name 'udt_bind';
Function listen(u: UDTSOCKET; backlog: Integer): Integer; Cdecl; External UDTLIB Name 'udt_listen';
Function accept(u: UDTSOCKET; addr: pSockAddr; addrlen: pInteger): UDTSOCKET; Cdecl; External UDTLIB Name 'udt_accept';
Function connect(u: UDTSOCKET; Const name: pSockAddr; namelen: Integer): Integer; Cdecl; External UDTLIB Name 'udt_connect';
Function close(u: UDTSOCKET): Integer; Cdecl; External UDTLIB Name 'udt_close';
Function getpeername(u: UDTSOCKET; name: pSockAddr; namelen: pInteger): Integer; Cdecl; External UDTLIB Name 'udt_getpeername';
Function getsockname(u: UDTSOCKET; name: pSockAddr; namelen: pInteger): Integer; Cdecl; External UDTLIB Name 'udt_getsockname';
Function getsockopt(u: UDTSOCKET; level: Integer; optname: SOCKOPT; optval: Pointer; optlen: pInteger): Integer; Cdecl; External UDTLIB Name 'udt_getsockopt';
Function setsockopt(u: UDTSOCKET; level: Integer; optname: SOCKOPT; Const optval: Pointer; optlen: Integer): Integer; Cdecl; External UDTLIB Name 'udt_setsockopt';
Function send(u: UDTSOCKET; Const buf: pChar; len, flags: Integer): Integer; Cdecl; External UDTLIB Name 'udt_send';
Function recv(u: UDTSOCKET; buf: pChar; len, flags: Integer): Integer; Cdecl; External UDTLIB Name 'udt_recv';
Function sendmsg(u: UDTSOCKET; Const buf: pChar; len: Integer; ttl: Integer = -1; inorder: Boolean = false): Integer; Cdecl; External UDTLIB Name 'udt_sendmsg';
Function recvmsg(u: UDTSOCKET; buf: pChar; len: Integer): Integer; Cdecl; External UDTLIB Name 'udt_recvmsg';
Function perfmon(u: UDTSOCKET; perf: pTRACEINFO; clear: Boolean = True): Integer; Cdecl; External UDTLIB Name 'udt_perfmon';
Function getlasterror: pChar; Cdecl; External UDTLIB Name 'udt_getlasterror';
Function select(nfds: Integer; readfds, writefds, exceptfds: pUDSET; Const timeout: pTimeVal): Integer; Cdecl; External UDTLIB Name 'udt_select';
Function write_set(u: pUDTSOCKET; uslen: Integer): pUDSET; Cdecl; External UDTLIB;
Procedure read_set(u: pUDSET; us: pUDTSOCKET; uslen: pInteger); Cdecl; External UDTLIB;Procedure free_set(u: pUDSET); Cdecl; External UDTLIB;
Implementation
End.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -