This is a simple example that shows how to download a file using Ecore_Con_Url.
The full source code for this example can be found at ecore_con_url_download_example.c.
First we are setting some callbacks for events that will be sent when data arrives in our connection (the data is the content of the file being downloaded), and when the download is completed. The _url_progress_cb
and _url_complete_cb
are these callbacks:
Notice that we also declared a struct that will hold how many bytes were downloaded through this object. It will be set in the main
function using ecore_con_url_data_set().
In the next step, on the main
function, we open a file where we are going to save the content being downloaded:
With the file successfully open, let's create our Ecore_Con_Url object. For this, we initialize the libraries and create the object:
Then we allocate and set the data struct to the connection object, and set a file descriptor from our previously open file to it. We also add the event handlers (callbacks) to the events that will be emitted on data being received and download complete:
Finally we start our request, and run the main loop:
The rest of this code was just freeing resources, with some labels to be used for error handling.