Name
easy:Recv -- receives raw data on an easy connection
Synopsis
data$, n = easy:Recv(len)
Function
This function receives raw data from the established connection. You may use it together with easy:Send() 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 get-up. You have to pass the number of bytes to receive in len.

To establish the connection, get #CURLOPT_CONNECT_ONLY option before calling easy:Perform() or multi:Perform(). Note that easy:Recv() does not work on connections that were created without this option.

The call will return -1 in n if there is no data to read - the socket is used in non-blocking mode internally. When -1 is returned, sleep for a few milliseconds to wait for data. You should sleep for a few seconds only if easy:Recv() returns -1 in n. The reason for this is libcurl or the SSL library may internally cache some data, therefore you should call easy:Recv() until all data is read which would include any cached data.

Furthermore, easy:Recv() may return -1 in n if the only data that was read was for internal SSL processing, and no other data is available.

Inputs
len
number of bytes to read
Results
data$
data read
n
number of bytes read

Show TOC