aboutsummaryrefslogtreecommitdiff
path: root/doc/socket.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/socket.html')
-rw-r--r--doc/socket.html48
1 files changed, 46 insertions, 2 deletions
diff --git a/doc/socket.html b/doc/socket.html
index 06296a3..4d77478 100644
--- a/doc/socket.html
+++ b/doc/socket.html
@@ -60,6 +60,49 @@ This constant is set to <tt><b>true</b></tt> if the library was compiled
60with debug support. 60with debug support.
61</p> 61</p>
62 62
63<!-- newtry +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
64
65<p class=name id=newtry>
66socket.<b>newtry(</b>finalizer<b>)</b>
67</p>
68
69<p class=description>
70Creates and returns a <em>clean</em>
71<a href="#try"><tt>try</tt></a>
72function that allows for cleanup before the exception
73is raised.
74</p>
75
76<p class=parameters>
77<tt>Finalizer</tt> is a function that will be called before
78<tt>try</tt> throws the exception. It will be called
79in <em>protected</em> mode.
80</p>
81
82<p class=return>
83The function returns your customized <tt>try</tt> function.
84</p>
85
86<p class=note>
87Note: This idea saved a <em>lot</em> of work with the
88implementation of protocols in LuaSocket:
89</p>
90
91<pre class=example>
92foo = socket.protect(function()
93 -- connect somewhere
94 local c = socket.try(socket.connect("somewhere", 42))
95 -- create a try function that closes 'c' on error
96 local try = socket.newtry(function() c:close() end)
97 -- do everything reassured c will be closed
98 try(c:send("helo there?\r\n"))
99 local answer = try(c:receive())
100 ...
101 try(c:send("good bye\r\n"))
102 c:close()
103end)
104</pre>
105
63 106
64<!-- protect +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 107<!-- protect +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
65 108
@@ -209,7 +252,7 @@ Freezes the program execution during a given amount of time.
209 252
210<p class=parameters> 253<p class=parameters>
211<tt>Time</tt> is the number of seconds to sleep for. 254<tt>Time</tt> is the number of seconds to sleep for.
212The function truncates <tt>time</tt> to the nearest integer. 255The function truncates <tt>time</tt> down to the nearest integer.
213</p> 256</p>
214 257
215<!-- source +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 258<!-- source +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@@ -252,7 +295,8 @@ socket.<b>time()</b>
252 295
253<p class=description> 296<p class=description>
254Returns the time in seconds, relative to the origin of the 297Returns the time in seconds, relative to the origin of the
255universe. Only time differences are meaninful. 298universe. You should subtract the values returned by this function
299to get meaningful values.
256</p> 300</p>
257 301
258<p class=return> 302<p class=return>