UDT Reference

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. Do NOT change this unless you know what you are doing. Must change this before modifying the buffer sizes.
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).
UDT_STATE | int32_t | Current status of the UDT socket. | Read only.
UDT_EVENT | int32_t | The EPOLL events available to this socket. | Read only.
UDT_SNDDATA | int32_t | Size of pending data in the sending buffer. | Read only.
UDT_RCVDATA | int32_t | Size of data available to read, in the receiving buffer. | Read only.

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