From cdae8c02ed79efec522408b95106dca028e30ebf Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 18 Jun 2004 21:41:51 +0000 Subject: *** empty log message *** --- doc/socket.html | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'doc/socket.html') 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 true if the library was compiled with debug support.

+ + +

+socket.newtry(finalizer) +

+ +

+Creates and returns a clean +try +function that allows for cleanup before the exception +is raised. +

+ +

+Finalizer is a function that will be called before +try throws the exception. It will be called +in protected mode. +

+ +

+The function returns your customized try function. +

+ +

+Note: This idea saved a lot of work with the +implementation of protocols in LuaSocket: +

+ +
+foo = socket.protect(function()
+    -- connect somewhere
+    local c = socket.try(socket.connect("somewhere", 42))
+    -- create a try function that closes 'c' on error
+    local try = socket.newtry(function() c:close() end)
+    -- do everything reassured c will be closed 
+    try(c:send("helo there?\r\n"))
+    local answer = try(c:receive())
+    ...
+    try(c:send("good bye\r\n"))
+    c:close()
+end)
+
+ @@ -209,7 +252,7 @@ Freezes the program execution during a given amount of time.

Time is the number of seconds to sleep for. -The function truncates time to the nearest integer. +The function truncates time down to the nearest integer.

@@ -252,7 +295,8 @@ socket.time()

Returns the time in seconds, relative to the origin of the -universe. Only time differences are meaninful. +universe. You should subtract the values returned by this function +to get meaningful values.

-- cgit v1.2.3-55-g6feb