1 /*
2 * SRT - Secure, Reliable, Transport
3 * Copyright (c) 2018 Haivision Systems Inc.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 */
10
11 /*****************************************************************************
12 written by
13 Haivision Systems Inc.
14 *****************************************************************************/
15
16 #ifndef INC_SRTC_H
17 #define INC_SRTC_H
18
19 #include "version.h"
20
21 #include "platform_sys.h"
22
23 #include <string.h>
24 #include <stdlib.h>
25
26 #include "logging_api.h"
27
28 ////////////////////////////////////////////////////////////////////////////////
29
30 //if compiling on VC6.0 or pre-WindowsXP systems
31 //use -DLEGACY_WIN32
32
33 //if compiling with MinGW, it only works on XP or above
34 //use -D_WIN32_WINNT=0x0501
35
36
37 #ifdef _WIN32
38 #ifndef __MINGW32__
39 // Explicitly define 32-bit and 64-bit numbers
40 typedef __int32 int32_t;
41 typedef __int64 int64_t;
42 typedef unsigned __int32 uint32_t;
43 #ifndef LEGACY_WIN32
44 typedef unsigned __int64 uint64_t;
45 #else
46 // VC 6.0 does not support unsigned __int64: may cause potential problems.
47 typedef __int64 uint64_t;
48 #endif
49
50 #ifdef SRT_DYNAMIC
51 #ifdef SRT_EXPORTS
52 #define SRT_API __declspec(dllexport)
53 #else
54 #define SRT_API __declspec(dllimport)
55 #endif
56 #else
57 #define SRT_API
58 #endif
59 #else // __MINGW32__
60 #define SRT_API
61 #endif
62 #else
63 #define SRT_API __attribute__ ((visibility("default")))
64 #endif
65
66
67 // For feature tests if you need.
68 // You can use these constants with SRTO_MINVERSION option.
69 #define SRT_VERSION_FEAT_HSv5 0x010300
70
71 #if defined(__cplusplus) && __cplusplus > 201406
72 #define SRT_HAVE_CXX17 1
73 #else
74 #define SRT_HAVE_CXX17 0
75 #endif
76
77
78 // Stadnard attributes
79
80 // When compiling in C++17 mode, use the standard C++17 attributes
81 // (out of these, only [[deprecated]] is supported in C++14, so
82 // for all lesser standard use compiler-specific attributes).
83 #if SRT_HAVE_CXX17
84
85 // Unused: DO NOT issue a warning if this entity is unused.
86 #define SRT_ATR_UNUSED [[maybe_unused]]
87
88 // Nodiscard: issue a warning if the return value was discarded.
89 #define SRT_ATR_NODISCARD [[nodiscard]]
90
91 // GNUG is GNU C/C++; this syntax is also supported by Clang
92 #elif defined(__GNUC__)
93 #define SRT_ATR_UNUSED __attribute__((unused))
94 #define SRT_ATR_NODISCARD __attribute__((warn_unused_result))
95 #elif defined(_MSC_VER)
96 #define SRT_ATR_UNUSED __pragma(warning(suppress: 4100 4101))
97 #define SRT_ATR_NODISCARD _Check_return_
98 #else
99 #define SRT_ATR_UNUSED
100 #define SRT_ATR_NODISCARD
101 #endif
102
103
104 // DEPRECATED attributes
105
106 // There's needed DEPRECATED and DEPRECATED_PX, as some compilers require them
107 // before the entity, others after the entity.
108 // The *_PX version is the prefix attribute, which applies only
109 // to functions (Microsoft compilers).
110
111 // When deprecating a function, mark it:
112 //
113 // SRT_ATR_DEPRECATED_PX retval function(arguments) SRT_ATR_DEPRECATED;
114 //
115
116 // When SRT_NO_DEPRECATED defined, do not issue any deprecation warnings.
117 // Regardless of the compiler type.
118 #if defined(SRT_NO_DEPRECATED)
119
120 #define SRT_ATR_DEPRECATED
121 #define SRT_ATR_DEPRECATED_PX
122
123 #elif SRT_HAVE_CXX17
124
125 #define SRT_ATR_DEPRECATED
126 #define SRT_ATR_DEPRECATED_PX [[deprecated]]
127
128 // GNUG is GNU C/C++; this syntax is also supported by Clang
129 #elif defined(__GNUC__)
130 #define SRT_ATR_DEPRECATED_PX
131 #define SRT_ATR_DEPRECATED __attribute__((deprecated))
132 #elif defined(_MSC_VER)
133 #define SRT_ATR_DEPRECATED_PX __declspec(deprecated)
134 #define SRT_ATR_DEPRECATED // no postfix-type modifier
135 #else
136 #define SRT_ATR_DEPRECATED_PX
137 #define SRT_ATR_DEPRECATED
138 #endif
139
140 #ifdef __cplusplus
141 extern "C" {
142 #endif
143
144 typedef int32_t SRTSOCKET;
145
146 // The most significant bit 31 (sign bit actually) is left unused,
147 // so that all people who check the value for < 0 instead of -1
148 // still get what they want. The bit 30 is reserved for marking
149 // the "socket group". Most of the API functions should work
150 // transparently with the socket descriptor designating a single
151 // socket or a socket group.
152 static const int32_t SRTGROUP_MASK = (1 << 30);
153
154 #ifdef _WIN32
155 #ifndef __MINGW32__
156 typedef SOCKET SYSSOCKET;
157 #else
158 typedef int SYSSOCKET;
159 #endif
160 #else
161 typedef int SYSSOCKET;
162 #endif
163
164 #ifndef ENABLE_EXPERIMENTAL_BONDING
165 #define ENABLE_EXPERIMENTAL_BONDING 0
166 #endif
167
168 typedef SYSSOCKET UDPSOCKET;
169
170
171 // Values returned by srt_getsockstate()
172 typedef enum SRT_SOCKSTATUS {
173 SRTS_INIT = 1,
174 SRTS_OPENED,
175 SRTS_LISTENING,
176 SRTS_CONNECTING,
177 SRTS_CONNECTED,
178 SRTS_BROKEN,
179 SRTS_CLOSING,
180 SRTS_CLOSED,
181 SRTS_NONEXIST
182 } SRT_SOCKSTATUS;
183
184 // This is a duplicate enum. Must be kept in sync with the original UDT enum for
185 // backward compatibility until all compat is destroyed.
186 typedef enum SRT_SOCKOPT {
187
188 SRTO_MSS = 0, // the Maximum Transfer Unit
189 SRTO_SNDSYN = 1, // if sending is blocking
190 SRTO_RCVSYN = 2, // if receiving is blocking
191 SRTO_ISN = 3, // Initial Sequence Number (valid only after srt_connect or srt_accept-ed sockets)
192 SRTO_FC = 4, // Flight flag size (window size)
193 SRTO_SNDBUF = 5, // maximum buffer in sending queue
194 SRTO_RCVBUF = 6, // UDT receiving buffer size
195 SRTO_LINGER = 7, // waiting for unsent data when closing
196 SRTO_UDP_SNDBUF = 8, // UDP sending buffer size
197 SRTO_UDP_RCVBUF = 9, // UDP receiving buffer size
198 // (some space left)
199 SRTO_RENDEZVOUS = 12, // rendezvous connection mode
200 SRTO_SNDTIMEO = 13, // send() timeout
201 SRTO_RCVTIMEO = 14, // recv() timeout
202 SRTO_REUSEADDR = 15, // reuse an existing port or create a new one
203 SRTO_MAXBW = 16, // maximum bandwidth (bytes per second) that the connection can use
204 SRTO_STATE = 17, // current socket state, see UDTSTATUS, read only
205 SRTO_EVENT = 18, // current available events associated with the socket
206 SRTO_SNDDATA = 19, // size of data in the sending buffer
207 SRTO_RCVDATA = 20, // size of data available for recv
208 SRTO_SENDER = 21, // Sender mode (independent of conn mode), for encryption, tsbpd handshake.
209 SRTO_TSBPDMODE = 22, // Enable/Disable TsbPd. Enable -> Tx set origin timestamp, Rx deliver packet at origin time + delay
210 SRTO_LATENCY = 23, // NOT RECOMMENDED. SET: to both SRTO_RCVLATENCY and SRTO_PEERLATENCY. GET: same as SRTO_RCVLATENCY.
211 SRTO_INPUTBW = 24, // Estimated input stream rate.
212 SRTO_OHEADBW, // MaxBW ceiling based on % over input stream rate. Applies when UDT_MAXBW=0 (auto).
213 SRTO_PASSPHRASE = 26, // Crypto PBKDF2 Passphrase (must be 10..79 characters, or empty to disable encryption)
214 SRTO_PBKEYLEN, // Crypto key len in bytes {16,24,32} Default: 16 (AES-128)
215 SRTO_KMSTATE, // Key Material exchange status (UDT_SRTKmState)
216 SRTO_IPTTL = 29, // IP Time To Live (passthru for system sockopt IPPROTO_IP/IP_TTL)
217 SRTO_IPTOS, // IP Type of Service (passthru for system sockopt IPPROTO_IP/IP_TOS)
218 SRTO_TLPKTDROP = 31, // Enable receiver pkt drop
219 SRTO_SNDDROPDELAY = 32, // Extra delay towards latency for sender TLPKTDROP decision (-1 to off)
220 SRTO_NAKREPORT = 33, // Enable receiver to send periodic NAK reports
221 SRTO_VERSION = 34, // Local SRT Version
222 SRTO_PEERVERSION, // Peer SRT Version (from SRT Handshake)
223 SRTO_CONNTIMEO = 36, // Connect timeout in msec. Caller default: 3000, rendezvous (x 10)
224 SRTO_DRIFTTRACER = 37, // Enable or disable drift tracer
225 SRTO_MININPUTBW = 38, // Minimum estimate of input stream rate.
226 // (some space left)
227 SRTO_SNDKMSTATE = 40, // (GET) the current state of the encryption at the peer side
228 SRTO_RCVKMSTATE, // (GET) the current state of the encryption at the agent side
229 SRTO_LOSSMAXTTL, // Maximum possible packet reorder tolerance (number of packets to receive after loss to send lossreport)
230 SRTO_RCVLATENCY, // TsbPd receiver delay (mSec) to absorb burst of missed packet retransmission
231 SRTO_PEERLATENCY, // Minimum value of the TsbPd receiver delay (mSec) for the opposite side (peer)
232 SRTO_MINVERSION, // Minimum SRT version needed for the peer (peers with less version will get connection reject)
233 SRTO_STREAMID, // A string set to a socket and passed to the listener's accepted socket
234 SRTO_CONGESTION, // Congestion controller type selection
235 SRTO_MESSAGEAPI, // In File mode, use message API (portions of data with boundaries)
236 SRTO_PAYLOADSIZE, // Maximum payload size sent in one UDP packet (0 if unlimited)
237 SRTO_TRANSTYPE = 50, // Transmission type (set of options required for given transmission type)
238 SRTO_KMREFRESHRATE, // After sending how many packets the encryption key should be flipped to the new key
239 SRTO_KMPREANNOUNCE, // How many packets before key flip the new key is annnounced and after key flip the old one decommissioned
240 SRTO_ENFORCEDENCRYPTION, // Connection to be rejected or quickly broken when one side encryption set or bad password
241 SRTO_IPV6ONLY, // IPV6_V6ONLY mode
242 SRTO_PEERIDLETIMEO, // Peer-idle timeout (max time of silence heard from peer) in [ms]
243 SRTO_BINDTODEVICE, // Forward the SOL_SOCKET/SO_BINDTODEVICE option on socket (pass packets only from that device)
244 #if ENABLE_EXPERIMENTAL_BONDING
245 SRTO_GROUPCONNECT, // Set on a listener to allow group connection
246 SRTO_GROUPSTABTIMEO, // Stability timeout (backup groups) in [us]
247 SRTO_GROUPTYPE, // Group type to which an accepted socket is about to be added, available in the handshake
248 #endif
249 SRTO_PACKETFILTER = 60, // Add and configure a packet filter
250 SRTO_RETRANSMITALGO = 61, // An option to select packet retransmission algorithm
251
252 SRTO_E_SIZE // Always last element, not a valid option.
253 } SRT_SOCKOPT;
254
255
256 #ifdef __cplusplus
257
258
259 #if __cplusplus > 199711L // C++11
260 // Newer compilers report error when [[deprecated]] is applied to types,
261 // and C++11 and higher uses this.
262 // Note that this doesn't exactly use the 'deprecated' attribute,
263 // as it's introduced in C++14. What is actually used here is the
264 // fact that unknown attributes are ignored, but still warned about.
265 // This should only catch an eye - and that's what it does.
266 #define SRT_DEPRECATED_OPTION(value) ((SRT_SOCKOPT [[deprecated]])value)
267 #else
268 // Older (pre-C++11) compilers use gcc deprecated applied to a typedef
269 typedef SRT_ATR_DEPRECATED_PX SRT_SOCKOPT SRT_SOCKOPT_DEPRECATED SRT_ATR_DEPRECATED;
270 #define SRT_DEPRECATED_OPTION(value) ((SRT_SOCKOPT_DEPRECATED)value)
271 #endif
272
273
274 #else
275
276 // deprecated enum labels are supported only since gcc 6, so in C there
277 // will be a whole deprecated enum type, as it's not an error in C to mix
278 // enum types
279 enum SRT_ATR_DEPRECATED SRT_SOCKOPT_DEPRECATED
280 {
281
282 // Dummy last option, as every entry ends with a comma
283 SRTO_DEPRECATED_END = 0
284
285 };
286 #define SRT_DEPRECATED_OPTION(value) ((enum SRT_SOCKOPT_DEPRECATED)value)
287 #endif
288
289 // Note that there are no deprecated options at the moment, but the mechanism
290 // stays so that it can be used in future. Example:
291 // #define SRTO_STRICTENC SRT_DEPRECATED_OPTION(53)
292
293 typedef enum SRT_TRANSTYPE
294 {
295 SRTT_LIVE,
296 SRTT_FILE,
297 SRTT_INVALID
298 } SRT_TRANSTYPE;
299
300 // These sizes should be used for Live mode. In Live mode you should not
301 // exceed the size that fits in a single MTU.
302
303 // This is for MPEG TS and it's a default SRTO_PAYLOADSIZE for SRTT_LIVE.
304 static const int SRT_LIVE_DEF_PLSIZE = 1316; // = 188*7, recommended for MPEG TS
305
306 // This is the maximum payload size for Live mode, should you have a different
307 // payload type than MPEG TS.
308 static const int SRT_LIVE_MAX_PLSIZE = 1456; // MTU(1500) - UDP.hdr(28) - SRT.hdr(16)
309
310 // Latency for Live transmission: default is 120
311 static const int SRT_LIVE_DEF_LATENCY_MS = 120;
312
313 // Importrant note: please add new fields to this structure to the end and don't remove any existing fields
314 struct CBytePerfMon
315 {
316 // global measurements
317 int64_t msTimeStamp; // time since the UDT entity is started, in milliseconds
318 int64_t pktSentTotal; // total number of sent data packets, including retransmissions
319 int64_t pktRecvTotal; // total number of received packets
320 int pktSndLossTotal; // total number of lost packets (sender side)
321 int pktRcvLossTotal; // total number of lost packets (receiver side)
322 int pktRetransTotal; // total number of retransmitted packets
323 int pktSentACKTotal; // total number of sent ACK packets
324 int pktRecvACKTotal; // total number of received ACK packets
325 int pktSentNAKTotal; // total number of sent NAK packets
326 int pktRecvNAKTotal; // total number of received NAK packets
327 int64_t usSndDurationTotal; // total time duration when UDT is sending data (idle time exclusive)
328 //>new
329 int pktSndDropTotal; // number of too-late-to-send dropped packets
330 int pktRcvDropTotal; // number of too-late-to play missing packets
331 int pktRcvUndecryptTotal; // number of undecrypted packets
332 uint64_t byteSentTotal; // total number of sent data bytes, including retransmissions
333 uint64_t byteRecvTotal; // total number of received bytes
334 uint64_t byteRcvLossTotal; // total number of lost bytes
335 uint64_t byteRetransTotal; // total number of retransmitted bytes
336 uint64_t byteSndDropTotal; // number of too-late-to-send dropped bytes
337 uint64_t byteRcvDropTotal; // number of too-late-to play missing bytes (estimate based on average packet size)
338 uint64_t byteRcvUndecryptTotal; // number of undecrypted bytes
339 //<
340
341 // local measurements
342 int64_t pktSent; // number of sent data packets, including retransmissions
343 int64_t pktRecv; // number of received packets
344 int pktSndLoss; // number of lost packets (sender side)
345 int pktRcvLoss; // number of lost packets (receiver side)
346 int pktRetrans; // number of retransmitted packets
347 int pktRcvRetrans; // number of retransmitted packets received
348 int pktSentACK; // number of sent ACK packets
349 int pktRecvACK; // number of received ACK packets
350 int pktSentNAK; // number of sent NAK packets
351 int pktRecvNAK; // number of received NAK packets
352 double mbpsSendRate; // sending rate in Mb/s
353 double mbpsRecvRate; // receiving rate in Mb/s
354 int64_t usSndDuration; // busy sending time (i.e., idle time exclusive)
355 int pktReorderDistance; // size of order discrepancy in received sequences
356 double pktRcvAvgBelatedTime; // average time of packet delay for belated packets (packets with sequence past the ACK)
357 int64_t pktRcvBelated; // number of received AND IGNORED packets due to having come too late
358 //>new
359 int pktSndDrop; // number of too-late-to-send dropped packets
360 int pktRcvDrop; // number of too-late-to play missing packets
361 int pktRcvUndecrypt; // number of undecrypted packets
362 uint64_t byteSent; // number of sent data bytes, including retransmissions
363 uint64_t byteRecv; // number of received bytes
364 uint64_t byteRcvLoss; // number of retransmitted bytes
365 uint64_t byteRetrans; // number of retransmitted bytes
366 uint64_t byteSndDrop; // number of too-late-to-send dropped bytes
367 uint64_t byteRcvDrop; // number of too-late-to play missing bytes (estimate based on average packet size)
368 uint64_t byteRcvUndecrypt; // number of undecrypted bytes
369 //<
370
371 // instant measurements
372 double usPktSndPeriod; // packet sending period, in microseconds
373 int pktFlowWindow; // flow window size, in number of packets
374 int pktCongestionWindow; // congestion window size, in number of packets
375 int pktFlightSize; // number of packets on flight
376 double msRTT; // RTT, in milliseconds
377 double mbpsBandwidth; // estimated bandwidth, in Mb/s
378 int byteAvailSndBuf; // available UDT sender buffer size
379 int byteAvailRcvBuf; // available UDT receiver buffer size
380 //>new
381 double mbpsMaxBW; // Transmit Bandwidth ceiling (Mbps)
382 int byteMSS; // MTU
383
384 int pktSndBuf; // UnACKed packets in UDT sender
385 int byteSndBuf; // UnACKed bytes in UDT sender
386 int msSndBuf; // UnACKed timespan (msec) of UDT sender
387 int msSndTsbPdDelay; // Timestamp-based Packet Delivery Delay
388
389 int pktRcvBuf; // Undelivered packets in UDT receiver
390 int byteRcvBuf; // Undelivered bytes of UDT receiver
391 int msRcvBuf; // Undelivered timespan (msec) of UDT receiver
392 int msRcvTsbPdDelay; // Timestamp-based Packet Delivery Delay
393
394 int pktSndFilterExtraTotal; // number of control packets supplied by packet filter
395 int pktRcvFilterExtraTotal; // number of control packets received and not supplied back
396 int pktRcvFilterSupplyTotal; // number of packets that the filter supplied extra (e.g. FEC rebuilt)
397 int pktRcvFilterLossTotal; // number of packet loss not coverable by filter
398
399 int pktSndFilterExtra; // number of control packets supplied by packet filter
400 int pktRcvFilterExtra; // number of control packets received and not supplied back
401 int pktRcvFilterSupply; // number of packets that the filter supplied extra (e.g. FEC rebuilt)
402 int pktRcvFilterLoss; // number of packet loss not coverable by filter
403 int pktReorderTolerance; // packet reorder tolerance value
404 //<
405
406 // New stats in 1.5.0
407
408 // Total
409 int64_t pktSentUniqueTotal; // total number of data packets sent by the application
410 int64_t pktRecvUniqueTotal; // total number of packets to be received by the application
411 uint64_t byteSentUniqueTotal; // total number of data bytes, sent by the application
412 uint64_t byteRecvUniqueTotal; // total number of data bytes to be received by the application
413
414 // Local
415 int64_t pktSentUnique; // number of data packets sent by the application
416 int64_t pktRecvUnique; // number of packets to be received by the application
417 uint64_t byteSentUnique; // number of data bytes, sent by the application
418 uint64_t byteRecvUnique; // number of data bytes to be received by the application
419 };
420
421 ////////////////////////////////////////////////////////////////////////////////
422
423 // Error codes - define outside the CUDTException class
424 // because otherwise you'd have to use CUDTException::MJ_SUCCESS etc.
425 // in all throw CUDTException expressions.
426 enum CodeMajor
427 {
428 MJ_UNKNOWN = -1,
429 MJ_SUCCESS = 0,
430 MJ_SETUP = 1,
431 MJ_CONNECTION = 2,
432 MJ_SYSTEMRES = 3,
433 MJ_FILESYSTEM = 4,
434 MJ_NOTSUP = 5,
435 MJ_AGAIN = 6,
436 MJ_PEERERROR = 7
437 };
438
439 enum CodeMinor
440 {
441 // These are "minor" error codes from various "major" categories
442 // MJ_SETUP
443 MN_NONE = 0,
444 MN_TIMEOUT = 1,
445 MN_REJECTED = 2,
446 MN_NORES = 3,
447 MN_SECURITY = 4,
448 MN_CLOSED = 5,
449 // MJ_CONNECTION
450 MN_CONNLOST = 1,
451 MN_NOCONN = 2,
452 // MJ_SYSTEMRES
453 MN_THREAD = 1,
454 MN_MEMORY = 2,
455 MN_OBJECT = 3,
456 // MJ_FILESYSTEM
457 MN_SEEKGFAIL = 1,
458 MN_READFAIL = 2,
459 MN_SEEKPFAIL = 3,
460 MN_WRITEFAIL = 4,
461 // MJ_NOTSUP
462 MN_ISBOUND = 1,
463 MN_ISCONNECTED = 2,
464 MN_INVAL = 3,
465 MN_SIDINVAL = 4,
466 MN_ISUNBOUND = 5,
467 MN_NOLISTEN = 6,
468 MN_ISRENDEZVOUS = 7,
469 MN_ISRENDUNBOUND = 8,
470 MN_INVALMSGAPI = 9,
471 MN_INVALBUFFERAPI = 10,
472 MN_BUSY = 11,
473 MN_XSIZE = 12,
474 MN_EIDINVAL = 13,
475 MN_EEMPTY = 14,
476 MN_BUSYPORT = 15,
477 // MJ_AGAIN
478 MN_WRAVAIL = 1,
479 MN_RDAVAIL = 2,
480 MN_XMTIMEOUT = 3,
481 MN_CONGESTION = 4
482 };
483
484
485 // Stupid, but effective. This will be #undefined, so don't worry.
486 #define MJ(major) (1000 * MJ_##major)
487 #define MN(major, minor) (1000 * MJ_##major + MN_##minor)
488
489 // Some better way to define it, and better for C language.
490 typedef enum SRT_ERRNO
491 {
492 SRT_EUNKNOWN = -1,
493 SRT_SUCCESS = MJ_SUCCESS,
494
495 SRT_ECONNSETUP = MJ(SETUP),
496 SRT_ENOSERVER = MN(SETUP, TIMEOUT),
497 SRT_ECONNREJ = MN(SETUP, REJECTED),
498 SRT_ESOCKFAIL = MN(SETUP, NORES),
499 SRT_ESECFAIL = MN(SETUP, SECURITY),
500 SRT_ESCLOSED = MN(SETUP, CLOSED),
501
502 SRT_ECONNFAIL = MJ(CONNECTION),
503 SRT_ECONNLOST = MN(CONNECTION, CONNLOST),
504 SRT_ENOCONN = MN(CONNECTION, NOCONN),
505
506 SRT_ERESOURCE = MJ(SYSTEMRES),
507 SRT_ETHREAD = MN(SYSTEMRES, THREAD),
508 SRT_ENOBUF = MN(SYSTEMRES, MEMORY),
509 SRT_ESYSOBJ = MN(SYSTEMRES, OBJECT),
510
511 SRT_EFILE = MJ(FILESYSTEM),
512 SRT_EINVRDOFF = MN(FILESYSTEM, SEEKGFAIL),
513 SRT_ERDPERM = MN(FILESYSTEM, READFAIL),
514 SRT_EINVWROFF = MN(FILESYSTEM, SEEKPFAIL),
515 SRT_EWRPERM = MN(FILESYSTEM, WRITEFAIL),
516
517 SRT_EINVOP = MJ(NOTSUP),
518 SRT_EBOUNDSOCK = MN(NOTSUP, ISBOUND),
519 SRT_ECONNSOCK = MN(NOTSUP, ISCONNECTED),
520 SRT_EINVPARAM = MN(NOTSUP, INVAL),
521 SRT_EINVSOCK = MN(NOTSUP, SIDINVAL),
522 SRT_EUNBOUNDSOCK = MN(NOTSUP, ISUNBOUND),
523 SRT_ENOLISTEN = MN(NOTSUP, NOLISTEN),
524 SRT_ERDVNOSERV = MN(NOTSUP, ISRENDEZVOUS),
525 SRT_ERDVUNBOUND = MN(NOTSUP, ISRENDUNBOUND),
526 SRT_EINVALMSGAPI = MN(NOTSUP, INVALMSGAPI),
527 SRT_EINVALBUFFERAPI = MN(NOTSUP, INVALBUFFERAPI),
528 SRT_EDUPLISTEN = MN(NOTSUP, BUSY),
529 SRT_ELARGEMSG = MN(NOTSUP, XSIZE),
530 SRT_EINVPOLLID = MN(NOTSUP, EIDINVAL),
531 SRT_EPOLLEMPTY = MN(NOTSUP, EEMPTY),
532 SRT_EBINDCONFLICT = MN(NOTSUP, BUSYPORT),
533
534 SRT_EASYNCFAIL = MJ(AGAIN),
535 SRT_EASYNCSND = MN(AGAIN, WRAVAIL),
536 SRT_EASYNCRCV = MN(AGAIN, RDAVAIL),
537 SRT_ETIMEOUT = MN(AGAIN, XMTIMEOUT),
538 SRT_ECONGEST = MN(AGAIN, CONGESTION),
539
540 SRT_EPEERERR = MJ(PEERERROR)
541 } SRT_ERRNO;
542
543
544 #undef MJ
545 #undef MN
546
547 enum SRT_REJECT_REASON
548 {
549 SRT_REJ_UNKNOWN, // initial set when in progress
550 SRT_REJ_SYSTEM, // broken due to system function error
551 SRT_REJ_PEER, // connection was rejected by peer
552 SRT_REJ_RESOURCE, // internal problem with resource allocation
553 SRT_REJ_ROGUE, // incorrect data in handshake messages
554 SRT_REJ_BACKLOG, // listener's backlog exceeded
555 SRT_REJ_IPE, // internal program error
556 SRT_REJ_CLOSE, // socket is closing
557 SRT_REJ_VERSION, // peer is older version than agent's minimum set
558 SRT_REJ_RDVCOOKIE, // rendezvous cookie collision
559 SRT_REJ_BADSECRET, // wrong password
560 SRT_REJ_UNSECURE, // password required or unexpected
561 SRT_REJ_MESSAGEAPI, // streamapi/messageapi collision
562 SRT_REJ_CONGESTION, // incompatible congestion-controller type
563 SRT_REJ_FILTER, // incompatible packet filter
564 SRT_REJ_GROUP, // incompatible group
565 SRT_REJ_TIMEOUT, // connection timeout
566
567 SRT_REJ_E_SIZE,
568 };
569
570 // XXX This value remains for some time, but it's deprecated
571 // Planned deprecation removal: rel1.6.0.
572 #define SRT_REJ__SIZE SRT_REJ_E_SIZE
573
574 // Reject category codes:
575
576 #define SRT_REJC_VALUE(code) (1000 * (code/1000))
577 #define SRT_REJC_INTERNAL 0 // Codes from above SRT_REJECT_REASON enum
578 #define SRT_REJC_PREDEFINED 1000 // Standard server error codes
579 #define SRT_REJC_USERDEFINED 2000 // User defined error codes
580
581
582 // Logging API - specialization for SRT.
583
584 // WARNING: This part is generated.
585
586 // Logger Functional Areas
587 // Note that 0 is "general".
588
589 // Values 0* - general, unqualified
590 // Values 1* - control
591 // Values 2* - receiving
592 // Values 3* - sending
593 // Values 4* - management
594
595 // Made by #define so that it's available also for C API.
596
597 // Use ../scripts/generate-logging-defs.tcl to regenerate.
598
599 // SRT_LOGFA BEGIN GENERATED SECTION {
600
601 #define SRT_LOGFA_GENERAL 0 // gglog: General uncategorized log, for serious issues only
602 #define SRT_LOGFA_SOCKMGMT 1 // smlog: Socket create/open/close/configure activities
603 #define SRT_LOGFA_CONN 2 // cnlog: Connection establishment and handshake
604 #define SRT_LOGFA_XTIMER 3 // xtlog: The checkTimer and around activities
605 #define SRT_LOGFA_TSBPD 4 // tslog: The TsBPD thread
606 #define SRT_LOGFA_RSRC 5 // rslog: System resource allocation and management
607
608 #define SRT_LOGFA_CONGEST 7 // cclog: Congestion control module
609 #define SRT_LOGFA_PFILTER 8 // pflog: Packet filter module
610
611 #define SRT_LOGFA_API_CTRL 11 // aclog: API part for socket and library managmenet
612
613 #define SRT_LOGFA_QUE_CTRL 13 // qclog: Queue control activities
614
615 #define SRT_LOGFA_EPOLL_UPD 16 // eilog: EPoll, internal update activities
616
617 #define SRT_LOGFA_API_RECV 21 // arlog: API part for receiving
618 #define SRT_LOGFA_BUF_RECV 22 // brlog: Buffer, receiving side
619 #define SRT_LOGFA_QUE_RECV 23 // qrlog: Queue, receiving side
620 #define SRT_LOGFA_CHN_RECV 24 // krlog: CChannel, receiving side
621 #define SRT_LOGFA_GRP_RECV 25 // grlog: Group, receiving side
622
623 #define SRT_LOGFA_API_SEND 31 // aslog: API part for sending
624 #define SRT_LOGFA_BUF_SEND 32 // bslog: Buffer, sending side
625 #define SRT_LOGFA_QUE_SEND 33 // qslog: Queue, sending side
626 #define SRT_LOGFA_CHN_SEND 34 // kslog: CChannel, sending side
627 #define SRT_LOGFA_GRP_SEND 35 // gslog: Group, sending side
628
629 #define SRT_LOGFA_INTERNAL 41 // inlog: Internal activities not connected directly to a socket
630
631 #define SRT_LOGFA_QUE_MGMT 43 // qmlog: Queue, management part
632 #define SRT_LOGFA_CHN_MGMT 44 // kmlog: CChannel, management part
633 #define SRT_LOGFA_GRP_MGMT 45 // gmlog: Group, management part
634 #define SRT_LOGFA_EPOLL_API 46 // ealog: EPoll, API part
635
636 #define SRT_LOGFA_HAICRYPT 6 // hclog: Haicrypt module area
637 #define SRT_LOGFA_APPLOG 10 // aplog: Applications
638
639 // } SRT_LOGFA END GENERATED SECTION
640
641 // To make a typical int64_t size, although still use std::bitset.
642 // C API will carry it over.
643 #define SRT_LOGFA_LASTNONE 63
644
645 enum SRT_KM_STATE
646 {
647 SRT_KM_S_UNSECURED = 0, //No encryption
648 SRT_KM_S_SECURING = 1, //Stream encrypted, exchanging Keying Material
649 SRT_KM_S_SECURED = 2, //Stream encrypted, keying Material exchanged, decrypting ok.
650 SRT_KM_S_NOSECRET = 3, //Stream encrypted and no secret to decrypt Keying Material
651 SRT_KM_S_BADSECRET = 4 //Stream encrypted and wrong secret, cannot decrypt Keying Material
652 };
653
654 enum SRT_EPOLL_OPT
655 {
656 SRT_EPOLL_OPT_NONE = 0x0, // fallback
657
658 // Values intended to be the same as in `<sys/epoll.h>`.
659 // so that if system values are used by mistake, they should have the same effect
660 // This applies to: IN, OUT, ERR and ET.
661
662 /// Ready for 'recv' operation:
663 ///
664 /// - For stream mode it means that at least 1 byte is available.
665 /// In this mode the buffer may extract only a part of the packet,
666 /// leaving next data possible for extraction later.
667 ///
668 /// - For message mode it means that there is at least one packet
669 /// available (this may change in future, as it is desired that
670 /// one full message should only wake up, not single packet of a
671 /// not yet extractable message).
672 ///
673 /// - For live mode it means that there's at least one packet
674 /// ready to play.
675 ///
676 /// - For listener sockets, this means that there is a new connection
677 /// waiting for pickup through the `srt_accept()` call, that is,
678 /// the next call to `srt_accept()` will succeed without blocking
679 /// (see an alias SRT_EPOLL_ACCEPT below).
680 SRT_EPOLL_IN = 0x1,
681
682 /// Ready for 'send' operation.
683 ///
684 /// - For stream mode it means that there's a free space in the
685 /// sender buffer for at least 1 byte of data. The next send
686 /// operation will only allow to send as much data as it is free
687 /// space in the buffer.
688 ///
689 /// - For message mode it means that there's a free space for at
690 /// least one UDP packet. The edge-triggered mode can be used to
691 /// pick up updates as the free space in the sender buffer grows.
692 ///
693 /// - For live mode it means that there's a free space for at least
694 /// one UDP packet. On the other hand, no readiness for OUT usually
695 /// means an extraordinary congestion on the link, meaning also that
696 /// you should immediately slow down the sending rate or you may get
697 /// a connection break soon.
698 ///
699 /// - For non-blocking sockets used with `srt_connect*` operation,
700 /// this flag simply means that the connection was established.
701 SRT_EPOLL_OUT = 0x4,
702
703 /// The socket has encountered an error in the last operation
704 /// and the next operation on that socket will end up with error.
705 /// You can retry the operation, but getting the error from it
706 /// is certain, so you may as well close the socket.
707 SRT_EPOLL_ERR = 0x8,
708
709 // To avoid confusion in the internal code, the following
710 // duplicates are introduced to improve clarity.
711 SRT_EPOLL_CONNECT = SRT_EPOLL_OUT,
712 SRT_EPOLL_ACCEPT = SRT_EPOLL_IN,
713
714 SRT_EPOLL_UPDATE = 0x10,
715 SRT_EPOLL_ET = 1u << 31
716 };
717 // These are actually flags - use a bit container:
718 typedef int32_t SRT_EPOLL_T;
719
720 // Define which epoll flags determine events. All others are special flags.
721 #define SRT_EPOLL_EVENTTYPES (SRT_EPOLL_IN | SRT_EPOLL_OUT | SRT_EPOLL_UPDATE | SRT_EPOLL_ERR)
722 #define SRT_EPOLL_ETONLY (SRT_EPOLL_UPDATE)
723
724 enum SRT_EPOLL_FLAGS
725 {
726 /// This allows the EID container to be empty when calling the waiting
727 /// function with infinite time. This means an infinite hangup, although
728 /// a socket can be added to this EID from a separate thread.
729 SRT_EPOLL_ENABLE_EMPTY = 1,
730
731 /// This makes the waiting function check if there is output container
732 /// passed to it, and report an error if it isn't. By default it is allowed
733 /// that the output container is 0 size or NULL and therefore the readiness
734 /// state is reported only as a number of ready sockets from return value.
735 SRT_EPOLL_ENABLE_OUTPUTCHECK = 2
736 };
737
738 #ifdef __cplusplus
739 // In C++ these enums cannot be treated as int and glued by operator |.
740 // Unless this operator is defined.
741 inline SRT_EPOLL_OPT operator|(SRT_EPOLL_OPT a1, SRT_EPOLL_OPT a2)
742 {
743 return SRT_EPOLL_OPT( (int)a1 | (int)a2 );
744 }
745
746 #endif
747
748 typedef struct CBytePerfMon SRT_TRACEBSTATS;
749
750 static const SRTSOCKET SRT_INVALID_SOCK = -1;
751 static const int SRT_ERROR = -1;
752
753 // library initialization
754 SRT_API int srt_startup(void);
755 SRT_API int srt_cleanup(void);
756
757 //
758 // Socket operations
759 //
760 // DEPRECATED: srt_socket with 3 arguments. All these arguments are ignored
761 // and socket creation doesn't need any arguments. Use srt_create_socket().
762 // Planned deprecation removal: rel1.6.0
763 SRT_ATR_DEPRECATED_PX SRT_API SRTSOCKET srt_socket(int, int, int) SRT_ATR_DEPRECATED;
764 SRT_API SRTSOCKET srt_create_socket(void);
765
766 // Group management
767
768 // Stubs when off
769
770 typedef struct SRT_SocketGroupData_ SRT_SOCKGROUPDATA;
771
772 #if ENABLE_EXPERIMENTAL_BONDING
773
774 typedef enum SRT_GROUP_TYPE
775 {
776 SRT_GTYPE_UNDEFINED,
777 SRT_GTYPE_BROADCAST,
778 SRT_GTYPE_BACKUP,
779 SRT_GTYPE_BALANCING,
780 SRT_GTYPE_MULTICAST,
781 // ...
782 SRT_GTYPE_E_END
783 } SRT_GROUP_TYPE;
784
785 // Free-form flags for groups
786 // Flags may be type-specific!
787 static const uint32_t SRT_GFLAG_SYNCONMSG = 1;
788
789 typedef enum SRT_MemberStatus
790 {
791 SRT_GST_PENDING, // The socket is created correctly, but not yet ready for getting data.
792 SRT_GST_IDLE, // The socket is ready to be activated
793 SRT_GST_RUNNING, // The socket was already activated and is in use
794 SRT_GST_BROKEN // The last operation broke the socket, it should be closed.
795 } SRT_MEMBERSTATUS;
796
797 struct SRT_SocketGroupData_
798 {
799 SRTSOCKET id;
800 struct sockaddr_storage peeraddr; // Don't want to expose sockaddr_any to public API
801 SRT_SOCKSTATUS sockstate;
802 uint16_t weight;
803 SRT_MEMBERSTATUS memberstate;
804 int result;
805 int token;
806 };
807
808 typedef struct SRT_SocketOptionObject SRT_SOCKOPT_CONFIG;
809
810 typedef struct SRT_GroupMemberConfig_
811 {
812 SRTSOCKET id;
813 struct sockaddr_storage srcaddr;
814 struct sockaddr_storage peeraddr; // Don't want to expose sockaddr_any to public API
815 uint16_t weight;
816 SRT_SOCKOPT_CONFIG* config;
817 int errorcode;
818 int token;
819 } SRT_SOCKGROUPCONFIG;
820
821 SRT_API SRTSOCKET srt_create_group (SRT_GROUP_TYPE);
822 SRT_API int srt_include (SRTSOCKET socket, SRTSOCKET group);
823 SRT_API int srt_exclude (SRTSOCKET socket);
824 SRT_API SRTSOCKET srt_groupof (SRTSOCKET socket);
825 SRT_API int srt_group_data (SRTSOCKET socketgroup, SRT_SOCKGROUPDATA* output, size_t* inoutlen);
826 SRT_API int srt_group_configure(SRTSOCKET socketgroup, const char* str);
827
828 SRT_API SRT_SOCKOPT_CONFIG* srt_create_config(void);
829 SRT_API void srt_delete_config(SRT_SOCKOPT_CONFIG* config /*nullable*/);
830 SRT_API int srt_config_add(SRT_SOCKOPT_CONFIG* config, SRT_SOCKOPT option, const void* contents, int len);
831
832 SRT_API SRT_SOCKGROUPCONFIG srt_prepare_endpoint(const struct sockaddr* src /*nullable*/, const struct sockaddr* adr, int namelen);
833 SRT_API int srt_connect_group(SRTSOCKET group, SRT_SOCKGROUPCONFIG name [], int arraysize);
834
835 #endif // ENABLE_EXPERIMENTAL_BONDING
836
837 SRT_API int srt_bind (SRTSOCKET u, const struct sockaddr* name, int namelen);
838 SRT_API int srt_bind_acquire (SRTSOCKET u, UDPSOCKET sys_udp_sock);
839 // Old name of srt_bind_acquire(), please don't use
840 // Planned deprecation removal: rel1.6.0
841 SRT_ATR_DEPRECATED_PX static inline int srt_bind_peerof(SRTSOCKET u, UDPSOCKET sys_udp_sock) SRT_ATR_DEPRECATED;
srt_bind_peerof(SRTSOCKET u,UDPSOCKET sys_udp_sock)842 static inline int srt_bind_peerof (SRTSOCKET u, UDPSOCKET sys_udp_sock) { return srt_bind_acquire(u, sys_udp_sock); }
843 SRT_API int srt_listen (SRTSOCKET u, int backlog);
844 SRT_API SRTSOCKET srt_accept (SRTSOCKET u, struct sockaddr* addr, int* addrlen);
845 SRT_API SRTSOCKET srt_accept_bond (const SRTSOCKET listeners[], int lsize, int64_t msTimeOut);
846 typedef int srt_listen_callback_fn (void* opaq, SRTSOCKET ns, int hsversion, const struct sockaddr* peeraddr, const char* streamid);
847 SRT_API int srt_listen_callback(SRTSOCKET lsn, srt_listen_callback_fn* hook_fn, void* hook_opaque);
848 typedef void srt_connect_callback_fn (void* opaq, SRTSOCKET ns, int errorcode, const struct sockaddr* peeraddr, int token);
849 SRT_API int srt_connect_callback(SRTSOCKET clr, srt_connect_callback_fn* hook_fn, void* hook_opaque);
850 SRT_API int srt_connect (SRTSOCKET u, const struct sockaddr* name, int namelen);
851 SRT_API int srt_connect_debug(SRTSOCKET u, const struct sockaddr* name, int namelen, int forced_isn);
852 SRT_API int srt_connect_bind (SRTSOCKET u, const struct sockaddr* source,
853 const struct sockaddr* target, int len);
854 SRT_API int srt_rendezvous (SRTSOCKET u, const struct sockaddr* local_name, int local_namelen,
855 const struct sockaddr* remote_name, int remote_namelen);
856
857 SRT_API int srt_close (SRTSOCKET u);
858 SRT_API int srt_getpeername (SRTSOCKET u, struct sockaddr* name, int* namelen);
859 SRT_API int srt_getsockname (SRTSOCKET u, struct sockaddr* name, int* namelen);
860 SRT_API int srt_getsockopt (SRTSOCKET u, int level /*ignored*/, SRT_SOCKOPT optname, void* optval, int* optlen);
861 SRT_API int srt_setsockopt (SRTSOCKET u, int level /*ignored*/, SRT_SOCKOPT optname, const void* optval, int optlen);
862 SRT_API int srt_getsockflag (SRTSOCKET u, SRT_SOCKOPT opt, void* optval, int* optlen);
863 SRT_API int srt_setsockflag (SRTSOCKET u, SRT_SOCKOPT opt, const void* optval, int optlen);
864
865 typedef struct SRT_MsgCtrl_
866 {
867 int flags; // Left for future
868 int msgttl; // TTL for a message (millisec), default -1 (no TTL limitation)
869 int inorder; // Whether a message is allowed to supersede partially lost one. Unused in stream and live mode.
870 int boundary; // 0:mid pkt, 1(01b):end of frame, 2(11b):complete frame, 3(10b): start of frame
871 int64_t srctime; // source time since epoch (usec), 0: use internal time (sender)
872 int32_t pktseq; // sequence number of the first packet in received message (unused for sending)
873 int32_t msgno; // message number (output value for both sending and receiving)
874 SRT_SOCKGROUPDATA* grpdata;
875 size_t grpdata_size;
876 } SRT_MSGCTRL;
877
878 // Trap representation for sequence and message numbers
879 // This value means that this is "unset", and it's never
880 // a result of an operation made on this number.
881 static const int32_t SRT_SEQNO_NONE = -1; // -1: no seq (0 is a valid seqno!)
882 static const int32_t SRT_MSGNO_NONE = -1; // -1: unset
883 static const int32_t SRT_MSGNO_CONTROL = 0; // 0: control (used by packet filter)
884
885 static const int SRT_MSGTTL_INF = -1; // unlimited TTL specification for message TTL
886
887 // XXX Might be useful also other special uses of -1:
888 // - -1 as infinity for srt_epoll_wait
889 // - -1 as a trap index value used in list.cpp
890
891 // You are free to use either of these two methods to set SRT_MSGCTRL object
892 // to default values: either call srt_msgctrl_init(&obj) or obj = srt_msgctrl_default.
893 SRT_API void srt_msgctrl_init(SRT_MSGCTRL* mctrl);
894 SRT_API extern const SRT_MSGCTRL srt_msgctrl_default;
895
896 // The send/receive functions.
897 // These functions have different names due to different sets of parameters
898 // to be supplied. Not all of them are needed or make sense in all modes:
899
900 // Plain: supply only the buffer and its size.
901 // Msg: supply additionally
902 // - TTL (message is not delivered when exceeded) and
903 // - INORDER (when false, the message is allowed to be delivered in different
904 // order than when it was sent, when the later message is earlier ready to
905 // deliver)
906 // Msg2: Supply extra parameters in SRT_MSGCTRL. When receiving, these
907 // parameters will be filled, as needed. NULL is acceptable, in which case
908 // the defaults are used.
909
910 //
911 // Sending functions
912 //
913 SRT_API int srt_send (SRTSOCKET u, const char* buf, int len);
914 SRT_API int srt_sendmsg (SRTSOCKET u, const char* buf, int len, int ttl/* = -1*/, int inorder/* = false*/);
915 SRT_API int srt_sendmsg2(SRTSOCKET u, const char* buf, int len, SRT_MSGCTRL *mctrl);
916
917 //
918 // Receiving functions
919 //
920 SRT_API int srt_recv (SRTSOCKET u, char* buf, int len);
921
922 // srt_recvmsg is actually an alias to srt_recv, it stays under the old name for compat reasons.
923 SRT_API int srt_recvmsg (SRTSOCKET u, char* buf, int len);
924 SRT_API int srt_recvmsg2(SRTSOCKET u, char *buf, int len, SRT_MSGCTRL *mctrl);
925
926
927 // Special send/receive functions for files only.
928 #define SRT_DEFAULT_SENDFILE_BLOCK 364000
929 #define SRT_DEFAULT_RECVFILE_BLOCK 7280000
930 SRT_API int64_t srt_sendfile(SRTSOCKET u, const char* path, int64_t* offset, int64_t size, int block);
931 SRT_API int64_t srt_recvfile(SRTSOCKET u, const char* path, int64_t* offset, int64_t size, int block);
932
933
934 // last error detection
935 SRT_API const char* srt_getlasterror_str(void);
936 SRT_API int srt_getlasterror(int* errno_loc);
937 SRT_API const char* srt_strerror(int code, int errnoval);
938 SRT_API void srt_clearlasterror(void);
939
940 // Performance tracking
941 // Performance monitor with Byte counters for better bitrate estimation.
942 SRT_API int srt_bstats(SRTSOCKET u, SRT_TRACEBSTATS * perf, int clear);
943 // Performance monitor with Byte counters and instantaneous stats instead of moving averages for Snd/Rcvbuffer sizes.
944 SRT_API int srt_bistats(SRTSOCKET u, SRT_TRACEBSTATS * perf, int clear, int instantaneous);
945
946 // Socket Status (for problem tracking)
947 SRT_API SRT_SOCKSTATUS srt_getsockstate(SRTSOCKET u);
948
949 SRT_API int srt_epoll_create(void);
950 SRT_API int srt_epoll_clear_usocks(int eid);
951 SRT_API int srt_epoll_add_usock(int eid, SRTSOCKET u, const int* events);
952 SRT_API int srt_epoll_add_ssock(int eid, SYSSOCKET s, const int* events);
953 SRT_API int srt_epoll_remove_usock(int eid, SRTSOCKET u);
954 SRT_API int srt_epoll_remove_ssock(int eid, SYSSOCKET s);
955 SRT_API int srt_epoll_update_usock(int eid, SRTSOCKET u, const int* events);
956 SRT_API int srt_epoll_update_ssock(int eid, SYSSOCKET s, const int* events);
957
958 SRT_API int srt_epoll_wait(int eid, SRTSOCKET* readfds, int* rnum, SRTSOCKET* writefds, int* wnum, int64_t msTimeOut,
959 SYSSOCKET* lrfds, int* lrnum, SYSSOCKET* lwfds, int* lwnum);
960 typedef struct SRT_EPOLL_EVENT_STR
961 {
962 SRTSOCKET fd;
963 int events; // SRT_EPOLL_IN | SRT_EPOLL_OUT | SRT_EPOLL_ERR
964 #ifdef __cplusplus
SRT_EPOLL_EVENT_STRSRT_EPOLL_EVENT_STR965 SRT_EPOLL_EVENT_STR(SRTSOCKET s, int ev): fd(s), events(ev) {}
SRT_EPOLL_EVENT_STRSRT_EPOLL_EVENT_STR966 SRT_EPOLL_EVENT_STR(): fd(-1), events(0) {} // NOTE: allows singular values, no init.
967 #endif
968 } SRT_EPOLL_EVENT;
969 SRT_API int srt_epoll_uwait(int eid, SRT_EPOLL_EVENT* fdsSet, int fdsSize, int64_t msTimeOut);
970
971 SRT_API int32_t srt_epoll_set(int eid, int32_t flags);
972 SRT_API int srt_epoll_release(int eid);
973
974 // Logging control
975
976 SRT_API void srt_setloglevel(int ll);
977 SRT_API void srt_addlogfa(int fa);
978 SRT_API void srt_dellogfa(int fa);
979 SRT_API void srt_resetlogfa(const int* fara, size_t fara_size);
980 // This isn't predicted, will be only available in SRT C++ API.
981 // For the time being, until this API is ready, use UDT::setlogstream.
982 // SRT_API void srt_setlogstream(std::ostream& stream);
983 SRT_API void srt_setloghandler(void* opaque, SRT_LOG_HANDLER_FN* handler);
984 SRT_API void srt_setlogflags(int flags);
985
986
987 SRT_API int srt_getsndbuffer(SRTSOCKET sock, size_t* blocks, size_t* bytes);
988
989 SRT_API int srt_getrejectreason(SRTSOCKET sock);
990 SRT_API int srt_setrejectreason(SRTSOCKET sock, int value);
991 SRT_API extern const char* const srt_rejectreason_msg [];
992 SRT_API const char* srt_rejectreason_str(int id);
993
994 SRT_API uint32_t srt_getversion(void);
995
996 SRT_API int64_t srt_time_now(void);
997
998 SRT_API int64_t srt_connection_time(SRTSOCKET sock);
999
1000 // Possible internal clock types
1001 #define SRT_SYNC_CLOCK_STDCXX_STEADY 0 // C++11 std::chrono::steady_clock
1002 #define SRT_SYNC_CLOCK_GETTIME_MONOTONIC 1 // clock_gettime with CLOCK_MONOTONIC
1003 #define SRT_SYNC_CLOCK_WINQPC 2
1004 #define SRT_SYNC_CLOCK_MACH_ABSTIME 3
1005 #define SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY 4
1006 #define SRT_SYNC_CLOCK_AMD64_RDTSC 5
1007 #define SRT_SYNC_CLOCK_IA32_RDTSC 6
1008 #define SRT_SYNC_CLOCK_IA64_ITC 7
1009
1010 SRT_API int srt_clock_type(void);
1011
1012 #ifdef __cplusplus
1013 }
1014 #endif
1015
1016 #endif
1017