aboutsummaryrefslogtreecommitdiff
path: root/gem
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2007-10-13 23:55:20 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2007-10-13 23:55:20 +0000
commitd1a72435d5bd3528f3c334cd4d1da16dcead47bf (patch)
treeca6f092afee764923d747b0f0b6fd1ad2418cfae /gem
parent52ac60af8132ae7e42151d3012a9607d7cadaf95 (diff)
downloadluasocket-d1a72435d5bd3528f3c334cd4d1da16dcead47bf.tar.gz
luasocket-d1a72435d5bd3528f3c334cd4d1da16dcead47bf.tar.bz2
luasocket-d1a72435d5bd3528f3c334cd4d1da16dcead47bf.zip
New release.
Diffstat (limited to 'gem')
-rw-r--r--gem/TODO2
-rw-r--r--gem/ltn012.tex46
2 files changed, 23 insertions, 25 deletions
diff --git a/gem/TODO b/gem/TODO
deleted file mode 100644
index bdbe84e..0000000
--- a/gem/TODO
+++ /dev/null
@@ -1,2 +0,0 @@
1Talk a bout Wim
2Move thanks into the acknowledgement section.
diff --git a/gem/ltn012.tex b/gem/ltn012.tex
index 8eccd46..8027ecc 100644
--- a/gem/ltn012.tex
+++ b/gem/ltn012.tex
@@ -61,7 +61,7 @@ sinks, and pumps, which we introduce below.
61 61
62\emph{Filters} are functions that can be repeatedly invoked 62\emph{Filters} are functions that can be repeatedly invoked
63with chunks of input, successively returning processed 63with chunks of input, successively returning processed
64chunks of output. More importantly, the result of 64chunks of output. Naturally, the result of
65concatenating all the output chunks must be the same as the 65concatenating all the output chunks must be the same as the
66result of applying the filter to the concatenation of all 66result of applying the filter to the concatenation of all
67input chunks. In fancier language, filters \emph{commute} 67input chunks. In fancier language, filters \emph{commute}
@@ -81,11 +81,12 @@ which data will flow, potentially being transformed many
81times along the way. Chains connect these nodes together. 81times along the way. Chains connect these nodes together.
82The initial and final nodes of the network are 82The initial and final nodes of the network are
83\emph{sources} and \emph{sinks}, respectively. Less 83\emph{sources} and \emph{sinks}, respectively. Less
84abstractly, a source is a function that produces new data 84abstractly, a source is a function that produces new chunks
85every time it is invoked. Conversely, sinks are functions 85of data every time it is invoked. Conversely, sinks are
86that give a final destination to the data they receive. 86functions that give a final destination to the chunks of
87Naturally, sources and sinks can also be chained with 87data they receive in sucessive calls. Naturally, sources
88filters to produce filtered sources and sinks. 88and sinks can also be chained with filters to produce
89filtered sources and sinks.
89 90
90Finally, filters, chains, sources, and sinks are all passive 91Finally, filters, chains, sources, and sinks are all passive
91entities: they must be repeatedly invoked in order for 92entities: they must be repeatedly invoked in order for
@@ -95,8 +96,8 @@ sink, and indirectly through all intervening filters.
95 96
96In the following sections, we start with a simplified 97In the following sections, we start with a simplified
97interface, which we later refine. The evolution we present 98interface, which we later refine. The evolution we present
98is not contrived: it recreates the steps we followed 99is not contrived: it recreates the steps we ourselves
99ourselves as we consolidated our understanding of these 100followed as we consolidated our understanding of these
100concepts within our application domain. 101concepts within our application domain.
101 102
102\subsection{A simple example} 103\subsection{A simple example}
@@ -290,8 +291,8 @@ static int eol(lua_State *L) {
290\end{C} 291\end{C}
291\end{quote} 292\end{quote}
292 293
293When designing your own filters, the challenging part is to 294When designing filters, the challenging part is usually
294decide what will be in the context. For line breaking, for 295deciding what to store in the context. For line breaking, for
295instance, it could be the number of bytes that still fit in the 296instance, it could be the number of bytes that still fit in the
296current line. For Base64 encoding, it could be a string 297current line. For Base64 encoding, it could be a string
297with the bytes that remain after the division of the input 298with the bytes that remain after the division of the input
@@ -408,8 +409,8 @@ associated filter before returning it to the caller.
408Filtered sources are useful when working with 409Filtered sources are useful when working with
409functions that get their input data from a source (such as 410functions that get their input data from a source (such as
410the pumps in our examples). By chaining a source with one or 411the pumps in our examples). By chaining a source with one or
411more filters, the function can be transparently provided 412more filters, such functions can be transparently provided
412with filtered data, with no need to change its interface. 413with filtered data, with no need to change their interfaces.
413Here is a factory that does the job: 414Here is a factory that does the job:
414\begin{quote} 415\begin{quote}
415\begin{lua} 416\begin{lua}
@@ -434,11 +435,11 @@ end
434 435
435\subsection{Sinks} 436\subsection{Sinks}
436 437
437Just as we defined an interface for source of data, 438Just as we defined an interface for a source of data, we can
438we can also define an interface for a data destination. 439also define an interface for a data destination. We call
439We call any function respecting this 440any function respecting this interface a sink. In our first
440interface a \emph{sink}. In our first example, we used a 441example, we used a file sink connected to the standard
441file sink connected to the standard output. 442output.
442 443
443Sinks receive consecutive chunks of data, until the end of 444Sinks receive consecutive chunks of data, until the end of
444data is signaled by a \nil\ input chunk. A sink can be 445data is signaled by a \nil\ input chunk. A sink can be
@@ -665,7 +666,7 @@ SMTP dot-stuffing filter, connects a socket sink
665with the server, and simply pumps the data. The message is never 666with the server, and simply pumps the data. The message is never
666assembled in memory. Everything is produced on demand, 667assembled in memory. Everything is produced on demand,
667transformed in small pieces, and sent to the server in chunks, 668transformed in small pieces, and sent to the server in chunks,
668including the file attachment that is loaded from disk and 669including the file attachment which is loaded from disk and
669encoded on the fly. It just works. 670encoded on the fly. It just works.
670 671
671\section{Conclusions} 672\section{Conclusions}
@@ -685,11 +686,10 @@ components. Pumps simply push the data through.
685The concepts described in this text are the result of long 686The concepts described in this text are the result of long
686discussions with David Burgess. A version of this text has 687discussions with David Burgess. A version of this text has
687been released on-line as the Lua Technical Note 012, hence 688been released on-line as the Lua Technical Note 012, hence
688the name of the corresponding LuaSocket module, 689the name of the corresponding LuaSocket module, LTN12. Wim
689\texttt{ltn12}. Wim Couwenberg contributed to the 690Couwenberg contributed to the implementation of the module,
690implementation of the module, and Adrian Sietsma was the 691and Adrian Sietsma was the first to notice the
691first to notice the correspondence between sources and Lua 692correspondence between sources and Lua iterators.
692iterators.
693 693
694 694
695\end{document} 695\end{document}