aboutsummaryrefslogtreecommitdiff
path: root/doc/socket.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/socket.html')
-rw-r--r--doc/socket.html117
1 files changed, 115 insertions, 2 deletions
diff --git a/doc/socket.html b/doc/socket.html
index 9372648..bde882b 100644
--- a/doc/socket.html
+++ b/doc/socket.html
@@ -33,7 +33,7 @@
33 33
34<!-- socket +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 34<!-- socket +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
35 35
36<h2 id=socket>The LuaSocket namespace</h2> 36<h2 id=socket>The socket namespace</h2>
37 37
38<p> 38<p>
39The <tt>socket</tt> namespace contains the namespace tables for all 39The <tt>socket</tt> namespace contains the namespace tables for all
@@ -74,7 +74,120 @@ The function an equivalent function that instead of throwing exceptoins,
74returns <tt><b>nil</b></tt> followed by an error message. 74returns <tt><b>nil</b></tt> followed by an error message.
75</p> 75</p>
76 76
77<!-- toip +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 77<!-- select +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
78
79<p class=name id=select>
80socket.<b>select(</b>recvt, sendt [, timeout]<b>)</b>
81</p>
82
83<p class=description>
84Waits for a number of sockets to change status.
85</p>
86
87<p class=parameters>
88<tt>Recvt</tt> is an array with the sockets to test for characters
89available for reading. Sockets in the <tt>sendt</tt> array are watched to
90see if it is OK to immediately write on them. <tt>Timeout</tt> is the
91maximum amount of time (in seconds) to wait for a change in status. A
92<tt><b>nil</b></tt>, negative or omitted <tt>timeout</tt> value allows the
93function to block indefinitely. <tt>Recvt</tt> and <tt>sendt</tt> can also
94be empty tables or <tt><b>nil</b></tt>. Non-socket values in the arrays
95will be silently ignored.
96</p>
97
98<p class=return> The function returns a table with the sockets ready for
99reading, a table with the sockets ready for writing and an error message.
100The error message is "<tt>timeout</tt>" if a timeout condition was met and
101<tt><b>nil</b></tt> otherwise. The returned tables are associative, to
102simplify the test if a specific socket has changed status.
103</p>
104
105<p class=note>
106<b>Important Note</b>: a known bug in WinSock causes <tt>select</tt> to fail
107on non-blocking TCP sockets. The function may return a socket as
108writable even though the socket is <em>not</em> ready for sending.
109</p>
110
111<p class=note>
112<b>Important note</b>: calling select with a server socket in the receive
113parameter before a call to accept does <em>not</em> guarantee
114<a href=tcp.html#accept><tt>accept</tt></a> will return immediately.
115Use the <a href=tcp.html#timeout><tt>timeout</tt></a>
116method or <tt>accept</tt> might block forever.
117</p>
118
119<p class=note>
120Interesting note: as mentioned in some manuals, calling select with both
121sets empty and a non-null timeout is a fairly portable way to sleep with
122sub-second precision.
123</p>
124
125
126<!-- sink ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
127
128<p class=name id=sink>
129socket.<b>sink(</b>mode, socket<b>)</b>
130</p>
131
132<p class=description>
133Creates an
134<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN012</a>
135sink from a stream socket object.
136</p>
137
138<p class=parameters>
139<tt>Mode</tt> defines the behaviour of the sink. The following
140options are available:
141</p>
142<ul>
143<li> <tt>"http-chunked"</tt>: sends data through socket after applying the
144<em>chunked transfer coding</em>, closing the socket when done;
145<li> <tt>"close-when-done"</tt>: sends all received data through the
146socket, closing the socket when done;
147<li> <tt>"keep-open"</tt>: sends all received data through the
148socket, leaving it open when done.
149</ul>
150<p>
151<tt>Socket</tt> is the stream socket object used to send the data.
152</p>
153
154<p class=return>
155The function returns a sink with the appropriate behavior.
156</p>
157
158<!-- source +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
159
160<p class=name id=source>
161socket.<b>source(</b>mode, socket [, length]<b>)</b>
162</p>
163
164<p class=description>
165Creates an
166<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN012</a>
167source from a stream socket object.
168</p>
169
170<p class=parameters>
171<tt>Mode</tt> defines the behaviour of the source. The following
172options are available:
173</p>
174<ul>
175<li> <tt>"http-chunked"</tt>: receives data from socket and removes the
176<em>chunked transfer coding</em> before returning the data;
177<li> <tt>"by-length"</tt>: receives a fixed number of bytes from the
178socket. This mode requires the extra argument <tt>length</tt>;
179<li> <tt>"until-closed"</tt>: receives data from a socket until the other
180side closes the connection.
181</ul>
182<p>
183<tt>Socket</tt> is the stream socket object used to receive the data.
184</p>
185
186<p class=return>
187The function returns a source with the appropriate behavior.
188</p>
189
190<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
78 191
79<p class=name id=try> 192<p class=name id=try>
80socket.<b>try(</b>ret<sub>1</sub>, ret<sub>2</sub> ... ret<sub>N</sub><b>)</b> 193socket.<b>try(</b>ret<sub>1</sub>, ret<sub>2</sub> ... ret<sub>N</sub><b>)</b>