UDT Tutorial |
UDT supports both blocking and non-blocking IO, in traditional (same as socket API) or overlapped way.
A blocking UDT send call will be blocked until there is enough buffer in the sending queue. The user buffer is copied into the protocol buffer. If multiple send calls are used in multi-thread applications, all calls will be blocked and released one by one as the buffers in the waiting queue are sent out. However, the release order is NOT guaranteed by UDT, but depends on the thread mechanism on specific operating systems.
In overlapped sending, UDT does NOT copy the user data into the memory, but send the data directly into the network. The sending will not return until all data has been successfully received.
void DeleteBuf(char* buf, int) {delete [] buf;} ...
// blocking sending
if (UDT::ERROR == UDT::send(usock, buffer,
size, 0))
// blocking overlapped sending
if (UDT::ERROR == UDT::send(usock, buffer,
size, 0, &handle, DeleteBuf)) |
In the traditional blocking receiving, a UDT recv call is blocked until there is any data available for reading in the UDT protocol buffer. The data is copied from the protocol buffer into the user buffer.
In overlapped receiving, the user buffer is linked onto the protocol buffer and new data will be written directly into the user buffer. Thus, the recv call will not return until the buffer is fulfilled. Note that this receiving mode may block infinitely until the desired amount of data is received or the connection is broken.
Non-blocking sending will return immediately no matter if the sending succeed or not. A successful sending copies the user data into the protocol buffer, which will be sent out in background.
Overlapped non-blocking sending does not copy user buffer into the protocol buffer, and does not wait the sending to complete. A function pointer may be passed as parameter so that the user parameter can be automatically processed (e.g., release). In this mode, the buffer cannot be touched until the sending is completed. To test if a certain non-blocking sending is completed, use getoverlappedresult.
It may be necessary to use non-blocking sending together with select call.
Non-blocking receiving will return immediately with any available data no more than the size appointed in the parameter.
In overlapped mode, non-blocking receiving will not return any data to the user, instead, it process the user buffer using the function in the parameter after the user buffer is fulfilled.
Note that at most one non-blocking overlapped receiving is allowed in the current implementation.