UDT Reference: Functions

#### recvfile

The recvfile method reads certain amount of data into a local file.

int64_t recvfile(
UDTSOCKET u,
fstream& ofs,
int64_t& offset,
int64_t size,
int block = 366000
);

##### Parameters

u
  [in] Descriptor identifying a connected socket.
ofs
  [in] C++ fstream descriptor for the file to store incoming data.
offset
  [in, out] The offset position from where the data is written into the file; after the call returns, this value records the new offset of the write position.
size
  [in] The total size to be received.
block
  [in] Optional. The size of every data block for file IO.

##### Return Value

On success, recvfile returns the actual size of received data. Otherwise UDT::ERROR is returned and specific error information can be retrieved by getlasterror.

Error Name | Error Code | Comment
ECONNLOST | 2001 | connection has been broken and no data left in receiver buffer.
ENOCONN | 2002 | u is not connected.
EFILE | 4000 | File or disk system errors.
EINVSOCK | 5004 | u is not an valid socket.
EDGRAMILL | 5010 | cannot use recvfile in SOCK_DGRAM mode.

##### Description

The recvfile method reads certain amount of data and write it into a local file. It is always in blocking mode and neither UDT_RCVSYN nor UDT_RCVTIMEO affects this method. The actual size of data to expect must be known before calling recvfile, otherwise deadlock may occur due to insufficient incoming data.

##### See Also

send, sendfile, recv