<pclass="level0">This function receives raw data from the established connection. You may use it together with <aclass="emphasis"href="./curl_easy_send.html">curl_easy_send(3)</a> to implement custom protocols using libcurl. This functionality can be particularly useful if you use proxies and/or SSL encryption: libcurl will take care of proxy negotiation and connection set-up.
<pclass="level0"><spanClass="bold">buffer</span> is a pointer to your buffer that will get the received data. <spanClass="bold">buflen</span> is the maximum amount of data you can get in that buffer. The variable <spanClass="bold">n</span> points to will receive the number of received bytes.
<pclass="level0">To establish the connection, set <spanClass="bold">CURLOPT_CONNECT_ONLY</span> option before calling <aclass="emphasis"href="./curl_easy_perform.html">curl_easy_perform(3)</a>. Note that <aclass="emphasis"href="./curl_easy_recv.html">curl_easy_recv(3)</a> does not work on connections that were created without this option.
<pclass="level0">You must ensure that the socket has data to read before calling <aclass="emphasis"href="./curl_easy_recv.html">curl_easy_recv(3)</a>, otherwise the call will return <spanClass="bold">CURLE_AGAIN</span> - the socket is used in non-blocking mode internally. Use <aclass="emphasis"href="./curl_easy_getinfo.html">curl_easy_getinfo(3)</a> with <spanClass="bold">CURLINFO_LASTSOCKET</span> to obtain the socket; use your operating system facilities like <spanClass="emphasis">select(2)</span> to check if it has any data you can read. <aname="AVAILABILITY"></a><h2class="nroffsh">AVAILABILITY</h2>
<pclass="level0">Added in 7.18.2. <aname="RETURN"></a><h2class="nroffsh">RETURN VALUE</h2>
<pclass="level0">On success, returns <spanClass="bold">CURLE_OK</span>, stores the received data into <spanClass="bold">buffer</span>, and the number of bytes it actually read into <spanClass="bold">*n</span>.
<pclass="level0">On failure, returns the appropriate error code.
<pclass="level0">If there is no data to read, the function returns <spanClass="bold">CURLE_AGAIN</span>. Use your operating system facilities to wait until the data is ready, and retry. <aname="EXAMPLE"></a><h2class="nroffsh">EXAMPLE</h2>
<pclass="level0">See <spanClass="bold">sendrecv.c</span> in <spanClass="bold">docs/examples</span> directory for usage example. <aname="SEE"></a><h2class="nroffsh">SEE ALSO</h2>