As Ecore_Con works on an event driven design, as data arrives, events will be produced containing the data that arrived. It is up to the user of Ecore_Con to either parse as they go, append to a file to later parse the whole file in one go, or append to memory to parse or handle later.
To help with this Eina has some handy API's. The Eina_Binbuf and Eina_Strbuf APIs, abstract dynamic buffer management and make it trivial to handle buffers at runtime, without having to manage them. Eina_Binbuf makes it possible to create, expand, reset and slice a blob of memory - all via API. No system calls, no pointer manipulations and no size calculation.
Additional functions include adding content at specified byte positions in the buffer, escaping the inputs, find and replace strings. This provides extreme flexibility to play around, with a dynamic blob of memory.
It is good to free it (using eina_binbuf_free()) after using it.
Eina_Binbuf compliments Ecore_Con use cases, where dynamic sizes of data arrive from the network (think http download in chunks). Using Eina_Binbuf provides enough flexibility to handle data as it arrives and to defer its processing until desired, without having to think about where to store the temporary data and how to manage its size.
An example of how to use these with Ecore_Con follows.
#include <Ecore.h>
#include <Ecore_Con.h>
data_callback(void *data, int type, void *event)
{
{
fprintf(stderr,
"Appended %d \n", url_data->
size);
}
}
completion_callback(void *data, int type, void *event)
{
printf(
"download completed with status code: %d\n", url_complete->
status);
fprintf(stderr, "Size of data = %d bytes\n", size);
int fd = open("./elm.png", O_CREAT);
write(fd, ptr, size);
close(fd);
}
int
main(int argc, char **argv)
{
const char *url = "http://www.enlightenment.org/p/index/d/logo.png";
completion_callback,
data);
data_callback,
data);
return 0;
}
unsigned char data[1]
the data received on this event
Definition: Ecore_Con.h:601
EAPI int ECORE_CON_EVENT_URL_COMPLETE
A URL object has completed its transfer to and from the server and can be reused.
Definition: ecore_con_url.c:30
EAPI void eina_binbuf_free(Eina_Binbuf *buf) EINA_ARG_NONNULL(1)
Frees a string buffer.
void ecore_main_loop_quit(void)
Quits the main loop once all the events currently on the queue have been processed.
Definition: ecore_main.c:1300
Definition: Ecore_Con.h:610
struct _Ecore_Con_Url Ecore_Con_Url
Definition: Ecore_Con.h:347
Ecore_Event_Handler * ecore_event_handler_add(int type, Ecore_Event_Handler_Cb func, const void *data)
Adds an event handler.
Definition: ecore_events.c:13
EAPI int ECORE_CON_EVENT_URL_DATA
A URL object has data.
Definition: ecore_con_url.c:29
int size
the size of the current received data (in bytes)
Definition: Ecore_Con.h:600
EAPI Eina_Bool eina_binbuf_append_length(Eina_Binbuf *buf, const unsigned char *str, size_t length) EINA_ARG_NONNULL(1
Appends a string of exact length to a buffer, reallocating as necessary.
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1290
EAPI Ecore_Con_Url * ecore_con_url_new(const char *url)
Creates and initializes a new Ecore_Con_Url connection object.
Definition: ecore_con_url.c:784
#define EINA_TRUE
Definition: eina_types.h:539
unsigned char Eina_Bool
Definition: eina_types.h:527
EAPI const unsigned char * eina_binbuf_string_get(const Eina_Binbuf *buf) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT
Retrieves a pointer to the contents of a string buffer.
EAPI int ecore_con_url_init(void)
Initializes the Ecore_Con_Url library.
Definition: ecore_con_url.c:45
EAPI int ecore_con_init(void)
Initializes the Ecore_Con library.
Definition: ecore_con.c:72
EAPI Eina_Bool ecore_con_url_get(Ecore_Con_Url *url_con)
Sends a get request.
Definition: ecore_con_url.c:864
EAPI Eina_Binbuf * eina_binbuf_new(void) EINA_MALLOC EINA_WARN_UNUSED_RESULT
Creates a new binary string buffer.
Definition: Ecore_Con.h:598
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:229
EAPI size_t eina_binbuf_length_get(const Eina_Binbuf *buf) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT
Retrieves the length of the string buffer's content.
Definition: eina_strbuf_common.h:15
int status
HTTP status code of the operation (200, 404, 401, etc.)
Definition: Ecore_Con.h:612