\hypertarget{group__Ecore__Con__Buffer}{}\doxysection{Ecore Connection Buffering}
\label{group__Ecore__Con__Buffer}\index{Ecore Connection Buffering@{Ecore Connection Buffering}}


As Ecore\+\_\+\+Con works on an event driven design, as data arrives, events will be produced containing the data that arrived.  


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\textquotesingle{}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 \mbox{\hyperlink{group__Eina__Binary__Buffer__Group_ga9d4cb2aa16689f4388f082c18b0ac395}{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.


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Ecore.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Ecore\_Con.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{data\_callback(\textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{int}\ type,\ \textcolor{keywordtype}{void}\ *event)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Ecore__Con__Event__Url__Data}{Ecore\_Con\_Event\_Url\_Data}}\ *url\_data\ =\ event;}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (\ url\_data-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Data_a1d4725aa77f3875cc3405597a5fbff91}{size}}\ >\ 0)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{comment}{//\ append\ data\ as\ it\ arrives\ -\/\ don't\ worry\ where\ or\ how\ it\ gets\ stored.}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{comment}{//\ Also\ don't\ worry\ about\ size,\ expanding,\ reallocing\ etc.}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{comment}{//\ just\ keep\ appending\ -\/\ size\ is\ automatically\ handled.}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Eina__Binary__Buffer__Group_gafed8f157ce1542b0e92fc6668649af08}{eina\_binbuf\_append\_length}}(data,\ url\_data-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Data_aaa4c4dbc6575b071164f8152a7808268}{data}},\ url\_data-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Data_a1d4725aa77f3875cc3405597a5fbff91}{size}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Appended\ \%d\ \(\backslash\)n"{}},\ url\_data-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Data_a1d4725aa77f3875cc3405597a5fbff91}{size}});}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{completion\_callback(\textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{int}\ type,\ \textcolor{keywordtype}{void}\ *event)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Ecore__Con__Event__Url__Complete}{Ecore\_Con\_Event\_Url\_Complete}}\ *url\_complete\ =\ event;}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}download\ completed\ with\ status\ code:\ \%d\(\backslash\)n"{}},\ url\_complete-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Complete_ab842caa1615a911c3578e0dfeae5f773}{status}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{//\ get\ the\ data\ back\ from\ Eina\_Binbuf}}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ *ptr\ =\ \mbox{\hyperlink{group__Eina__Binary__Buffer__Group_ga3810a1ca5efb83920182575f7c4de9dc}{eina\_binbuf\_string\_get}}(data);}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{size\_t}\ size\ =\ \mbox{\hyperlink{group__Eina__Binary__Buffer__Group_ga70c8dfe71516ea732b4a168f658bcfb3}{eina\_binbuf\_length\_get}}(data);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{//\ process\ data\ as\ required\ (write\ to\ file)}}
\DoxyCodeLine{\ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Size\ of\ data\ =\ \%d\ bytes\(\backslash\)n"{}},\ size);}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ fd\ =\ open(\textcolor{stringliteral}{"{}./elm.png"{}},\ O\_CREAT);}
\DoxyCodeLine{\ \ \ write(fd,\ ptr,\ size);}
\DoxyCodeLine{\ \ \ close(fd);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{//\ free\ it\ when\ done.}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Binary__Buffer__Group_ga9d4cb2aa16689f4388f082c18b0ac395}{eina\_binbuf\_free}}(data);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}\ **argv)}
\DoxyCodeLine{\{}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *url\ =\ \textcolor{stringliteral}{"{}http://www.enlightenment.org/p/index/d/logo.png"{}};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}();}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga8a20f47372627a03e86a8705a6f8a82d}{ecore\_con\_init}}();}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga96388997453269f58bde7873811af6d5}{ecore\_con\_url\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{//\ This\ is\ single\ additional\ line\ to\ manage\ dynamic\ network\ data.}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__Strbuf}{Eina\_Binbuf}}\ *data\ =\ \mbox{\hyperlink{group__Eina__Binary__Buffer__Group_ga9cad59aa480e4b9daebe278507db4e5a}{eina\_binbuf\_new}}();}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Url__Group_gad928193ae403bd05c1ce5ba48a1d52ea}{Ecore\_Con\_Url}}\ *url\_con\ =\ \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga71cce8e67deb5ea13d5f62d67d51ad9b}{ecore\_con\_url\_new}}(url);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Event__Group_ga886c90c3f917f87b3b4c931adcbc41c5}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_gaa814f51fd5f97a92cdc76b624651d85a}{ECORE\_CON\_EVENT\_URL\_COMPLETE}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ completion\_callback,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ data);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Event__Group_ga886c90c3f917f87b3b4c931adcbc41c5}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga5affbb43768cd629c629d80afa2b5706}{ECORE\_CON\_EVENT\_URL\_DATA}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ data\_callback,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ data);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Url__Group_gaeb79adc8f07e54ad7a87a8c55de5ec72}{ecore\_con\_url\_get}}(url\_con);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}

\end{DoxyCode}
 