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.protocol.html">luci.http.protocol</a>
46 <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
50 <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
54 <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.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.jsonc.html">luci.jsonc</a>
74 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
78 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
82 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
86 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
90 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
94 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
98 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
102 <a href="../modules/nixio.html">nixio</a>
106 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
110 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
114 <a href="../modules/nixio.File.html">nixio.File</a>
118 <a href="../modules/nixio.README.html">nixio.README</a>
122 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
126 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
130 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
133 <li><strong>nixio.UnifiedIO</strong></li>
136 <a href="../modules/nixio.bin.html">nixio.bin</a>
140 <a href="../modules/nixio.bit.html">nixio.bit</a>
144 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
148 <a href="../modules/nixio.fs.html">nixio.fs</a>
163 </div><!-- id="navigation" -->
167 <h1>Object Instance <code>nixio.UnifiedIO</code></h1>
170 Unified high-level I/O utility API for Files, Sockets and TLS-Sockets.
171 These functions are added to the object function tables by doing <strong>
172 require "nixio.util"</strong>, can be used on all nixio IO Descriptors and
173 are based on the shared low-level read() and write() functions.</p>
182 <table class="function_list">
185 <td class="name" nowrap><a href="#UnifiedIO.blocksource">UnifiedIO:blocksource</a> (blocksize, limit)</td>
187 Create a block-based iterator.</td>
191 <td class="name" nowrap><a href="#UnifiedIO.close">UnifiedIO:close</a> ()</td>
193 Close the descriptor.</td>
197 <td class="name" nowrap><a href="#UnifiedIO.copy">UnifiedIO:copy</a> (fdout, size)</td>
199 Copy data from the current descriptor to another one.</td>
203 <td class="name" nowrap><a href="#UnifiedIO.copyz">UnifiedIO:copyz</a> (fdout, size)</td>
205 Copy data from the current descriptor to another one using kernel-space
206 copying if possible.</td>
210 <td class="name" nowrap><a href="#UnifiedIO.is_file">UnifiedIO:is_file</a> ()</td>
212 Test whether the I/O-Descriptor is a file.</td>
216 <td class="name" nowrap><a href="#UnifiedIO.is_socket">UnifiedIO:is_socket</a> ()</td>
218 Test whether the I/O-Descriptor is a socket.</td>
222 <td class="name" nowrap><a href="#UnifiedIO.is_tls_socket">UnifiedIO:is_tls_socket</a> ()</td>
224 Test whether the I/O-Descriptor is a TLS socket.</td>
228 <td class="name" nowrap><a href="#UnifiedIO.linesource">UnifiedIO:linesource</a> (limit)</td>
230 Create a line-based iterator.</td>
234 <td class="name" nowrap><a href="#UnifiedIO.readall">UnifiedIO:readall</a> (length)</td>
236 Read a block of data and wait until all data is available.</td>
240 <td class="name" nowrap><a href="#UnifiedIO.sink">UnifiedIO:sink</a> (close_when_done)</td>
246 <td class="name" nowrap><a href="#UnifiedIO.writeall">UnifiedIO:writeall</a> (block)</td>
248 Write a block of data and wait until all data is written.</td>
262 <h2><a name="functions"></a>Functions</h2>
263 <dl class="function">
267 <dt><a name="UnifiedIO.blocksource"></a><strong>UnifiedIO:blocksource</strong> (blocksize, limit)</dt>
270 Create a block-based iterator.
277 blocksize: Advisory blocksize (optional)
281 limit: Amount of data to consume (optional)
292 <li>This function uses the low-level read function of the descriptor.
294 <li>The blocksize given is only advisory and to be seen as an upper limit,
295 if an underlying read returns less bytes the chunk is nevertheless returned.
297 <li>If the limit parameter is ommited, the iterator returns data
298 until an end-of-file, end-of-stream, connection shutdown or similar happens.
300 <li>The iterator will not buffer so it is safe to mix with calls to read.
302 <li>If the descriptor is non-blocking the iterator may fail with EAGAIN.
304 <li>The iterator can be used as an LTN12 source.
310 <h3>Return value:</h3>
320 <dt><a name="UnifiedIO.close"></a><strong>UnifiedIO:close</strong> ()</dt>
323 Close the descriptor.
330 If the descriptor is a TLS-socket the underlying descriptor is
331 closed without touching the TLS connection.
335 <h3>Return value:</h3>
345 <dt><a name="UnifiedIO.copy"></a><strong>UnifiedIO:copy</strong> (fdout, size)</dt>
348 Copy data from the current descriptor to another one.
355 fdout: Target Descriptor
359 size: Bytes to copy (optional)
370 <li>This function uses the blocksource function of the source descriptor
371 and the sink function of the target descriptor.
373 <li>If the limit parameter is ommited, data is copied
374 until an end-of-file, end-of-stream, connection shutdown or similar happens.
376 <li>If the descriptor is non-blocking the function may fail with EAGAIN.
382 <h3>Return values:</h3>
385 <li>bytes that were successfully written if no error occured
387 <li>- reserved for error code -
389 <li>- reserved for error message -
391 <li>bytes that were successfully written even if an error occured
402 <dt><a name="UnifiedIO.copyz"></a><strong>UnifiedIO:copyz</strong> (fdout, size)</dt>
405 Copy data from the current descriptor to another one using kernel-space
413 fdout: Target Descriptor
417 size: Bytes to copy (optional)
428 <li>This function uses the sendfile() syscall to copy the data or the
429 blocksource function of the source descriptor and the sink function
430 of the target descriptor as a fallback mechanism.
432 <li>If the limit parameter is ommited, data is copied
433 until an end-of-file, end-of-stream, connection shutdown or similar happens.
435 <li>If the descriptor is non-blocking the function may fail with EAGAIN.
441 <h3>Return values:</h3>
444 <li>bytes that were successfully written if no error occured
446 <li>- reserved for error code -
448 <li>- reserved for error message -
450 <li>bytes that were successfully written even if an error occured
461 <dt><a name="UnifiedIO.is_file"></a><strong>UnifiedIO:is_file</strong> ()</dt>
464 Test whether the I/O-Descriptor is a file.
472 <h3>Return value:</h3>
482 <dt><a name="UnifiedIO.is_socket"></a><strong>UnifiedIO:is_socket</strong> ()</dt>
485 Test whether the I/O-Descriptor is a socket.
493 <h3>Return value:</h3>
503 <dt><a name="UnifiedIO.is_tls_socket"></a><strong>UnifiedIO:is_tls_socket</strong> ()</dt>
506 Test whether the I/O-Descriptor is a TLS socket.
514 <h3>Return value:</h3>
524 <dt><a name="UnifiedIO.linesource"></a><strong>UnifiedIO:linesource</strong> (limit)</dt>
527 Create a line-based iterator.
528 Lines may end with either \n or \r\n, these control chars are not included
547 <li>This function uses the low-level read function of the descriptor.
549 <li><strong>Note:</strong> This function uses an internal buffer to read
550 ahead. Do NOT mix calls to read(all) and the returned iterator. If you want
551 to stop reading line-based and want to use the read(all) functions instead
552 you can pass "true" to the iterator which will flush the buffer
553 and return the bufferd data.
555 <li>If the limit parameter is ommited, this function uses the nixio
556 buffersize (8192B by default).
558 <li>If the descriptor is non-blocking the iterator may fail with EAGAIN.
560 <li>The iterator can be used as an LTN12 source.
566 <h3>Return value:</h3>
576 <dt><a name="UnifiedIO.readall"></a><strong>UnifiedIO:readall</strong> (length)</dt>
579 Read a block of data and wait until all data is available.
586 length: Bytes to read (optional)
597 <li>This function uses the low-level read function of the descriptor.
599 <li>If the length parameter is ommited, this function returns all data
600 that can be read before an end-of-file, end-of-stream, connection shutdown
603 <li>If the descriptor is non-blocking this function may fail with EAGAIN.
609 <h3>Return values:</h3>
612 <li>data that was successfully read if no error occured
614 <li>- reserved for error code -
616 <li>- reserved for error message -
618 <li>data that was successfully read even if an error occured
629 <dt><a name="UnifiedIO.sink"></a><strong>UnifiedIO:sink</strong> (close_when_done)</dt>
633 This sink will simply write all data that it receives and optionally
634 close the descriptor afterwards.
641 close_when_done: (optional, boolean)
652 <li>This function uses the writeall function of the descriptor.
654 <li>If the descriptor is non-blocking the sink may fail with EAGAIN.
656 <li>The iterator can be used as an LTN12 sink.
662 <h3>Return value:</h3>
672 <dt><a name="UnifiedIO.writeall"></a><strong>UnifiedIO:writeall</strong> (block)</dt>
675 Write a block of data and wait until all data is written.
682 block: Bytes to write
693 <li>This function uses the low-level write function of the descriptor.
695 <li>If the descriptor is non-blocking this function may fail with EAGAIN.
701 <h3>Return values:</h3>
704 <li>bytes that were successfully written if no error occured
706 <li>- reserved for error code -
708 <li>- reserved for error message -
710 <li>bytes that were successfully written even if an error occured
725 </div> <!-- id="content" -->
727 </div> <!-- id="main" -->
730 <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>
731 </div> <!-- id="about" -->
733 </div> <!-- id="container" -->