curl_easy_recv

Syntax

#include <curl/curl.h>

CURLcode curl_easy_recv( CURL * curl , void * buffer , size_t buflen , size_t * n ); 

Parameters

curl Handle to a curl session.
buffer Pointer to a buffer that the data will be received into.
buflen Length of the buffer.
n Pointer to the number of received bytes.

Return Values

On success, returns CURLE_OK, stores the received data into buffer, and the number of bytes it read into n. On failure, returns the appropriate error code. If there is no data to read, the function returns CURLE_AGAIN. Use available operating system facilities to wait until the data is ready and then retry.

Description

This function receives raw data from the established connection. Use it together with curl_easy_send to implement custom protocols using libcurl. This functionality can be useful when using proxies and/or SSL encryption: libcurl will take care of proxy negotiation and connection setup.

buffer is a pointer to the buffer that will get the received data. buflen is the maximum amount of data available in that buffer. The variable n points to receives the number of received bytes.

To establish the connection, set CURLOPT_CONNECT_ONLY option before calling curl_easy_perform.

NOTE:
curl_easy_recv does not function on connections that were created without this option.

Ensure that the socket has data to read before calling curl_easy_recv, otherwise the call will return CURLE_AGAIN - the socket is used in non-blocking mode internally. Use curl_easy_getinfo with CURLINFO_LASTSOCKET to obtain the socket; use available operating system facilities, such as select, to check if there is any data that can be read.

Do Not Call From

None.

See Also

HTTP Client Library (libcurl)
libcurl API Functions
libcurl Error Codes
curl_easy_setopt
curl_easy_perform
curl_easy_getinfo
curl_easy_send

Revision History

2013/09/18 Conversion
2013/05/08 Automated cleanup pass.
2012/05/04 Initial version.


CONFIDENTIAL