[go: up one dir, main page]

Menu

[r70]: / udt / api.h  Maximize  Restore  History

Download this file

178 lines (132 with data), 6.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*****************************************************************************
Copyright © 2001 - 2007, The Board of Trustees of the University of Illinois.
All Rights Reserved.
UDP-based Data Transfer Library (UDT) version 4
National Center for Data Mining (NCDM)
University of Illinois at Chicago
http://www.ncdm.uic.edu/
UDT is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.
UDT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
/*****************************************************************************
This header file contains the definition of structures related to UDT API.
*****************************************************************************/
/*****************************************************************************
written by
Yunhong Gu [gu@lac.uic.edu], last updated 06/27/2007
*****************************************************************************/
#ifndef __UDT_API_H__
#define __UDT_API_H__
#include <map>
#include <vector>
#include "udt.h"
#include "packet.h"
#include "queue.h"
#include "control.h"
class CUDT;
struct CUDTSocket
{
CUDTSocket();
~CUDTSocket();
enum UDTSTATUS {INIT = 1, OPENED, LISTENING, CONNECTED, CLOSED};
UDTSTATUS m_Status; // current socket state
uint64_t m_TimeStamp; // time when the socket is closed
int m_iIPversion; // IP version
sockaddr* m_pSelfAddr; // pointer to the local address of the socket
sockaddr* m_pPeerAddr; // pointer to the peer address of the socket
UDTSOCKET m_Socket; // socket ID
UDTSOCKET m_ListenSocket; // ID of the listener socket; 0 means this is an independent socket
UDTSOCKET m_PeerID; // peer socket ID
int32_t m_iISN; // initial sequence number, used to tell different connection from same IP:port
CUDT* m_pUDT; // pointer to the UDT entity
std::set<UDTSOCKET>* m_pQueuedSockets; // set of connections waiting for accept()
std::set<UDTSOCKET>* m_pAcceptSockets; // set of accept()ed connections
pthread_cond_t m_AcceptCond; // used to block "accept" call
pthread_mutex_t m_AcceptLock; // mutex associated to m_AcceptCond
unsigned int m_uiBackLog; // maximum number of connections in queue
};
////////////////////////////////////////////////////////////////////////////////
class CUDTUnited
{
friend class CUDT;
public:
CUDTUnited();
~CUDTUnited();
public:
// Functionality:
// Create a new UDT socket.
// Parameters:
// 0) [in] af: IP version, IPv4 (AF_INET) or IPv6 (AF_INET6).
// 1) [in] type: socket type, SOCK_STREAM or SOCK_DGRAM
// Returned value:
// The new UDT socket ID, or INVALID_SOCK.
UDTSOCKET newSocket(const int& af, const int& type);
// Functionality:
// Create a new UDT connection.
// Parameters:
// 0) [in] listen: the listening UDT socket;
// 1) [in] peer: peer address.
// 2) [in/out] hs: handshake information from peer side (in), negotiated value (out);
// Returned value:
// If the new connection is successfully created: 1 success, 0 already exist, -1 error.
int newConnection(const UDTSOCKET listen, const sockaddr* peer, CHandShake* hs);
// Functionality:
// look up the UDT entity according to its ID.
// Parameters:
// 0) [in] u: the UDT socket ID.
// Returned value:
// Pointer to the UDT entity.
CUDT* lookup(const UDTSOCKET u);
// socket APIs
int bind(const UDTSOCKET u, const sockaddr* name, const int& namelen);
int listen(const UDTSOCKET u, const int& backlog);
UDTSOCKET accept(const UDTSOCKET listen, sockaddr* addr, int* addrlen);
int connect(const UDTSOCKET u, const sockaddr* name, const int& namelen);
int close(const UDTSOCKET u);
int getpeername(const UDTSOCKET u, sockaddr* name, int* namelen);
int getsockname(const UDTSOCKET u, sockaddr* name, int* namelen);
int select(ud_set* readfds, ud_set* writefds, ud_set* exceptfds, const timeval* timeout);
// Functionality:
// record the UDT exception.
// Parameters:
// 0) [in] e: pointer to a UDT exception instance.
// Returned value:
// None.
void setError(CUDTException* e);
// Functionality:
// look up the most recent UDT exception.
// Parameters:
// None.
// Returned value:
// pointer to a UDT exception instance.
CUDTException* getError();
private:
std::map<UDTSOCKET, CUDTSocket*> m_Sockets; // stores all the socket structures
pthread_mutex_t m_ControlLock; // used to synchronize UDT API
pthread_mutex_t m_IDLock; // used to synchronize ID generation
UDTSOCKET m_SocketID; // seed to generate a new unique socket ID
private:
pthread_key_t m_TLSError; // thread local error record (last error)
static void TLSDestroy(void* e) {if (NULL != e) delete (CUDTException*)e;}
private:
CUDTSocket* locate(const UDTSOCKET u);
CUDTSocket* locate(const UDTSOCKET u, const sockaddr* peer, const UDTSOCKET& id, const int32_t& isn);
void checkBrokenSockets();
void removeSocket(const UDTSOCKET u);
void updateMux(CUDT* u, const sockaddr* addr = NULL);
void updateMux(CUDT* u, const CUDTSocket* ls);
private:
std::vector<CMultiplexer> m_vMultiplexer; // UDP multiplexer
pthread_mutex_t m_MultiplexerLock;
private:
CControl* m_pController; // UDT congestion control manager
};
#endif