diff options
Diffstat (limited to '')
| -rw-r--r-- | docs/unix.html | 795 |
1 files changed, 795 insertions, 0 deletions
diff --git a/docs/unix.html b/docs/unix.html new file mode 100644 index 0000000..de71925 --- /dev/null +++ b/docs/unix.html | |||
| @@ -0,0 +1,795 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <meta name="description" content="LuaSocket: Unix domain socket support"> | ||
| 7 | <meta name="keywords" content="Lua, LuaSocket, Socket, Unix, Domain, IPC, Library, Support"> | ||
| 8 | <title>LuaSocket: Unix domain socket support</title> | ||
| 9 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 10 | </head> | ||
| 11 | |||
| 12 | <body> | ||
| 13 | |||
| 14 | <!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 15 | |||
| 16 | <div class="header"> | ||
| 17 | <hr> | ||
| 18 | <center> | ||
| 19 | <table summary="LuaSocket logo"> | ||
| 20 | <tr><td align="center"><a href="http://www.lua.org"> | ||
| 21 | <img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png"> | ||
| 22 | </a></td></tr> | ||
| 23 | <tr><td align="center" valign="top">Network support for the Lua language | ||
| 24 | </td></tr> | ||
| 25 | </table> | ||
| 26 | <p class="bar"> | ||
| 27 | <a href="index.html">home</a> · | ||
| 28 | <a href="index.html#download">download</a> · | ||
| 29 | <a href="installation.html">installation</a> · | ||
| 30 | <a href="introduction.html">introduction</a> · | ||
| 31 | <a href="reference.html">reference</a> | ||
| 32 | </p> | ||
| 33 | </center> | ||
| 34 | <hr> | ||
| 35 | </div> | ||
| 36 | |||
| 37 | <!-- unix ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 38 | |||
| 39 | <h2 id="unix">Unix domain sockets</h2> | ||
| 40 | |||
| 41 | <p> | ||
| 42 | Unix domain sockets provide inter-process communication between processes | ||
| 43 | on the same host, addressed by a path in the file system rather than by an | ||
| 44 | IP address and port. LuaSocket supports both the stream (connection | ||
| 45 | oriented, like TCP) and datagram (connectionless, like UDP) flavors. | ||
| 46 | </p> | ||
| 47 | |||
| 48 | <p class="note"> | ||
| 49 | Note: This module is only built on Unix-like platforms (Linux, macOS, | ||
| 50 | BSD, Haiku). It is not available on Windows. | ||
| 51 | </p> | ||
| 52 | |||
| 53 | <p> | ||
| 54 | Unlike the core <tt>socket</tt> namespace, Unix domain socket support is a | ||
| 55 | separate module that must be required explicitly: | ||
| 56 | </p> | ||
| 57 | |||
| 58 | <pre class="example"> | ||
| 59 | -- loads the socket.unix module | ||
| 60 | local unix = require("socket.unix") | ||
| 61 | </pre> | ||
| 62 | |||
| 63 | <p> | ||
| 64 | The module table returned by <tt>require("socket.unix")</tt> exposes two | ||
| 65 | constructors, <a href="#socket.unix.stream"><tt>unix.stream()</tt></a> and | ||
| 66 | <a href="#socket.unix.dgram"><tt>unix.dgram()</tt></a>. For backwards | ||
| 67 | compatibility, <tt>unix.tcp</tt> and <tt>unix.udp</tt> are aliases for | ||
| 68 | <tt>stream</tt> and <tt>dgram</tt> respectively, and the module table | ||
| 69 | itself can be called directly as a shortcut for <tt>unix.stream()</tt> | ||
| 70 | (i.e. <tt>unix()</tt> is the same as <tt>unix.stream()</tt>). | ||
| 71 | </p> | ||
| 72 | |||
| 73 | <p class="note"> | ||
| 74 | Note: Paths passed to <a href="#stream.bind"><tt>bind</tt></a>, | ||
| 75 | <a href="#stream.connect"><tt>connect</tt></a> and their datagram | ||
| 76 | equivalents are limited by the platform's <tt>sun_path</tt> buffer size | ||
| 77 | (commonly around 100–108 bytes). A path that does not fit returns | ||
| 78 | <b><tt>nil</tt></b> followed by the error message '<tt>path too | ||
| 79 | long</tt>'. | ||
| 80 | </p> | ||
| 81 | |||
| 82 | <!-- stream ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 83 | |||
| 84 | <h3 id="stream">Stream (<tt>socket.unix.stream</tt>)</h3> | ||
| 85 | |||
| 86 | <p> | ||
| 87 | Stream Unix domain sockets behave like TCP sockets (see | ||
| 88 | <a href="tcp.html">TCP</a>): a freshly created object is a <em>master</em> | ||
| 89 | object, which becomes a <em>client</em> object after a successful | ||
| 90 | <a href="#stream.connect"><tt>connect</tt></a>, or a <em>server</em> | ||
| 91 | object after a successful <a href="#stream.listen"><tt>listen</tt></a> | ||
| 92 | (itself normally preceded by <a href="#stream.bind"><tt>bind</tt></a>). | ||
| 93 | Server objects produce client objects via | ||
| 94 | <a href="#stream.accept"><tt>accept</tt></a>. Most methods below work the | ||
| 95 | same way as their TCP counterparts, just addressed by path instead of | ||
| 96 | IP/port. | ||
| 97 | </p> | ||
| 98 | |||
| 99 | <!-- stream.accept ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 100 | |||
| 101 | <p class="name" id="stream.accept"> | ||
| 102 | server:<b>accept()</b> | ||
| 103 | </p> | ||
| 104 | |||
| 105 | <p class="description"> | ||
| 106 | Waits for a remote connection on the server object and returns a client | ||
| 107 | object representing that connection. Works exactly like | ||
| 108 | <a href="tcp.html#accept"><tt>tcp:accept</tt></a>. | ||
| 109 | </p> | ||
| 110 | |||
| 111 | <p class="return"> | ||
| 112 | If a connection is successfully accepted, a client object is returned. If a | ||
| 113 | timeout condition is met, the method returns <b><tt>nil</tt></b> followed | ||
| 114 | by the error string '<tt>timeout</tt>'. Other errors are reported by | ||
| 115 | <b><tt>nil</tt></b> followed by a message describing the error. | ||
| 116 | </p> | ||
| 117 | |||
| 118 | <!-- stream.bind ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 119 | |||
| 120 | <p class="name" id="stream.bind"> | ||
| 121 | master:<b>bind(</b>path<b>)</b><br> | ||
| 122 | master:<b>setsockname(</b>path<b>)</b> | ||
| 123 | </p> | ||
| 124 | |||
| 125 | <p class="description"> | ||
| 126 | Binds a master object to a file system <tt>path</tt>. <tt>setsockname</tt> | ||
| 127 | is an alias for <tt>bind</tt>. | ||
| 128 | </p> | ||
| 129 | |||
| 130 | <p class="parameters"> | ||
| 131 | <tt>Path</tt> is a string with the file system path to bind to. The path | ||
| 132 | must not already exist as a socket file — remove any stale socket | ||
| 133 | file left over from a previous run before binding. | ||
| 134 | </p> | ||
| 135 | |||
| 136 | <p class="return"> | ||
| 137 | In case of success, the method returns 1. In case of error, the method | ||
| 138 | returns <b><tt>nil</tt></b> followed by an error message. | ||
| 139 | </p> | ||
| 140 | |||
| 141 | <!-- stream.close +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 142 | |||
| 143 | <p class="name" id="stream.close"> | ||
| 144 | master:<b>close()</b><br> | ||
| 145 | client:<b>close()</b><br> | ||
| 146 | server:<b>close()</b> | ||
| 147 | </p> | ||
| 148 | |||
| 149 | <p class="description"> | ||
| 150 | Closes a stream Unix domain object. The internal socket used by the object | ||
| 151 | is closed. No further operations (except further calls to | ||
| 152 | <tt>close</tt>) are allowed on a closed socket. | ||
| 153 | </p> | ||
| 154 | |||
| 155 | <p class="note"> | ||
| 156 | Note: Closing a socket does not remove the bound path from the file | ||
| 157 | system. Delete the socket file yourself (e.g. <tt>os.remove(path)</tt>) | ||
| 158 | once the server is done with it. | ||
| 159 | </p> | ||
| 160 | |||
| 161 | <p class="note"> | ||
| 162 | Note: Garbage-collected objects are automatically closed before | ||
| 163 | destruction. | ||
| 164 | </p> | ||
| 165 | |||
| 166 | <!-- stream.connect +++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 167 | |||
| 168 | <p class="name" id="stream.connect"> | ||
| 169 | master:<b>connect(</b>path<b>)</b><br> | ||
| 170 | master:<b>setpeername(</b>path<b>)</b> | ||
| 171 | </p> | ||
| 172 | |||
| 173 | <p class="description"> | ||
| 174 | Attempts to connect a master object to <tt>path</tt>, transforming it | ||
| 175 | into a client object. <tt>setpeername</tt> is an alias for | ||
| 176 | <tt>connect</tt>. Client objects support | ||
| 177 | <a href="#stream.send"><tt>send</tt></a>, | ||
| 178 | <a href="#stream.receive"><tt>receive</tt></a>, | ||
| 179 | <a href="#stream.getsockname"><tt>getsockname</tt></a>, | ||
| 180 | <a href="#stream.settimeout"><tt>settimeout</tt></a>, | ||
| 181 | <a href="#stream.shutdown"><tt>shutdown</tt></a>, and | ||
| 182 | <a href="#stream.close"><tt>close</tt></a>. | ||
| 183 | </p> | ||
| 184 | |||
| 185 | <p class="parameters"> | ||
| 186 | <tt>Path</tt> is a string with the file system path of a listening server | ||
| 187 | object. | ||
| 188 | </p> | ||
| 189 | |||
| 190 | <p class="return"> | ||
| 191 | In case of error, the method returns <b><tt>nil</tt></b> followed by a | ||
| 192 | string describing the error. In case of success, the method returns 1. | ||
| 193 | </p> | ||
| 194 | |||
| 195 | <!-- stream.dirty +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 196 | |||
| 197 | <p class="name" id="stream.dirty"> | ||
| 198 | master:<b>dirty()</b><br> | ||
| 199 | client:<b>dirty()</b><br> | ||
| 200 | server:<b>dirty()</b> | ||
| 201 | </p> | ||
| 202 | |||
| 203 | <p class="description"> | ||
| 204 | Check the read buffer status. | ||
| 205 | </p> | ||
| 206 | |||
| 207 | <p class="return"> | ||
| 208 | Returns <tt>true</tt> if there is any data in the read buffer, | ||
| 209 | <tt>false</tt> otherwise. | ||
| 210 | </p> | ||
| 211 | |||
| 212 | <p class="note"> | ||
| 213 | Note: <b>This is an internal method, use at your own risk.</b> | ||
| 214 | </p> | ||
| 215 | |||
| 216 | <!-- stream.getfd ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 217 | |||
| 218 | <p class="name" id="stream.getfd"> | ||
| 219 | master:<b>getfd()</b><br> | ||
| 220 | client:<b>getfd()</b><br> | ||
| 221 | server:<b>getfd()</b> | ||
| 222 | </p> | ||
| 223 | |||
| 224 | <p class="description"> | ||
| 225 | Returns the underlying socket descriptor or handle associated to the | ||
| 226 | object. | ||
| 227 | </p> | ||
| 228 | |||
| 229 | <p class="return"> | ||
| 230 | The descriptor or handle. | ||
| 231 | </p> | ||
| 232 | |||
| 233 | <p class="note"> | ||
| 234 | Note: <b>This is an internal method. Unlikely to be portable. Use at your | ||
| 235 | own risk.</b> | ||
| 236 | </p> | ||
| 237 | |||
| 238 | <!-- stream.getsockname +++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 239 | |||
| 240 | <p class="name" id="stream.getsockname"> | ||
| 241 | master:<b>getsockname()</b><br> | ||
| 242 | client:<b>getsockname()</b><br> | ||
| 243 | server:<b>getsockname()</b> | ||
| 244 | </p> | ||
| 245 | |||
| 246 | <p class="description"> | ||
| 247 | Returns the local path the object is bound to. | ||
| 248 | </p> | ||
| 249 | |||
| 250 | <p class="return"> | ||
| 251 | The method returns a string with the local path. In case of error, the | ||
| 252 | method returns <b><tt>nil</tt></b>. | ||
| 253 | </p> | ||
| 254 | |||
| 255 | <!-- stream.getstats +++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 256 | |||
| 257 | <p class="name" id="stream.getstats"> | ||
| 258 | master:<b>getstats()</b><br> | ||
| 259 | client:<b>getstats()</b><br> | ||
| 260 | server:<b>getstats()</b> | ||
| 261 | </p> | ||
| 262 | |||
| 263 | <p class="description"> | ||
| 264 | Returns accounting information on the socket, useful for throttling of | ||
| 265 | bandwidth. Works exactly like <a href="tcp.html#getstats"><tt>tcp:getstats</tt></a>. | ||
| 266 | </p> | ||
| 267 | |||
| 268 | <p class="return"> | ||
| 269 | The method returns the number of bytes received, the number of bytes | ||
| 270 | sent, and the age of the socket object in seconds. | ||
| 271 | </p> | ||
| 272 | |||
| 273 | <!-- stream.listen ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 274 | |||
| 275 | <p class="name" id="stream.listen"> | ||
| 276 | master:<b>listen(</b>[backlog]<b>)</b> | ||
| 277 | </p> | ||
| 278 | |||
| 279 | <p class="description"> | ||
| 280 | Specifies the socket is willing to receive connections, transforming the | ||
| 281 | object into a server object. Server objects support | ||
| 282 | <a href="#stream.accept"><tt>accept</tt></a>, | ||
| 283 | <a href="#stream.getsockname"><tt>getsockname</tt></a>, | ||
| 284 | <a href="#stream.setoption"><tt>setoption</tt></a>, | ||
| 285 | <a href="#stream.settimeout"><tt>settimeout</tt></a>, and | ||
| 286 | <a href="#stream.close"><tt>close</tt></a>. | ||
| 287 | </p> | ||
| 288 | |||
| 289 | <p class="parameters"> | ||
| 290 | The optional <tt>backlog</tt> parameter specifies the number of client | ||
| 291 | connections that can be queued waiting for service. Defaults to 32. | ||
| 292 | </p> | ||
| 293 | |||
| 294 | <p class="return"> | ||
| 295 | In case of success, the method returns 1. In case of error, the method | ||
| 296 | returns <b><tt>nil</tt></b> followed by an error message. | ||
| 297 | </p> | ||
| 298 | |||
| 299 | <!-- stream.receive +++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 300 | |||
| 301 | <p class="name" id="stream.receive"> | ||
| 302 | client:<b>receive(</b>[pattern [, prefix [, maxsize]]]<b>)</b> | ||
| 303 | </p> | ||
| 304 | |||
| 305 | <p class="description"> | ||
| 306 | Reads data from a client object. Works exactly like | ||
| 307 | <a href="tcp.html#receive"><tt>tcp:receive</tt></a>, including the | ||
| 308 | <tt>*a</tt>/<tt>*l</tt>/<tt>number</tt> patterns and the | ||
| 309 | <tt>prefix</tt>/<tt>maxsize</tt> parameters. | ||
| 310 | </p> | ||
| 311 | |||
| 312 | <!-- stream.send +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 313 | |||
| 314 | <p class="name" id="stream.send"> | ||
| 315 | client:<b>send(</b>data [, i [, j]]<b>)</b> | ||
| 316 | </p> | ||
| 317 | |||
| 318 | <p class="description"> | ||
| 319 | Sends <tt>data</tt> through a client object. Works exactly like | ||
| 320 | <a href="tcp.html#send"><tt>tcp:send</tt></a>, including the optional | ||
| 321 | <tt>i</tt>/<tt>j</tt> substring selection. | ||
| 322 | </p> | ||
| 323 | |||
| 324 | <!-- stream.setfd ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 325 | |||
| 326 | <p class="name" id="stream.setfd"> | ||
| 327 | master:<b>setfd(</b>fd<b>)</b><br> | ||
| 328 | client:<b>setfd(</b>fd<b>)</b><br> | ||
| 329 | server:<b>setfd(</b>fd<b>)</b> | ||
| 330 | </p> | ||
| 331 | |||
| 332 | <p class="description"> | ||
| 333 | Sets the underlying socket descriptor or handle associated to the object. | ||
| 334 | The current one is simply replaced, not closed, and no other change to | ||
| 335 | the object state is made. | ||
| 336 | </p> | ||
| 337 | |||
| 338 | <p class="return"> | ||
| 339 | No return value. | ||
| 340 | </p> | ||
| 341 | |||
| 342 | <p class="note"> | ||
| 343 | Note: <b>This is an internal method. Unlikely to be portable. Use at your | ||
| 344 | own risk.</b> | ||
| 345 | </p> | ||
| 346 | |||
| 347 | <!-- stream.setoption +++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 348 | |||
| 349 | <p class="name" id="stream.setoption"> | ||
| 350 | client:<b>setoption(</b>option [, value]<b>)</b><br> | ||
| 351 | server:<b>setoption(</b>option [, value]<b>)</b> | ||
| 352 | </p> | ||
| 353 | |||
| 354 | <p class="description"> | ||
| 355 | Sets options for the stream object. Options are only needed by low-level | ||
| 356 | or time-critical applications. You should only modify an option if you | ||
| 357 | are sure you need it. | ||
| 358 | </p> | ||
| 359 | |||
| 360 | <p class="parameters"> | ||
| 361 | <tt>Option</tt> is a string with the option name, and <tt>value</tt> | ||
| 362 | depends on the option being set: | ||
| 363 | </p> | ||
| 364 | |||
| 365 | <ul> | ||
| 366 | <li> '<tt>keepalive</tt>': Setting this option to <tt>true</tt> enables | ||
| 367 | the periodic transmission of messages on a connected socket. See | ||
| 368 | <a href="tcp.html#setoption"><tt>tcp:setoption</tt></a> for details;</li> | ||
| 369 | <li> '<tt>reuseaddr</tt>': Setting this option indicates that the rules | ||
| 370 | used in validating addresses supplied in a call to | ||
| 371 | <a href="#stream.bind"><tt>bind</tt></a> should allow reuse of local | ||
| 372 | addresses;</li> | ||
| 373 | <li> '<tt>linger</tt>': Controls the action taken when unsent data are | ||
| 374 | queued on a socket and a close is performed. See | ||
| 375 | <a href="tcp.html#setoption"><tt>tcp:setoption</tt></a> for the full | ||
| 376 | description of the <tt>on</tt>/<tt>timeout</tt> value table.</li> | ||
| 377 | </ul> | ||
| 378 | |||
| 379 | <p class="return"> | ||
| 380 | The method returns 1 in case of success, or <b><tt>nil</tt></b> followed | ||
| 381 | by an error message otherwise. | ||
| 382 | </p> | ||
| 383 | |||
| 384 | <!-- stream.setstats +++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 385 | |||
| 386 | <p class="name" id="stream.setstats"> | ||
| 387 | master:<b>setstats(</b>received, sent, age<b>)</b><br> | ||
| 388 | client:<b>setstats(</b>received, sent, age<b>)</b><br> | ||
| 389 | server:<b>setstats(</b>received, sent, age<b>)</b> | ||
| 390 | </p> | ||
| 391 | |||
| 392 | <p class="description"> | ||
| 393 | Resets accounting information on the socket, useful for throttling of | ||
| 394 | bandwidth. Works exactly like | ||
| 395 | <a href="tcp.html#setstats"><tt>tcp:setstats</tt></a>. | ||
| 396 | </p> | ||
| 397 | |||
| 398 | <p class="return"> | ||
| 399 | The method returns 1 in case of success and <tt><b>nil</b></tt> otherwise. | ||
| 400 | </p> | ||
| 401 | |||
| 402 | <!-- stream.settimeout +++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 403 | |||
| 404 | <p class="name" id="stream.settimeout"> | ||
| 405 | master:<b>settimeout(</b>value [, mode]<b>)</b><br> | ||
| 406 | client:<b>settimeout(</b>value [, mode]<b>)</b><br> | ||
| 407 | server:<b>settimeout(</b>value [, mode]<b>)</b> | ||
| 408 | </p> | ||
| 409 | |||
| 410 | <p class="description"> | ||
| 411 | Changes the timeout values for the object. Works exactly like | ||
| 412 | <a href="tcp.html#settimeout"><tt>tcp:settimeout</tt></a>, including the | ||
| 413 | '<tt>b</tt>' (block) and '<tt>t</tt>' (total) modes. | ||
| 414 | </p> | ||
| 415 | |||
| 416 | <!-- stream.shutdown ++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 417 | |||
| 418 | <p class="name" id="stream.shutdown"> | ||
| 419 | client:<b>shutdown(</b>[mode]<b>)</b> | ||
| 420 | </p> | ||
| 421 | |||
| 422 | <p class="description"> | ||
| 423 | Shuts down part of a full-duplex connection. Works exactly like | ||
| 424 | <a href="tcp.html#shutdown"><tt>tcp:shutdown</tt></a>. | ||
| 425 | </p> | ||
| 426 | |||
| 427 | <p class="parameters"> | ||
| 428 | <tt>Mode</tt> can be "<tt>both</tt>" (default), "<tt>send</tt>" or | ||
| 429 | "<tt>receive</tt>". | ||
| 430 | </p> | ||
| 431 | |||
| 432 | <p class="return"> | ||
| 433 | This function returns 1. | ||
| 434 | </p> | ||
| 435 | |||
| 436 | <!-- socket.unix.stream +++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 437 | |||
| 438 | <p class="name" id="socket.unix.stream"> | ||
| 439 | unix.<b>stream()</b> | ||
| 440 | </p> | ||
| 441 | |||
| 442 | <p class="description"> | ||
| 443 | Creates and returns a stream Unix domain master object. A master object | ||
| 444 | can be transformed into a server object with | ||
| 445 | <a href="#stream.listen"><tt>listen</tt></a> (after a call to | ||
| 446 | <a href="#stream.bind"><tt>bind</tt></a>) or into a client object with | ||
| 447 | <a href="#stream.connect"><tt>connect</tt></a>. The only other method | ||
| 448 | supported by a master object is <a href="#stream.close"><tt>close</tt></a>. | ||
| 449 | </p> | ||
| 450 | |||
| 451 | <p class="return"> | ||
| 452 | In case of success, a new master object is returned. In case of error, | ||
| 453 | <b><tt>nil</tt></b> is returned, followed by an error message. | ||
| 454 | </p> | ||
| 455 | |||
| 456 | <!-- dgram +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 457 | |||
| 458 | <h3 id="dgram">Datagram (<tt>socket.unix.dgram</tt>)</h3> | ||
| 459 | |||
| 460 | <p> | ||
| 461 | Datagram Unix domain sockets behave like UDP sockets (see | ||
| 462 | <a href="udp.html">UDP</a>): a socket starts out unconnected, and can | ||
| 463 | optionally be turned into a connected socket with | ||
| 464 | <a href="#dgram.connect"><tt>connect</tt></a> for repeated exchanges with | ||
| 465 | a single peer. | ||
| 466 | </p> | ||
| 467 | |||
| 468 | <!-- dgram.bind +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 469 | |||
| 470 | <p class="name" id="dgram.bind"> | ||
| 471 | unconnected:<b>bind(</b>path<b>)</b><br> | ||
| 472 | unconnected:<b>setsockname(</b>path<b>)</b> | ||
| 473 | </p> | ||
| 474 | |||
| 475 | <p class="description"> | ||
| 476 | Binds the datagram object to a local file system <tt>path</tt>. | ||
| 477 | <tt>setsockname</tt> is an alias for <tt>bind</tt>. Binding is only | ||
| 478 | required if you want other processes to be able to | ||
| 479 | <a href="#dgram.sendto"><tt>sendto</tt></a> this object; it is not | ||
| 480 | required to <a href="#dgram.sendto"><tt>sendto</tt></a> or | ||
| 481 | <a href="#dgram.connect"><tt>connect</tt></a> from it. | ||
| 482 | </p> | ||
| 483 | |||
| 484 | <p class="return"> | ||
| 485 | In case of success, the method returns 1. In case of error, the method | ||
| 486 | returns <b><tt>nil</tt></b> followed by an error message. | ||
| 487 | </p> | ||
| 488 | |||
| 489 | <!-- dgram.close ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 490 | |||
| 491 | <p class="name" id="dgram.close"> | ||
| 492 | connected:<b>close()</b><br> | ||
| 493 | unconnected:<b>close()</b> | ||
| 494 | </p> | ||
| 495 | |||
| 496 | <p class="description"> | ||
| 497 | Closes a datagram Unix domain object. | ||
| 498 | </p> | ||
| 499 | |||
| 500 | <p class="note"> | ||
| 501 | Note: Closing a socket does not remove the bound path from the file | ||
| 502 | system. Delete the socket file yourself (e.g. <tt>os.remove(path)</tt>) | ||
| 503 | once you are done with it. | ||
| 504 | </p> | ||
| 505 | |||
| 506 | <p class="note"> | ||
| 507 | Note: Garbage-collected objects are automatically closed before | ||
| 508 | destruction. | ||
| 509 | </p> | ||
| 510 | |||
| 511 | <!-- dgram.connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 512 | |||
| 513 | <p class="name" id="dgram.connect"> | ||
| 514 | connected:<b>connect(</b>path<b>)</b><br> | ||
| 515 | unconnected:<b>connect(</b>path<b>)</b><br> | ||
| 516 | connected:<b>setpeername(</b>path<b>)</b><br> | ||
| 517 | unconnected:<b>setpeername(</b>path<b>)</b> | ||
| 518 | </p> | ||
| 519 | |||
| 520 | <p class="description"> | ||
| 521 | Sets (or changes) the peer of a datagram object, turning an unconnected | ||
| 522 | object into a connected one. <tt>setpeername</tt> is an alias for | ||
| 523 | <tt>connect</tt>. | ||
| 524 | </p> | ||
| 525 | |||
| 526 | <p class="parameters"> | ||
| 527 | <tt>Path</tt> is a string with the file system path of the peer. | ||
| 528 | </p> | ||
| 529 | |||
| 530 | <p class="return"> | ||
| 531 | In case of error, the method returns <b><tt>nil</tt></b> followed by an | ||
| 532 | error message. In case of success, the method returns 1. | ||
| 533 | </p> | ||
| 534 | |||
| 535 | <p class="note"> | ||
| 536 | Note: Unlike <a href="udp.html#setpeername"><tt>udp:setpeername</tt></a>, | ||
| 537 | there is no '<tt>*</tt>' path to dissolve the peer association back to an | ||
| 538 | unconnected socket. | ||
| 539 | </p> | ||
| 540 | |||
| 541 | <!-- dgram.dirty ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 542 | |||
| 543 | <p class="name" id="dgram.dirty"> | ||
| 544 | connected:<b>dirty()</b><br> | ||
| 545 | unconnected:<b>dirty()</b> | ||
| 546 | </p> | ||
| 547 | |||
| 548 | <p class="description"> | ||
| 549 | Check the read buffer status. | ||
| 550 | </p> | ||
| 551 | |||
| 552 | <p class="return"> | ||
| 553 | Always returns <tt>false</tt>. Datagram objects do not keep a read | ||
| 554 | buffer. | ||
| 555 | </p> | ||
| 556 | |||
| 557 | <p class="note"> | ||
| 558 | Note: <b>This is an internal method, use at your own risk.</b> | ||
| 559 | </p> | ||
| 560 | |||
| 561 | <!-- dgram.getfd ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 562 | |||
| 563 | <p class="name" id="dgram.getfd"> | ||
| 564 | connected:<b>getfd()</b><br> | ||
| 565 | unconnected:<b>getfd()</b> | ||
| 566 | </p> | ||
| 567 | |||
| 568 | <p class="description"> | ||
| 569 | Returns the underlying socket descriptor or handle associated to the | ||
| 570 | object. | ||
| 571 | </p> | ||
| 572 | |||
| 573 | <p class="return"> | ||
| 574 | The descriptor or handle. | ||
| 575 | </p> | ||
| 576 | |||
| 577 | <p class="note"> | ||
| 578 | Note: <b>This is an internal method. Unlikely to be portable. Use at your | ||
| 579 | own risk.</b> | ||
| 580 | </p> | ||
| 581 | |||
| 582 | <!-- dgram.getsockname +++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 583 | |||
| 584 | <p class="name" id="dgram.getsockname"> | ||
| 585 | connected:<b>getsockname()</b><br> | ||
| 586 | unconnected:<b>getsockname()</b> | ||
| 587 | </p> | ||
| 588 | |||
| 589 | <p class="description"> | ||
| 590 | Returns the local path the object is bound to. | ||
| 591 | </p> | ||
| 592 | |||
| 593 | <p class="return"> | ||
| 594 | The method returns a string with the local path. In case of error, the | ||
| 595 | method returns <b><tt>nil</tt></b>. | ||
| 596 | </p> | ||
| 597 | |||
| 598 | <!-- dgram.gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 599 | |||
| 600 | <p class="name" id="dgram.gettimeout"> | ||
| 601 | connected:<b>gettimeout()</b><br> | ||
| 602 | unconnected:<b>gettimeout()</b> | ||
| 603 | </p> | ||
| 604 | |||
| 605 | <p class="description"> | ||
| 606 | Returns the current timeout value. | ||
| 607 | </p> | ||
| 608 | |||
| 609 | <!-- dgram.receive +++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 610 | |||
| 611 | <p class="name" id="dgram.receive"> | ||
| 612 | connected:<b>receive(</b>[size]<b>)</b><br> | ||
| 613 | unconnected:<b>receive(</b>[size]<b>)</b> | ||
| 614 | </p> | ||
| 615 | |||
| 616 | <p class="description"> | ||
| 617 | Receives a datagram from the object. If the object is connected, only | ||
| 618 | datagrams coming from the peer are accepted. | ||
| 619 | </p> | ||
| 620 | |||
| 621 | <p class="parameters"> | ||
| 622 | The optional <tt>size</tt> parameter specifies the maximum size of the | ||
| 623 | datagram to be retrieved (defaults to 8192 bytes). | ||
| 624 | </p> | ||
| 625 | |||
| 626 | <p class="return"> | ||
| 627 | In case of success, the method returns the received datagram, which may | ||
| 628 | be the empty string (a valid zero-length datagram, not end-of-stream). In | ||
| 629 | case of timeout, the method returns <b><tt>nil</tt></b> followed by the | ||
| 630 | string '<tt>timeout</tt>'. | ||
| 631 | </p> | ||
| 632 | |||
| 633 | <!-- dgram.receivefrom +++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 634 | |||
| 635 | <p class="name" id="dgram.receivefrom"> | ||
| 636 | unconnected:<b>receivefrom(</b>[size]<b>)</b> | ||
| 637 | </p> | ||
| 638 | |||
| 639 | <p class="description"> | ||
| 640 | Works exactly as <a href="#dgram.receive"><tt>receive</tt></a>, except it | ||
| 641 | also returns the sender's path as a second return value. | ||
| 642 | </p> | ||
| 643 | |||
| 644 | <p class="return"> | ||
| 645 | In case of success, the method returns the received datagram followed by | ||
| 646 | the sender's path (the empty string if the sender's socket was not | ||
| 647 | bound). In case of timeout, the method returns <b><tt>nil</tt></b> | ||
| 648 | followed by the string '<tt>timeout</tt>'. | ||
| 649 | </p> | ||
| 650 | |||
| 651 | <!-- dgram.send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 652 | |||
| 653 | <p class="name" id="dgram.send"> | ||
| 654 | connected:<b>send(</b>datagram<b>)</b> | ||
| 655 | </p> | ||
| 656 | |||
| 657 | <p class="description"> | ||
| 658 | Sends a datagram to the peer of a connected object. | ||
| 659 | </p> | ||
| 660 | |||
| 661 | <p class="return"> | ||
| 662 | If successful, the method returns the number of bytes sent. In case of | ||
| 663 | error, the method returns <b><tt>nil</tt></b> followed by an error | ||
| 664 | message (the string '<tt>refused</tt>' if the peer's socket is not | ||
| 665 | accepting datagrams). | ||
| 666 | </p> | ||
| 667 | |||
| 668 | <!-- dgram.sendto +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 669 | |||
| 670 | <p class="name" id="dgram.sendto"> | ||
| 671 | unconnected:<b>sendto(</b>datagram, path<b>)</b> | ||
| 672 | </p> | ||
| 673 | |||
| 674 | <p class="description"> | ||
| 675 | Sends a datagram to the object bound to <tt>path</tt>. | ||
| 676 | </p> | ||
| 677 | |||
| 678 | <p class="parameters"> | ||
| 679 | <tt>Datagram</tt> is a string with the datagram contents. <tt>Path</tt> | ||
| 680 | is the file system path of the recipient. | ||
| 681 | </p> | ||
| 682 | |||
| 683 | <p class="return"> | ||
| 684 | If successful, the method returns the number of bytes sent. In case of | ||
| 685 | error, the method returns <b><tt>nil</tt></b> followed by an error | ||
| 686 | message (the string '<tt>refused</tt>' if the recipient's socket is not | ||
| 687 | accepting datagrams). | ||
| 688 | </p> | ||
| 689 | |||
| 690 | <!-- dgram.setfd ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 691 | |||
| 692 | <p class="name" id="dgram.setfd"> | ||
| 693 | connected:<b>setfd(</b>fd<b>)</b><br> | ||
| 694 | unconnected:<b>setfd(</b>fd<b>)</b> | ||
| 695 | </p> | ||
| 696 | |||
| 697 | <p class="description"> | ||
| 698 | Sets the underlying socket descriptor or handle associated to the object. | ||
| 699 | </p> | ||
| 700 | |||
| 701 | <p class="return"> | ||
| 702 | No return value. | ||
| 703 | </p> | ||
| 704 | |||
| 705 | <p class="note"> | ||
| 706 | Note: <b>This is an internal method. Unlikely to be portable. Use at your | ||
| 707 | own risk.</b> | ||
| 708 | </p> | ||
| 709 | |||
| 710 | <!-- dgram.setoption +++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 711 | |||
| 712 | <p class="name" id="dgram.setoption"> | ||
| 713 | connected:<b>setoption(</b>option [, value]<b>)</b><br> | ||
| 714 | unconnected:<b>setoption(</b>option [, value]<b>)</b> | ||
| 715 | </p> | ||
| 716 | |||
| 717 | <p class="description"> | ||
| 718 | Sets options for the datagram object. | ||
| 719 | </p> | ||
| 720 | |||
| 721 | <p class="parameters"> | ||
| 722 | <tt>Option</tt> is a string with the option name: | ||
| 723 | </p> | ||
| 724 | |||
| 725 | <ul> | ||
| 726 | <li> '<tt>reuseaddr</tt>': Indicates that the rules used in validating | ||
| 727 | addresses supplied in a <a href="#dgram.bind"><tt>bind</tt></a> call | ||
| 728 | should allow reuse of local addresses. Receives a boolean value.</li> | ||
| 729 | </ul> | ||
| 730 | |||
| 731 | <p class="return"> | ||
| 732 | The method returns 1 in case of success, or <b><tt>nil</tt></b> followed | ||
| 733 | by an error message otherwise. | ||
| 734 | </p> | ||
| 735 | |||
| 736 | <!-- dgram.settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 737 | |||
| 738 | <p class="name" id="dgram.settimeout"> | ||
| 739 | connected:<b>settimeout(</b>value<b>)</b><br> | ||
| 740 | unconnected:<b>settimeout(</b>value<b>)</b> | ||
| 741 | </p> | ||
| 742 | |||
| 743 | <p class="description"> | ||
| 744 | Changes the timeout value for the object. Works like | ||
| 745 | <a href="udp.html#settimeout"><tt>udp:settimeout</tt></a>: since | ||
| 746 | <a href="#dgram.send"><tt>send</tt></a> and | ||
| 747 | <a href="#dgram.sendto"><tt>sendto</tt></a> never block, this only | ||
| 748 | affects <a href="#dgram.receive"><tt>receive</tt></a> and | ||
| 749 | <a href="#dgram.receivefrom"><tt>receivefrom</tt></a>. | ||
| 750 | </p> | ||
| 751 | |||
| 752 | <!-- socket.unix.dgram +++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 753 | |||
| 754 | <p class="name" id="socket.unix.dgram"> | ||
| 755 | unix.<b>dgram()</b> | ||
| 756 | </p> | ||
| 757 | |||
| 758 | <p class="description"> | ||
| 759 | Creates and returns an unconnected datagram Unix domain object. | ||
| 760 | Unconnected objects support | ||
| 761 | <a href="#dgram.sendto"><tt>sendto</tt></a>, | ||
| 762 | <a href="#dgram.receive"><tt>receive</tt></a>, | ||
| 763 | <a href="#dgram.receivefrom"><tt>receivefrom</tt></a>, | ||
| 764 | <a href="#dgram.getsockname"><tt>getsockname</tt></a>, | ||
| 765 | <a href="#dgram.setoption"><tt>setoption</tt></a>, | ||
| 766 | <a href="#dgram.settimeout"><tt>settimeout</tt></a>, | ||
| 767 | <a href="#dgram.connect"><tt>connect</tt></a>, and | ||
| 768 | <a href="#dgram.close"><tt>close</tt></a>. Use | ||
| 769 | <a href="#dgram.connect"><tt>connect</tt></a> to turn the object into a | ||
| 770 | connected object. | ||
| 771 | </p> | ||
| 772 | |||
| 773 | <p class="return"> | ||
| 774 | In case of success, a new unconnected datagram object is returned. In | ||
| 775 | case of error, <b><tt>nil</tt></b> is returned, followed by an error | ||
| 776 | message. | ||
| 777 | </p> | ||
| 778 | |||
| 779 | <!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 780 | |||
| 781 | <div class="footer"> | ||
| 782 | <hr> | ||
| 783 | <center> | ||
| 784 | <p class="bar"> | ||
| 785 | <a href="index.html">home</a> · | ||
| 786 | <a href="index.html#download">download</a> · | ||
| 787 | <a href="installation.html">installation</a> · | ||
| 788 | <a href="introduction.html">introduction</a> · | ||
| 789 | <a href="reference.html">reference</a> | ||
| 790 | </p> | ||
| 791 | </center> | ||
| 792 | </div> | ||
| 793 | |||
| 794 | </body> | ||
| 795 | </html> | ||
