nixio.UnifiedIO.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  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"/-->
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo"></div>
  13. <div id="product_name"><big><b></b></big></div>
  14. <div id="product_description"></div>
  15. </div> <!-- id="product" -->
  16. <div id="main">
  17. <div id="navigation">
  18. <h1>LuaDoc</h1>
  19. <ul>
  20. <li><a href="../index.html">Index</a></li>
  21. </ul>
  22. <!-- Module list -->
  23. <h1>Modules</h1>
  24. <ul>
  25. <li>
  26. <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
  27. </li>
  28. <li>
  29. <a href="../modules/luci.http.html">luci.http</a>
  30. </li>
  31. <li>
  32. <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
  33. </li>
  34. <li>
  35. <a href="../modules/luci.http.date.html">luci.http.date</a>
  36. </li>
  37. <li>
  38. <a href="../modules/luci.http.mime.html">luci.http.mime</a>
  39. </li>
  40. <li>
  41. <a href="../modules/luci.i18n.html">luci.i18n</a>
  42. </li>
  43. <li>
  44. <a href="../modules/luci.ip.html">luci.ip</a>
  45. </li>
  46. <li>
  47. <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
  48. </li>
  49. <li>
  50. <a href="../modules/luci.json.html">luci.json</a>
  51. </li>
  52. <li>
  53. <a href="../modules/luci.jsonc.html">luci.jsonc</a>
  54. </li>
  55. <li>
  56. <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
  57. </li>
  58. <li>
  59. <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
  60. </li>
  61. <li>
  62. <a href="../modules/luci.model.uci.html">luci.model.uci</a>
  63. </li>
  64. <li>
  65. <a href="../modules/luci.rpcc.html">luci.rpcc</a>
  66. </li>
  67. <li>
  68. <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
  69. </li>
  70. <li>
  71. <a href="../modules/luci.sys.html">luci.sys</a>
  72. </li>
  73. <li>
  74. <a href="../modules/luci.sys.init.html">luci.sys.init</a>
  75. </li>
  76. <li>
  77. <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
  78. </li>
  79. <li>
  80. <a href="../modules/luci.sys.net.html">luci.sys.net</a>
  81. </li>
  82. <li>
  83. <a href="../modules/luci.sys.process.html">luci.sys.process</a>
  84. </li>
  85. <li>
  86. <a href="../modules/luci.sys.user.html">luci.sys.user</a>
  87. </li>
  88. <li>
  89. <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
  90. </li>
  91. <li>
  92. <a href="../modules/luci.util.html">luci.util</a>
  93. </li>
  94. <li>
  95. <a href="../modules/nixio.html">nixio</a>
  96. </li>
  97. <li>
  98. <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
  99. </li>
  100. <li>
  101. <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
  102. </li>
  103. <li>
  104. <a href="../modules/nixio.File.html">nixio.File</a>
  105. </li>
  106. <li>
  107. <a href="../modules/nixio.README.html">nixio.README</a>
  108. </li>
  109. <li>
  110. <a href="../modules/nixio.Socket.html">nixio.Socket</a>
  111. </li>
  112. <li>
  113. <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
  114. </li>
  115. <li>
  116. <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
  117. </li>
  118. <li><strong>nixio.UnifiedIO</strong></li>
  119. <li>
  120. <a href="../modules/nixio.bin.html">nixio.bin</a>
  121. </li>
  122. <li>
  123. <a href="../modules/nixio.bit.html">nixio.bit</a>
  124. </li>
  125. <li>
  126. <a href="../modules/nixio.crypto.html">nixio.crypto</a>
  127. </li>
  128. <li>
  129. <a href="../modules/nixio.fs.html">nixio.fs</a>
  130. </li>
  131. </ul>
  132. <!-- File list -->
  133. </div><!-- id="navigation" -->
  134. <div id="content">
  135. <h1>Object Instance <code>nixio.UnifiedIO</code></h1>
  136. <p>
  137. Unified high-level I/O utility API for Files, Sockets and TLS-Sockets.
  138. These functions are added to the object function tables by doing <strong>
  139. require "nixio.util"</strong>, can be used on all nixio IO Descriptors and
  140. are based on the shared low-level read() and write() functions.</p>
  141. <h2>Functions</h2>
  142. <table class="function_list">
  143. <tr>
  144. <td class="name" nowrap><a href="#UnifiedIO.blocksource">UnifiedIO:blocksource</a>&nbsp;(blocksize, limit)</td>
  145. <td class="summary">
  146. Create a block-based iterator.</td>
  147. </tr>
  148. <tr>
  149. <td class="name" nowrap><a href="#UnifiedIO.close">UnifiedIO:close</a>&nbsp;()</td>
  150. <td class="summary">
  151. Close the descriptor.</td>
  152. </tr>
  153. <tr>
  154. <td class="name" nowrap><a href="#UnifiedIO.copy">UnifiedIO:copy</a>&nbsp;(fdout, size)</td>
  155. <td class="summary">
  156. Copy data from the current descriptor to another one.</td>
  157. </tr>
  158. <tr>
  159. <td class="name" nowrap><a href="#UnifiedIO.copyz">UnifiedIO:copyz</a>&nbsp;(fdout, size)</td>
  160. <td class="summary">
  161. Copy data from the current descriptor to another one using kernel-space
  162. copying if possible.</td>
  163. </tr>
  164. <tr>
  165. <td class="name" nowrap><a href="#UnifiedIO.is_file">UnifiedIO:is_file</a>&nbsp;()</td>
  166. <td class="summary">
  167. Test whether the I/O-Descriptor is a file.</td>
  168. </tr>
  169. <tr>
  170. <td class="name" nowrap><a href="#UnifiedIO.is_socket">UnifiedIO:is_socket</a>&nbsp;()</td>
  171. <td class="summary">
  172. Test whether the I/O-Descriptor is a socket.</td>
  173. </tr>
  174. <tr>
  175. <td class="name" nowrap><a href="#UnifiedIO.is_tls_socket">UnifiedIO:is_tls_socket</a>&nbsp;()</td>
  176. <td class="summary">
  177. Test whether the I/O-Descriptor is a TLS socket.</td>
  178. </tr>
  179. <tr>
  180. <td class="name" nowrap><a href="#UnifiedIO.linesource">UnifiedIO:linesource</a>&nbsp;(limit)</td>
  181. <td class="summary">
  182. Create a line-based iterator.</td>
  183. </tr>
  184. <tr>
  185. <td class="name" nowrap><a href="#UnifiedIO.readall">UnifiedIO:readall</a>&nbsp;(length)</td>
  186. <td class="summary">
  187. Read a block of data and wait until all data is available.</td>
  188. </tr>
  189. <tr>
  190. <td class="name" nowrap><a href="#UnifiedIO.sink">UnifiedIO:sink</a>&nbsp;(close_when_done)</td>
  191. <td class="summary">
  192. Create a sink.</td>
  193. </tr>
  194. <tr>
  195. <td class="name" nowrap><a href="#UnifiedIO.writeall">UnifiedIO:writeall</a>&nbsp;(block)</td>
  196. <td class="summary">
  197. Write a block of data and wait until all data is written.</td>
  198. </tr>
  199. </table>
  200. <br/>
  201. <br/>
  202. <h2><a name="functions"></a>Functions</h2>
  203. <dl class="function">
  204. <dt><a name="UnifiedIO.blocksource"></a><strong>UnifiedIO:blocksource</strong>&nbsp;(blocksize, limit)</dt>
  205. <dd>
  206. Create a block-based iterator.
  207. <h3>Parameters</h3>
  208. <ul>
  209. <li>
  210. blocksize: Advisory blocksize (optional)
  211. </li>
  212. <li>
  213. limit: Amount of data to consume (optional)
  214. </li>
  215. </ul>
  216. <h3>Usage</h3>
  217. <ul>
  218. <li>This function uses the low-level read function of the descriptor.
  219. <li>The blocksize given is only advisory and to be seen as an upper limit,
  220. if an underlying read returns less bytes the chunk is nevertheless returned.
  221. <li>If the limit parameter is omitted, the iterator returns data
  222. until an end-of-file, end-of-stream, connection shutdown or similar happens.
  223. <li>The iterator will not buffer so it is safe to mix with calls to read.
  224. <li>If the descriptor is non-blocking the iterator may fail with EAGAIN.
  225. <li>The iterator can be used as an LTN12 source.
  226. </ul>
  227. <h3>Return value:</h3>
  228. Block-based Iterator
  229. </dd>
  230. <dt><a name="UnifiedIO.close"></a><strong>UnifiedIO:close</strong>&nbsp;()</dt>
  231. <dd>
  232. Close the descriptor.
  233. <h3>Usage:</h3>
  234. If the descriptor is a TLS-socket the underlying descriptor is
  235. closed without touching the TLS connection.
  236. <h3>Return value:</h3>
  237. true
  238. </dd>
  239. <dt><a name="UnifiedIO.copy"></a><strong>UnifiedIO:copy</strong>&nbsp;(fdout, size)</dt>
  240. <dd>
  241. Copy data from the current descriptor to another one.
  242. <h3>Parameters</h3>
  243. <ul>
  244. <li>
  245. fdout: Target Descriptor
  246. </li>
  247. <li>
  248. size: Bytes to copy (optional)
  249. </li>
  250. </ul>
  251. <h3>Usage</h3>
  252. <ul>
  253. <li>This function uses the blocksource function of the source descriptor
  254. and the sink function of the target descriptor.
  255. <li>If the limit parameter is omitted, data is copied
  256. until an end-of-file, end-of-stream, connection shutdown or similar happens.
  257. <li>If the descriptor is non-blocking the function may fail with EAGAIN.
  258. </ul>
  259. <h3>Return values:</h3>
  260. <ol>
  261. <li>bytes that were successfully written if no error occurred
  262. <li>- reserved for error code -
  263. <li>- reserved for error message -
  264. <li>bytes that were successfully written even if an error occurred
  265. </ol>
  266. </dd>
  267. <dt><a name="UnifiedIO.copyz"></a><strong>UnifiedIO:copyz</strong>&nbsp;(fdout, size)</dt>
  268. <dd>
  269. Copy data from the current descriptor to another one using kernel-space
  270. copying if possible.
  271. <h3>Parameters</h3>
  272. <ul>
  273. <li>
  274. fdout: Target Descriptor
  275. </li>
  276. <li>
  277. size: Bytes to copy (optional)
  278. </li>
  279. </ul>
  280. <h3>Usage</h3>
  281. <ul>
  282. <li>This function uses the sendfile() syscall to copy the data or the
  283. blocksource function of the source descriptor and the sink function
  284. of the target descriptor as a fallback mechanism.
  285. <li>If the limit parameter is omitted, data is copied
  286. until an end-of-file, end-of-stream, connection shutdown or similar happens.
  287. <li>If the descriptor is non-blocking the function may fail with EAGAIN.
  288. </ul>
  289. <h3>Return values:</h3>
  290. <ol>
  291. <li>bytes that were successfully written if no error occurred
  292. <li>- reserved for error code -
  293. <li>- reserved for error message -
  294. <li>bytes that were successfully written even if an error occurred
  295. </ol>
  296. </dd>
  297. <dt><a name="UnifiedIO.is_file"></a><strong>UnifiedIO:is_file</strong>&nbsp;()</dt>
  298. <dd>
  299. Test whether the I/O-Descriptor is a file.
  300. <h3>Return value:</h3>
  301. boolean
  302. </dd>
  303. <dt><a name="UnifiedIO.is_socket"></a><strong>UnifiedIO:is_socket</strong>&nbsp;()</dt>
  304. <dd>
  305. Test whether the I/O-Descriptor is a socket.
  306. <h3>Return value:</h3>
  307. boolean
  308. </dd>
  309. <dt><a name="UnifiedIO.is_tls_socket"></a><strong>UnifiedIO:is_tls_socket</strong>&nbsp;()</dt>
  310. <dd>
  311. Test whether the I/O-Descriptor is a TLS socket.
  312. <h3>Return value:</h3>
  313. boolean
  314. </dd>
  315. <dt><a name="UnifiedIO.linesource"></a><strong>UnifiedIO:linesource</strong>&nbsp;(limit)</dt>
  316. <dd>
  317. Create a line-based iterator.
  318. Lines may end with either \n or \r\n, these control chars are not included
  319. in the return value.
  320. <h3>Parameters</h3>
  321. <ul>
  322. <li>
  323. limit: Line limit
  324. </li>
  325. </ul>
  326. <h3>Usage</h3>
  327. <ul>
  328. <li>This function uses the low-level read function of the descriptor.
  329. <li><strong>Note:</strong> This function uses an internal buffer to read
  330. ahead. Do NOT mix calls to read(all) and the returned iterator. If you want
  331. to stop reading line-based and want to use the read(all) functions instead
  332. you can pass "true" to the iterator which will flush the buffer
  333. and return the bufferd data.
  334. <li>If the limit parameter is omitted, this function uses the nixio
  335. buffersize (8192B by default).
  336. <li>If the descriptor is non-blocking the iterator may fail with EAGAIN.
  337. <li>The iterator can be used as an LTN12 source.
  338. </ul>
  339. <h3>Return value:</h3>
  340. Line-based Iterator
  341. </dd>
  342. <dt><a name="UnifiedIO.readall"></a><strong>UnifiedIO:readall</strong>&nbsp;(length)</dt>
  343. <dd>
  344. Read a block of data and wait until all data is available.
  345. <h3>Parameters</h3>
  346. <ul>
  347. <li>
  348. length: Bytes to read (optional)
  349. </li>
  350. </ul>
  351. <h3>Usage</h3>
  352. <ul>
  353. <li>This function uses the low-level read function of the descriptor.
  354. <li>If the length parameter is omitted, this function returns all data
  355. that can be read before an end-of-file, end-of-stream, connection shutdown
  356. or similar happens.
  357. <li>If the descriptor is non-blocking this function may fail with EAGAIN.
  358. </ul>
  359. <h3>Return values:</h3>
  360. <ol>
  361. <li>data that was successfully read if no error occurred
  362. <li>- reserved for error code -
  363. <li>- reserved for error message -
  364. <li>data that was successfully read even if an error occurred
  365. </ol>
  366. </dd>
  367. <dt><a name="UnifiedIO.sink"></a><strong>UnifiedIO:sink</strong>&nbsp;(close_when_done)</dt>
  368. <dd>
  369. Create a sink.
  370. This sink will simply write all data that it receives and optionally
  371. close the descriptor afterwards.
  372. <h3>Parameters</h3>
  373. <ul>
  374. <li>
  375. close_when_done: (optional, boolean)
  376. </li>
  377. </ul>
  378. <h3>Usage</h3>
  379. <ul>
  380. <li>This function uses the writeall function of the descriptor.
  381. <li>If the descriptor is non-blocking the sink may fail with EAGAIN.
  382. <li>The iterator can be used as an LTN12 sink.
  383. </ul>
  384. <h3>Return value:</h3>
  385. Sink
  386. </dd>
  387. <dt><a name="UnifiedIO.writeall"></a><strong>UnifiedIO:writeall</strong>&nbsp;(block)</dt>
  388. <dd>
  389. Write a block of data and wait until all data is written.
  390. <h3>Parameters</h3>
  391. <ul>
  392. <li>
  393. block: Bytes to write
  394. </li>
  395. </ul>
  396. <h3>Usage</h3>
  397. <ul>
  398. <li>This function uses the low-level write function of the descriptor.
  399. <li>If the descriptor is non-blocking this function may fail with EAGAIN.
  400. </ul>
  401. <h3>Return values:</h3>
  402. <ol>
  403. <li>bytes that were successfully written if no error occurred
  404. <li>- reserved for error code -
  405. <li>- reserved for error message -
  406. <li>bytes that were successfully written even if an error occurred
  407. </ol>
  408. </dd>
  409. </dl>
  410. </div> <!-- id="content" -->
  411. </div> <!-- id="main" -->
  412. <div id="about">
  413. <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>
  414. </div> <!-- id="about" -->
  415. </div> <!-- id="container" -->
  416. </body>
  417. </html>