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.conditionals.html">luci.http.conditionals</a>
50 <a href="../modules/luci.http.date.html">luci.http.date</a>
54 <a href="../modules/luci.http.mime.html">luci.http.mime</a>
58 <a href="../modules/luci.i18n.html">luci.i18n</a>
62 <a href="../modules/luci.ip.html">luci.ip</a>
66 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
70 <a href="../modules/luci.json.html">luci.json</a>
74 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
78 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
82 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
86 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
90 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
94 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
98 <a href="../modules/luci.sys.html">luci.sys</a>
102 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
106 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
110 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
114 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
118 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
122 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
126 <a href="../modules/luci.util.html">luci.util</a>
130 <a href="../modules/nixio.html">nixio</a>
134 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
138 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
142 <a href="../modules/nixio.File.html">nixio.File</a>
146 <a href="../modules/nixio.README.html">nixio.README</a>
150 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
154 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
158 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
161 <li><strong>nixio.UnifiedIO</strong></li>
164 <a href="../modules/nixio.bin.html">nixio.bin</a>
168 <a href="../modules/nixio.bit.html">nixio.bit</a>
172 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
176 <a href="../modules/nixio.fs.html">nixio.fs</a>
191 </div><!-- id="navigation" -->
195 <h1>Object Instance <code>nixio.UnifiedIO</code></h1>
198 Unified high-level I/O utility API for Files, Sockets and TLS-Sockets.
199 These functions are added to the object function tables by doing <strong>
200 require "nixio.util"</strong>, can be used on all nixio IO Descriptors and
201 are based on the shared low-level read() and write() functions.</p>
210 <table class="function_list">
213 <td class="name" nowrap><a href="#UnifiedIO.blocksource">UnifiedIO:blocksource</a> (blocksize, limit)</td>
215 Create a block-based iterator.</td>
219 <td class="name" nowrap><a href="#UnifiedIO.close">UnifiedIO:close</a> ()</td>
221 Close the descriptor.</td>
225 <td class="name" nowrap><a href="#UnifiedIO.copy">UnifiedIO:copy</a> (fdout, size)</td>
227 Copy data from the current descriptor to another one.</td>
231 <td class="name" nowrap><a href="#UnifiedIO.copyz">UnifiedIO:copyz</a> (fdout, size)</td>
233 Copy data from the current descriptor to another one using kernel-space
234 copying if possible.</td>
238 <td class="name" nowrap><a href="#UnifiedIO.is_file">UnifiedIO:is_file</a> ()</td>
240 Test whether the I/O-Descriptor is a file.</td>
244 <td class="name" nowrap><a href="#UnifiedIO.is_socket">UnifiedIO:is_socket</a> ()</td>
246 Test whether the I/O-Descriptor is a socket.</td>
250 <td class="name" nowrap><a href="#UnifiedIO.is_tls_socket">UnifiedIO:is_tls_socket</a> ()</td>
252 Test whether the I/O-Descriptor is a TLS socket.</td>
256 <td class="name" nowrap><a href="#UnifiedIO.linesource">UnifiedIO:linesource</a> (limit)</td>
258 Create a line-based iterator.</td>
262 <td class="name" nowrap><a href="#UnifiedIO.readall">UnifiedIO:readall</a> (length)</td>
264 Read a block of data and wait until all data is available.</td>
268 <td class="name" nowrap><a href="#UnifiedIO.sink">UnifiedIO:sink</a> (close_when_done)</td>
274 <td class="name" nowrap><a href="#UnifiedIO.writeall">UnifiedIO:writeall</a> (block)</td>
276 Write a block of data and wait until all data is written.</td>
290 <h2><a name="functions"></a>Functions</h2>
291 <dl class="function">
295 <dt><a name="UnifiedIO.blocksource"></a><strong>UnifiedIO:blocksource</strong> (blocksize, limit)</dt>
298 Create a block-based iterator.
305 blocksize: Advisory blocksize (optional)
309 limit: Amount of data to consume (optional)
320 <li>This function uses the low-level read function of the descriptor.
322 <li>The blocksize given is only advisory and to be seen as an upper limit,
323 if an underlying read returns less bytes the chunk is nevertheless returned.
325 <li>If the limit parameter is omitted, the iterator returns data
326 until an end-of-file, end-of-stream, connection shutdown or similar happens.
328 <li>The iterator will not buffer so it is safe to mix with calls to read.
330 <li>If the descriptor is non-blocking the iterator may fail with EAGAIN.
332 <li>The iterator can be used as an LTN12 source.
338 <h3>Return value:</h3>
348 <dt><a name="UnifiedIO.close"></a><strong>UnifiedIO:close</strong> ()</dt>
351 Close the descriptor.
358 If the descriptor is a TLS-socket the underlying descriptor is
359 closed without touching the TLS connection.
363 <h3>Return value:</h3>
373 <dt><a name="UnifiedIO.copy"></a><strong>UnifiedIO:copy</strong> (fdout, size)</dt>
376 Copy data from the current descriptor to another one.
383 fdout: Target Descriptor
387 size: Bytes to copy (optional)
398 <li>This function uses the blocksource function of the source descriptor
399 and the sink function of the target descriptor.
401 <li>If the limit parameter is omitted, data is copied
402 until an end-of-file, end-of-stream, connection shutdown or similar happens.
404 <li>If the descriptor is non-blocking the function may fail with EAGAIN.
410 <h3>Return values:</h3>
413 <li>bytes that were successfully written if no error occurred
415 <li>- reserved for error code -
417 <li>- reserved for error message -
419 <li>bytes that were successfully written even if an error occurred
430 <dt><a name="UnifiedIO.copyz"></a><strong>UnifiedIO:copyz</strong> (fdout, size)</dt>
433 Copy data from the current descriptor to another one using kernel-space
441 fdout: Target Descriptor
445 size: Bytes to copy (optional)
456 <li>This function uses the sendfile() syscall to copy the data or the
457 blocksource function of the source descriptor and the sink function
458 of the target descriptor as a fallback mechanism.
460 <li>If the limit parameter is omitted, data is copied
461 until an end-of-file, end-of-stream, connection shutdown or similar happens.
463 <li>If the descriptor is non-blocking the function may fail with EAGAIN.
469 <h3>Return values:</h3>
472 <li>bytes that were successfully written if no error occurred
474 <li>- reserved for error code -
476 <li>- reserved for error message -
478 <li>bytes that were successfully written even if an error occurred
489 <dt><a name="UnifiedIO.is_file"></a><strong>UnifiedIO:is_file</strong> ()</dt>
492 Test whether the I/O-Descriptor is a file.
500 <h3>Return value:</h3>
510 <dt><a name="UnifiedIO.is_socket"></a><strong>UnifiedIO:is_socket</strong> ()</dt>
513 Test whether the I/O-Descriptor is a socket.
521 <h3>Return value:</h3>
531 <dt><a name="UnifiedIO.is_tls_socket"></a><strong>UnifiedIO:is_tls_socket</strong> ()</dt>
534 Test whether the I/O-Descriptor is a TLS socket.
542 <h3>Return value:</h3>
552 <dt><a name="UnifiedIO.linesource"></a><strong>UnifiedIO:linesource</strong> (limit)</dt>
555 Create a line-based iterator.
556 Lines may end with either \n or \r\n, these control chars are not included
575 <li>This function uses the low-level read function of the descriptor.
577 <li><strong>Note:</strong> This function uses an internal buffer to read
578 ahead. Do NOT mix calls to read(all) and the returned iterator. If you want
579 to stop reading line-based and want to use the read(all) functions instead
580 you can pass "true" to the iterator which will flush the buffer
581 and return the bufferd data.
583 <li>If the limit parameter is omitted, this function uses the nixio
584 buffersize (8192B by default).
586 <li>If the descriptor is non-blocking the iterator may fail with EAGAIN.
588 <li>The iterator can be used as an LTN12 source.
594 <h3>Return value:</h3>
604 <dt><a name="UnifiedIO.readall"></a><strong>UnifiedIO:readall</strong> (length)</dt>
607 Read a block of data and wait until all data is available.
614 length: Bytes to read (optional)
625 <li>This function uses the low-level read function of the descriptor.
627 <li>If the length parameter is omitted, this function returns all data
628 that can be read before an end-of-file, end-of-stream, connection shutdown
631 <li>If the descriptor is non-blocking this function may fail with EAGAIN.
637 <h3>Return values:</h3>
640 <li>data that was successfully read if no error occurred
642 <li>- reserved for error code -
644 <li>- reserved for error message -
646 <li>data that was successfully read even if an error occurred
657 <dt><a name="UnifiedIO.sink"></a><strong>UnifiedIO:sink</strong> (close_when_done)</dt>
661 This sink will simply write all data that it receives and optionally
662 close the descriptor afterwards.
669 close_when_done: (optional, boolean)
680 <li>This function uses the writeall function of the descriptor.
682 <li>If the descriptor is non-blocking the sink may fail with EAGAIN.
684 <li>The iterator can be used as an LTN12 sink.
690 <h3>Return value:</h3>
700 <dt><a name="UnifiedIO.writeall"></a><strong>UnifiedIO:writeall</strong> (block)</dt>
703 Write a block of data and wait until all data is written.
710 block: Bytes to write
721 <li>This function uses the low-level write function of the descriptor.
723 <li>If the descriptor is non-blocking this function may fail with EAGAIN.
729 <h3>Return values:</h3>
732 <li>bytes that were successfully written if no error occurred
734 <li>- reserved for error code -
736 <li>- reserved for error message -
738 <li>bytes that were successfully written even if an error occurred
753 </div> <!-- id="content" -->
755 </div> <!-- id="main" -->
758 <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>
759 </div> <!-- id="about" -->
761 </div> <!-- id="container" -->