UDT Reference: Functions

getsockopt

setsockopt

The getsockopt and setsockopt methods read and set UDT options, respectively.

int getsockopt(
  UDTSOCKET u,
  int level,
  SOCKOPT optname,
  char* optval,
  int* optlen
);

int setsockopt(
  UDTSOCKET u,
  int level,
  SOCKOPT optname,
  const char* optval,
  int optlen
);
Parameters
u
[in] Descriptor identifying a UDT socket.
level
[in] Unused. For compatibility only.
optName
[in] The enum name of UDT option. The names and meanings are listed in the table below.
 
Name Type Meaning Comment
UDT_MSS int Maximum packet size (bytes). Including all UDT, UDP, and IP headers. Default 1500 bytes.
UDT_SNDSYN bool synchronization mode of data sending. true for blocking sending; false for non-blocking sending. Default true.
UDT_RCVSYN bool synchronization mode for receiving. true for blocking receiving; false for non-blocking receiving. Default true.
UDT_CC CCCFactory*
CCC**
user defined congestion control algorithm. optval is a pointer to a CCC Factory class instance (for setsockopt).
optval is a pointer of pointer to a CCC class instance (for getsockopt).
UDT_FC int Maximum window size (packets) Default 25600.
UDT_SNDBUF int UDT sender buffer size limit (bytes) Default 10MB (10240000).
UDT_RCVBUF int UDT receiver buffer size limit (bytes) Default 10MB (10240000).
UDP_SNDBUF int UDP socket sender buffer size (bytes) Default 1MB (1024000).
UDP_RCVBUF int UDP socket receiver buffer size (bytes) Default 1MB (1024000).
UDT_LINGER linger Linger time on close(). Default 180 seconds.
UDT_RENDEZVOUS bool Rendezvous connection setup. Default false (no rendezvous mode).
UDT_SNDTIMEO int sending call timeout (milliseconds). Default -1 (infinite).
UDT_RCVTIMEO int receiving call timeout (milliseconds). Default -1 (infinite).
UDT_REUSEADDR bool reuse an existing address or create a new one. Default true (reuse).
UDT_MAXBW int64_t maximum bandwidth that one single UDT connection can use (bytes per second). Default -1 (no upper limit).
optval
[in (set), out (get)] Pointer to the value of UDT option.
optlen
[in (set), in/out (get)] Pointer to the length of optval.
Return Value

On success, 0 is returned and proper UDT option is set or read; otherwise UDT::ERROR is returned and the specific error information can be retrieved using getlasterror.

Error Name Error Code Comment
EBOUNDSOCK 5001 the sepecific option cannot be set on a bound socket.
ECONNSOCK 5002 the specific option cannot be set on a connected socket.
EINVPARAM 5003 the option value or length is invalid.
EINVSOCK 5004 u is an invalid UDT socket.
Description

the setsockopt method sets the UDT option optName with the value of optval. The parameter of optlen is checked to verify the goodness of the option value. Not all options can be set at any state of UDT. In fact, most options must be set before bind or connect is called, because these values are necessary to initialize certain data structures when a UDT connection is created.

The getsockopt method reads the current option value. The value is written into the buffer pointed by optval and the length is returned in optlen.

Example
To send data sending in non-blocking mode, the code can be like:
UDTSOCKET u;
...
bool block = false;
UDT::setsockopt(u, 0, UDT_SNDSYN, &block, sizeof(bool));
See Also

Configure UDT Options