diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-18 21:41:51 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-18 21:41:51 +0000 |
| commit | cdae8c02ed79efec522408b95106dca028e30ebf (patch) | |
| tree | d15ee16ba5e886654863291394dae68b3a0bcc9d /doc/socket.html | |
| parent | 7ed89c97f760600df238f9853ee453570935870f (diff) | |
| download | luasocket-cdae8c02ed79efec522408b95106dca028e30ebf.tar.gz luasocket-cdae8c02ed79efec522408b95106dca028e30ebf.tar.bz2 luasocket-cdae8c02ed79efec522408b95106dca028e30ebf.zip | |
*** empty log message ***
Diffstat (limited to 'doc/socket.html')
| -rw-r--r-- | doc/socket.html | 48 |
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 | |||
| 60 | with debug support. | 60 | with debug support. |
| 61 | </p> | 61 | </p> |
| 62 | 62 | ||
| 63 | <!-- newtry +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 64 | |||
| 65 | <p class=name id=newtry> | ||
| 66 | socket.<b>newtry(</b>finalizer<b>)</b> | ||
| 67 | </p> | ||
| 68 | |||
| 69 | <p class=description> | ||
| 70 | Creates and returns a <em>clean</em> | ||
| 71 | <a href="#try"><tt>try</tt></a> | ||
| 72 | function that allows for cleanup before the exception | ||
| 73 | is 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 | ||
| 79 | in <em>protected</em> mode. | ||
| 80 | </p> | ||
| 81 | |||
| 82 | <p class=return> | ||
| 83 | The function returns your customized <tt>try</tt> function. | ||
| 84 | </p> | ||
| 85 | |||
| 86 | <p class=note> | ||
| 87 | Note: This idea saved a <em>lot</em> of work with the | ||
| 88 | implementation of protocols in LuaSocket: | ||
| 89 | </p> | ||
| 90 | |||
| 91 | <pre class=example> | ||
| 92 | foo = 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() | ||
| 103 | end) | ||
| 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. |
| 212 | The function truncates <tt>time</tt> to the nearest integer. | 255 | The 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> |
| 254 | Returns the time in seconds, relative to the origin of the | 297 | Returns the time in seconds, relative to the origin of the |
| 255 | universe. Only time differences are meaninful. | 298 | universe. You should subtract the values returned by this function |
| 299 | to get meaningful values. | ||
| 256 | </p> | 300 | </p> |
| 257 | 301 | ||
| 258 | <p class=return> | 302 | <p class=return> |
