UDT Reference: UDT Functions

send

The send method sends out an application buffer.

int send(
  UDTSOCKET u,             
  const char *buf
  int len,              
  int flags,

  int *handle = NULL,

  UDT_MEM_ROUTINE routine = NULL

  void* context = NULL           
);

Parameters

u
[in] Descriptor identifying a connected socket.
buf
[in] Buffer containing the data to be transmitted.
len
[in] Length of the data in buf.
flags
[in] Ignored. For compatibility use only.
handle
[out] Optional. An descriptor to this send call.
routine
[in] optional. Function used to process the buffer after the sending is finished.
context
[in] optional. Context parameter to be used in the buffer process routine.

Return Values

On success, the actual size of data sent is returned; Otherwise, UDT::ERROR is returned and the specific error information can be retrieved by getlasterror. When UDT_SNDTIMEO is set to a positive value, zero will be returned if no data is sent out before the assigned timer expires.

Error Code Comment

2001

connection broken before send is completed.

2002

u is not connected.

5003

invalid parameters.

5004

u is an invalid UDT socket.

5010

cannot use send in SOCK_DGRAM mode.

6001

insufficient buffer size for non-blocking sending.

Description

The send method's behavior depends on the sending blocking mode and overlapped IO.

In regular IO, with blocking mode, the send is blocked until there is enough buffer size in the UDT sender's buffer. On non-blocking IO, send will return immediately. UDT send either sends all the data specified by the length parameter or nothing. However, it is still recommended to use a loop to check the return value for future compatibilities.

In overlapped IO (when the handle parameter is given), a blocking sending waits until all data are sent out, whereas a non-blocking sending returns immediately and the data will be sent at background (if there is enough buffer). Once the data sending is completed, the function of routine will be executed on the data. Note that UDT does not duplicate the context parameter: it should remain valid until the routine is called, and it should be released (if necessary) by applications.

The progress the overlapped send can be queried by using getoverlappedresult.

See Also

select, recv, sendfile, recvfile, getoverlappedresult