UDT Reference: CUDT Methods

send

The send method sends out an application buffer.

void send(
   char* data,

   const int& len
);

Parameters

data
[in] The pointer to the application data block to be sent.
len
[in] The length of the buffer.

Return Values

NONE.

Exceptions

A CUDTException exception can be threw out if the UDT entity is not connected or the connection has been broken.

Description

The send method returns immediately if the UDT_SNDSYN is set to true, otherwise it waits until all the data has been successfully received the the peer side.

If the UDT_MFLAG is set to 1, the buffer of data MUST not be modified thereafter. Current UDT implementation does not make any protection to the buffer to be sent.

Zero or negative value is allowed for len. In such situation, the method returns immediately.

Notes

The send method does NOT check the current memory usage situation. Special care should be done in the program if non-blocking sending mode is used, otherwise, the data sending can easily crash the host. For example, the piece of codes below is bad:

CUDT udt;

bool block = false;

udt.setOpt(UDT_SNDSYN, &block, sizeof(bool));

...

while (true)

{

   // Produce data here...

   ...

   udt.send(data, len)

};

If the data production speed is greater than the sending speed, the memory will be used up. The good codes should like:

while (true)

{

   // Produce data here...

   ...

   while (udt.getCurrSndBufSize() > 100000000) //Using a large value here, but not too large for the system memory

      usleep(10);

   udt.send(data, len)

};

See Also

listen, connect, open, getCurrSndBufSize