2
0

nixio.UnifiedIO.html 13 KB

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