UDT Reference: CUDT Methods

sendfile

The sendfile method sends out a file stream.

int sendfile(
   ifstream& ifs,

   const long long& offset,

   const long long& size
);

Parameters

ifs
[in] The input file stream from which the data will be read and sent.
 
offset
[in] The position from where data will be sent.
size
[in] The total length of data to be sent.

Return Values

Actual size of data sent.

Exceptions

A CUDTException exception can be threw out if the UDT entity is not connected or the connection has been broken, or any file stream exception arises for ifs. Specially, if size is greater than the actual file size, exceptions will arise. Application should be responsible to check the file size.

Description

The sendfile method sends data from a file stream. To send a whole file, simply set the offset to 0, and the size to the actual file size.

The data sending and receiving are orthogonal, i.e., the peer side can use either recv or recvfile to receive data, no matter send or sendfile is used at the other side.

sendfile is always in blocking mode. The UDT_SNDSYN option only affects send.

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

Notes

The long long type parameters of offset and size are actually 64 bit integers. They are defined as __int64 in the implementation, and __int64 is defined as long long on most of systems. See migration guide for detail. Similarly, all int type parameter are actually 32 bit integers, which is defined as __int32 in the source codes.

Examples

The following codes show how to send a whole file to the remote node using UDT:

CUDT udt;

...

 

ifstream& ifs("largefile.dat");

ifs.seekg(0, ios::end);

int size = ifs.tellg();

ifs.seekg(0, ios::beg);

 

try

{

   sender->sendfile(ifs, 0, size);

}

catch (CUDTException e)

{

   // process error...

}

See Also

send, recv, recvfile