1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5 <title>Reference</title>
6 <link rel="stylesheet" href="../luadoc.css" type="text/css" />
7 <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
14 <div id="product_logo"></div>
15 <div id="product_name"><big><b></b></big></div>
16 <div id="product_description"></div>
17 </div> <!-- id="product" -->
27 <li><a href="../index.html">Index</a></li>
38 <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
42 <a href="../modules/luci.http.html">luci.http</a>
46 <a href="../modules/luci.http.protocol.html">luci.http.protocol</a>
50 <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
54 <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
58 <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.mime</a>
62 <a href="../modules/luci.i18n.html">luci.i18n</a>
66 <a href="../modules/luci.ip.html">luci.ip</a>
70 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
74 <a href="../modules/luci.json.html">luci.json</a>
78 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
82 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
86 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
90 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
94 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
98 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
102 <a href="../modules/luci.sys.html">luci.sys</a>
106 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
110 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
114 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
118 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
122 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
126 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
130 <a href="../modules/luci.util.html">luci.util</a>
134 <a href="../modules/nixio.html">nixio</a>
138 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
142 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
146 <a href="../modules/nixio.File.html">nixio.File</a>
150 <a href="../modules/nixio.README.html">nixio.README</a>
154 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
158 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
162 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
165 <li><strong>nixio.UnifiedIO</strong></li>
168 <a href="../modules/nixio.bin.html">nixio.bin</a>
172 <a href="../modules/nixio.bit.html">nixio.bit</a>
176 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
180 <a href="../modules/nixio.fs.html">nixio.fs</a>
195 </div><!-- id="navigation" -->
199 <h1>Object Instance <code>nixio.UnifiedIO</code></h1>
202 Unified high-level I/O utility API for Files, Sockets and TLS-Sockets.
203 These functions are added to the object function tables by doing <strong>
204 require "nixio.util"</strong>, can be used on all nixio IO Descriptors and
205 are based on the shared low-level read() and write() functions.</p>
214 <table class="function_list">
217 <td class="name" nowrap><a href="#UnifiedIO.blocksource">UnifiedIO:blocksource</a> (blocksize, limit)</td>
219 Create a block-based iterator.</td>
223 <td class="name" nowrap><a href="#UnifiedIO.close">UnifiedIO:close</a> ()</td>
225 Close the descriptor.</td>
229 <td class="name" nowrap><a href="#UnifiedIO.copy">UnifiedIO:copy</a> (fdout, size)</td>
231 Copy data from the current descriptor to another one.</td>
235 <td class="name" nowrap><a href="#UnifiedIO.copyz">UnifiedIO:copyz</a> (fdout, size)</td>
237 Copy data from the current descriptor to another one using kernel-space
238 copying if possible.</td>
242 <td class="name" nowrap><a href="#UnifiedIO.is_file">UnifiedIO:is_file</a> ()</td>
244 Test whether the I/O-Descriptor is a file.</td>
248 <td class="name" nowrap><a href="#UnifiedIO.is_socket">UnifiedIO:is_socket</a> ()</td>
250 Test whether the I/O-Descriptor is a socket.</td>
254 <td class="name" nowrap><a href="#UnifiedIO.is_tls_socket">UnifiedIO:is_tls_socket</a> ()</td>
256 Test whether the I/O-Descriptor is a TLS socket.</td>
260 <td class="name" nowrap><a href="#UnifiedIO.linesource">UnifiedIO:linesource</a> (limit)</td>
262 Create a line-based iterator.</td>
266 <td class="name" nowrap><a href="#UnifiedIO.readall">UnifiedIO:readall</a> (length)</td>
268 Read a block of data and wait until all data is available.</td>
272 <td class="name" nowrap><a href="#UnifiedIO.sink">UnifiedIO:sink</a> (close_when_done)</td>
278 <td class="name" nowrap><a href="#UnifiedIO.writeall">UnifiedIO:writeall</a> (block)</td>
280 Write a block of data and wait until all data is written.</td>
294 <h2><a name="functions"></a>Functions</h2>
295 <dl class="function">
299 <dt><a name="UnifiedIO.blocksource"></a><strong>UnifiedIO:blocksource</strong> (blocksize, limit)</dt>
302 Create a block-based iterator.
309 blocksize: Advisory blocksize (optional)
313 limit: Amount of data to consume (optional)
324 <li>This function uses the low-level read function of the descriptor.
326 <li>The blocksize given is only advisory and to be seen as an upper limit,
327 if an underlying read returns less bytes the chunk is nevertheless returned.
329 <li>If the limit parameter is ommited, the iterator returns data
330 until an end-of-file, end-of-stream, connection shutdown or similar happens.
332 <li>The iterator will not buffer so it is safe to mix with calls to read.
334 <li>If the descriptor is non-blocking the iterator may fail with EAGAIN.
336 <li>The iterator can be used as an LTN12 source.
342 <h3>Return value:</h3>
352 <dt><a name="UnifiedIO.close"></a><strong>UnifiedIO:close</strong> ()</dt>
355 Close the descriptor.
362 If the descriptor is a TLS-socket the underlying descriptor is
363 closed without touching the TLS connection.
367 <h3>Return value:</h3>
377 <dt><a name="UnifiedIO.copy"></a><strong>UnifiedIO:copy</strong> (fdout, size)</dt>
380 Copy data from the current descriptor to another one.
387 fdout: Target Descriptor
391 size: Bytes to copy (optional)
402 <li>This function uses the blocksource function of the source descriptor
403 and the sink function of the target descriptor.
405 <li>If the limit parameter is ommited, data is copied
406 until an end-of-file, end-of-stream, connection shutdown or similar happens.
408 <li>If the descriptor is non-blocking the function may fail with EAGAIN.
414 <h3>Return values:</h3>
417 <li>bytes that were successfully written if no error occured
419 <li>- reserved for error code -
421 <li>- reserved for error message -
423 <li>bytes that were successfully written even if an error occured
434 <dt><a name="UnifiedIO.copyz"></a><strong>UnifiedIO:copyz</strong> (fdout, size)</dt>
437 Copy data from the current descriptor to another one using kernel-space
445 fdout: Target Descriptor
449 size: Bytes to copy (optional)
460 <li>This function uses the sendfile() syscall to copy the data or the
461 blocksource function of the source descriptor and the sink function
462 of the target descriptor as a fallback mechanism.
464 <li>If the limit parameter is ommited, data is copied
465 until an end-of-file, end-of-stream, connection shutdown or similar happens.
467 <li>If the descriptor is non-blocking the function may fail with EAGAIN.
473 <h3>Return values:</h3>
476 <li>bytes that were successfully written if no error occured
478 <li>- reserved for error code -
480 <li>- reserved for error message -
482 <li>bytes that were successfully written even if an error occured
493 <dt><a name="UnifiedIO.is_file"></a><strong>UnifiedIO:is_file</strong> ()</dt>
496 Test whether the I/O-Descriptor is a file.
504 <h3>Return value:</h3>
514 <dt><a name="UnifiedIO.is_socket"></a><strong>UnifiedIO:is_socket</strong> ()</dt>
517 Test whether the I/O-Descriptor is a socket.
525 <h3>Return value:</h3>
535 <dt><a name="UnifiedIO.is_tls_socket"></a><strong>UnifiedIO:is_tls_socket</strong> ()</dt>
538 Test whether the I/O-Descriptor is a TLS socket.
546 <h3>Return value:</h3>
556 <dt><a name="UnifiedIO.linesource"></a><strong>UnifiedIO:linesource</strong> (limit)</dt>
559 Create a line-based iterator.
560 Lines may end with either \n or \r\n, these control chars are not included
579 <li>This function uses the low-level read function of the descriptor.
581 <li><strong>Note:</strong> This function uses an internal buffer to read
582 ahead. Do NOT mix calls to read(all) and the returned iterator. If you want
583 to stop reading line-based and want to use the read(all) functions instead
584 you can pass "true" to the iterator which will flush the buffer
585 and return the bufferd data.
587 <li>If the limit parameter is ommited, this function uses the nixio
588 buffersize (8192B by default).
590 <li>If the descriptor is non-blocking the iterator may fail with EAGAIN.
592 <li>The iterator can be used as an LTN12 source.
598 <h3>Return value:</h3>
608 <dt><a name="UnifiedIO.readall"></a><strong>UnifiedIO:readall</strong> (length)</dt>
611 Read a block of data and wait until all data is available.
618 length: Bytes to read (optional)
629 <li>This function uses the low-level read function of the descriptor.
631 <li>If the length parameter is ommited, this function returns all data
632 that can be read before an end-of-file, end-of-stream, connection shutdown
635 <li>If the descriptor is non-blocking this function may fail with EAGAIN.
641 <h3>Return values:</h3>
644 <li>data that was successfully read if no error occured
646 <li>- reserved for error code -
648 <li>- reserved for error message -
650 <li>data that was successfully read even if an error occured
661 <dt><a name="UnifiedIO.sink"></a><strong>UnifiedIO:sink</strong> (close_when_done)</dt>
665 This sink will simply write all data that it receives and optionally
666 close the descriptor afterwards.
673 close_when_done: (optional, boolean)
684 <li>This function uses the writeall function of the descriptor.
686 <li>If the descriptor is non-blocking the sink may fail with EAGAIN.
688 <li>The iterator can be used as an LTN12 sink.
694 <h3>Return value:</h3>
704 <dt><a name="UnifiedIO.writeall"></a><strong>UnifiedIO:writeall</strong> (block)</dt>
707 Write a block of data and wait until all data is written.
714 block: Bytes to write
725 <li>This function uses the low-level write function of the descriptor.
727 <li>If the descriptor is non-blocking this function may fail with EAGAIN.
733 <h3>Return values:</h3>
736 <li>bytes that were successfully written if no error occured
738 <li>- reserved for error code -
740 <li>- reserved for error message -
742 <li>bytes that were successfully written even if an error occured
757 </div> <!-- id="content" -->
759 </div> <!-- id="main" -->
762 <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
763 </div> <!-- id="about" -->
765 </div> <!-- id="container" -->