\doxysubsection{scoop.\+c File Reference}
\label{scoop_8c}\index{scoop.c@{scoop.c}}


This file deals with readahead from caller-\/supplied buffers.  


Include dependency graph for scoop.\+c\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{scoop_8c__incl}
\end{center}
\end{figure}
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
static void \mbox{\hyperlink{scoop_8c_a8ae53f7e4fef0f68a2308d26767ddbdc}{rs\+\_\+scoop\+\_\+input}} (\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$job, size\+\_\+t len)
\begin{DoxyCompactList}\small\item\em Try to accept a from the input buffer to get LEN bytes in the scoop. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{scoop_8c_aad3e63ccd707266363d6feeca754a370}{rs\+\_\+scoop\+\_\+advance}} (\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$job, size\+\_\+t len)
\begin{DoxyCompactList}\small\item\em Advance the input cursor forward {\ttfamily len} bytes. \end{DoxyCompactList}\item 
\mbox{\hyperlink{librsync_8h_a7feb858ceba3b8f3cf048d49be108253}{rs\+\_\+result}} \mbox{\hyperlink{scoop_8c_a026b9505478d48f4b9b05fea46c166e1}{rs\+\_\+scoop\+\_\+readahead}} (\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$job, size\+\_\+t len, void $\ast$$\ast$ptr)
\begin{DoxyCompactList}\small\item\em Read from scoop without advancing. \end{DoxyCompactList}\item 
\mbox{\hyperlink{librsync_8h_a7feb858ceba3b8f3cf048d49be108253}{rs\+\_\+result}} \mbox{\hyperlink{scoop_8c_a9eb894edc12cd2972a1eb020bdc80725}{rs\+\_\+scoop\+\_\+read}} (\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$job, size\+\_\+t len, void $\ast$$\ast$ptr)
\begin{DoxyCompactList}\small\item\em Read LEN bytes if possible, and remove them from the input scoop. \end{DoxyCompactList}\item 
\mbox{\hyperlink{librsync_8h_a7feb858ceba3b8f3cf048d49be108253}{rs\+\_\+result}} \mbox{\hyperlink{scoop_8c_af9c1b8a80bbed23d9409559fa101496b}{rs\+\_\+scoop\+\_\+read\+\_\+rest}} (\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$job, size\+\_\+t $\ast$len, void $\ast$$\ast$ptr)
\begin{DoxyCompactList}\small\item\em Read whatever data remains in the input stream. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsubsection{Detailed Description}
This file deals with readahead from caller-\/supplied buffers. 

Many functions require a certain minimum amount of contiguous input data to do their processing. For example, to calculate a strong checksum of a block we need at least a block of input.

Since we put the buffers completely under the control of the caller, we can\textquotesingle{}t count on ever getting this much data all in one go. We can\textquotesingle{}t simply wait, because the caller might have a smaller buffer than we require and so we\textquotesingle{}ll never get it.

Stream input data is used directly if there is sufficient data to satisfy the readhead requests, otherwise it is copied and accumulated into an internal buffer until there is enough. This means for large input buffers we can leave a \char`\"{}tail\char`\"{} of unprocessed data in the input buffer, and only consume all the data if it was too small and start accumulating into the internal buffer. Provided the input buffers always have enough data we avoid copying into the internal buffer at all.

\begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000014}{Todo}}]We probably know a maximum amount of data that can be scooped up, so we could just avoid dynamic allocation. However that can\textquotesingle{}t be fixed at compile time, because when generating a delta it needs to be large enough to hold one full block. Perhaps we can set it up when the job is allocated? It would be kind of nice to not do any memory allocation after startup, as bzlib does this. \end{DoxyRefDesc}


Definition in file \mbox{\hyperlink{scoop_8c_source}{scoop.\+c}}.



\doxysubsubsection{Function Documentation}
\mbox{\label{scoop_8c_a8ae53f7e4fef0f68a2308d26767ddbdc}} 
\index{scoop.c@{scoop.c}!rs\_scoop\_input@{rs\_scoop\_input}}
\index{rs\_scoop\_input@{rs\_scoop\_input}!scoop.c@{scoop.c}}
\doxyparagraph{\texorpdfstring{rs\_scoop\_input()}{rs\_scoop\_input()}}
{\footnotesize\ttfamily static void rs\+\_\+scoop\+\_\+input (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$}]{job,  }\item[{size\+\_\+t}]{len }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



Try to accept a from the input buffer to get LEN bytes in the scoop. 



Definition at line \mbox{\hyperlink{scoop_8c_source_l00066}{66}} of file \mbox{\hyperlink{scoop_8c_source}{scoop.\+c}}.

\mbox{\label{scoop_8c_aad3e63ccd707266363d6feeca754a370}} 
\index{scoop.c@{scoop.c}!rs\_scoop\_advance@{rs\_scoop\_advance}}
\index{rs\_scoop\_advance@{rs\_scoop\_advance}!scoop.c@{scoop.c}}
\doxyparagraph{\texorpdfstring{rs\_scoop\_advance()}{rs\_scoop\_advance()}}
{\footnotesize\ttfamily void rs\+\_\+scoop\+\_\+advance (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$}]{job,  }\item[{size\+\_\+t}]{len }\end{DoxyParamCaption})}



Advance the input cursor forward {\ttfamily len} bytes. 

This is used after doing readahead, when you decide you want to keep it. {\ttfamily len} must be no more than the amount of available data, so you can\textquotesingle{}t cheat.

So when creating a delta, we require one block of readahead. But after examining that block, we might decide to advance over all of it (if there is a match), or just one byte (if not). 

Definition at line \mbox{\hyperlink{scoop_8c_source_l00117}{117}} of file \mbox{\hyperlink{scoop_8c_source}{scoop.\+c}}.

\mbox{\label{scoop_8c_a026b9505478d48f4b9b05fea46c166e1}} 
\index{scoop.c@{scoop.c}!rs\_scoop\_readahead@{rs\_scoop\_readahead}}
\index{rs\_scoop\_readahead@{rs\_scoop\_readahead}!scoop.c@{scoop.c}}
\doxyparagraph{\texorpdfstring{rs\_scoop\_readahead()}{rs\_scoop\_readahead()}}
{\footnotesize\ttfamily \mbox{\hyperlink{librsync_8h_a7feb858ceba3b8f3cf048d49be108253}{rs\+\_\+result}} rs\+\_\+scoop\+\_\+readahead (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$}]{job,  }\item[{size\+\_\+t}]{len,  }\item[{void $\ast$$\ast$}]{ptr }\end{DoxyParamCaption})}



Read from scoop without advancing. 

Ask for LEN bytes of input from the stream. If that much data is available, then return a pointer to it in PTR, advance the stream input pointer over the data, and return RS\+\_\+\+DONE. If there\textquotesingle{}s not enough data, then accept whatever is there into a buffer, advance over it, and return RS\+\_\+\+BLOCKED.

The data is not actually removed from the input, so this function lets you do readahead. If you want to keep any of the data, you should also call \mbox{\hyperlink{scoop_8c_aad3e63ccd707266363d6feeca754a370}{rs\+\_\+scoop\+\_\+advance()}} to skip over it. 

Definition at line \mbox{\hyperlink{scoop_8c_source_l00148}{148}} of file \mbox{\hyperlink{scoop_8c_source}{scoop.\+c}}.

\mbox{\label{scoop_8c_a9eb894edc12cd2972a1eb020bdc80725}} 
\index{scoop.c@{scoop.c}!rs\_scoop\_read@{rs\_scoop\_read}}
\index{rs\_scoop\_read@{rs\_scoop\_read}!scoop.c@{scoop.c}}
\doxyparagraph{\texorpdfstring{rs\_scoop\_read()}{rs\_scoop\_read()}}
{\footnotesize\ttfamily \mbox{\hyperlink{librsync_8h_a7feb858ceba3b8f3cf048d49be108253}{rs\+\_\+result}} rs\+\_\+scoop\+\_\+read (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$}]{job,  }\item[{size\+\_\+t}]{len,  }\item[{void $\ast$$\ast$}]{ptr }\end{DoxyParamCaption})}



Read LEN bytes if possible, and remove them from the input scoop. 


\begin{DoxyParams}{Parameters}
{\em $\ast$job} & An rs\+\_\+job\+\_\+t pointer to the job instance.\\
\hline
{\em len} & The length of the data in the ptr buffer.\\
\hline
{\em $\ast$$\ast$ptr} & will be updated to point to a read-\/only buffer holding the data, if enough is available.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
RS\+\_\+\+DONE if there was enough data, RS\+\_\+\+BLOCKED if there was not enough data yet, or RS\+\_\+\+INPUT\+\_\+\+ENDED if there was not enough data and at EOF. 
\end{DoxyReturn}


Definition at line \mbox{\hyperlink{scoop_8c_source_l00192}{192}} of file \mbox{\hyperlink{scoop_8c_source}{scoop.\+c}}.

\mbox{\label{scoop_8c_af9c1b8a80bbed23d9409559fa101496b}} 
\index{scoop.c@{scoop.c}!rs\_scoop\_read\_rest@{rs\_scoop\_read\_rest}}
\index{rs\_scoop\_read\_rest@{rs\_scoop\_read\_rest}!scoop.c@{scoop.c}}
\doxyparagraph{\texorpdfstring{rs\_scoop\_read\_rest()}{rs\_scoop\_read\_rest()}}
{\footnotesize\ttfamily \mbox{\hyperlink{librsync_8h_a7feb858ceba3b8f3cf048d49be108253}{rs\+\_\+result}} rs\+\_\+scoop\+\_\+read\+\_\+rest (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{librsync_8h_add6622b38e3fa557301a190876d5ed4a}{rs\+\_\+job\+\_\+t}} $\ast$}]{job,  }\item[{size\+\_\+t $\ast$}]{len,  }\item[{void $\ast$$\ast$}]{ptr }\end{DoxyParamCaption})}



Read whatever data remains in the input stream. 


\begin{DoxyParams}{Parameters}
{\em $\ast$job} & The rs\+\_\+job\+\_\+t instance the job instance.\\
\hline
{\em $\ast$len} & will be updated to the length of the available data.\\
\hline
{\em $\ast$$\ast$ptr} & will point at the available data.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
RS\+\_\+\+DONE if there was data, RS\+\_\+\+INPUT\+\_\+\+ENDED if there was no data and at EOF, RS\+\_\+\+BLOCKED if there was no data and not at EOF. 
\end{DoxyReturn}


Definition at line \mbox{\hyperlink{scoop_8c_source_l00212}{212}} of file \mbox{\hyperlink{scoop_8c_source}{scoop.\+c}}.

