Name
easy:SetOpt_ReadFunction -- read callback for data uploads
Synopsis
easy:SetOpt_ReadFunction(read_callback[, userdata])
Function
Pass a callback function. This callback function gets called by libcurl as soon as it needs to read data in order to send it to the peer - like if you ask it to upload or post data to the server.

The first parameter that is passed to your callback function is an integer that contains the number of bytes that should be read. If you pass the optional userdata argument, the value you pass in userdata will be passed to your callback function as a second parameter. The userdata parameter can be of any type.

Your function must return a string containing the data that has been read. This may contain less bytes than requested but there must be at least one byte in the return string or the transfer will be aborted.

If you stop the current transfer by returning an empty string (i.e before the server expected it, like when you've said you will upload N bytes and you upload less than N bytes), you may experience that the server "hangs" waiting for the rest of the data that won't come.

The read callback may return #CURL_READFUNC_ABORT to stop the current operation immediately, resulting in a #CURLE_ABORTED_BY_CALLBACK error code from the transfer.

The callback can return #CURL_READFUNC_PAUSE to cause reading from this connection to pause. See easy:Pause() for further details.

Bugs: when doing TFTP uploads, you must return the exact amount of data that the callback wants, or it will be considered the final packet by the server end and the transfer will end there.

Inputs
read_callback
input value
userdata
optional: user data to pass to callback function
Example
Function p_ReadData(len)
   If readlen + len > totallen Then len = totallen - readlen
   If len > 0
      readlen = readlen + len
      Return(ReadBytes(1, len))
   Else
      Return("")
   EndIf
EndFunction
readlen = 0
totallen = FileLength(1)
e:SetOpt_ReadFunction(p_ReadData)
The code above installs a read function that will read all data from the file using the identifier 1.

Show TOC