luvref.txt 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899
  1. *luvref.txt* Nvim
  2. LUV REFERENCE MANUAL
  3. This file documents the Lua bindings for the LibUV library which is used for
  4. Nvim's event-loop and is accessible from Lua via |vim.loop| (e.g., |uv.version()|
  5. is exposed as `vim.loop.version()`).
  6. For information about this manual, see |luv-credits|.
  7. For further examples, see https://github.com/luvit/luv/tree/master/examples.
  8. ==============================================================================
  9. INTRODUCTION *luv* *luv-intro* *uv*
  10. The luv (https://github.com/luvit/luv) project provides access to the
  11. multi-platform support library libuv (https://github.com/libuv/libuv) in Lua
  12. code. It was primarily developed for the luvit
  13. (https://github.com/luvit/luvit) project as the built-in `uv` module, but can
  14. be used in other Lua environments.
  15. More information about the core libuv library can be found at the original
  16. libuv documentation page (https://docs.libuv.org/).
  17. TCP Echo Server Example~
  18. Here is a small example showing a TCP echo server:
  19. >
  20. local uv = vim.loop
  21. local server = uv.new_tcp()
  22. server:bind("127.0.0.1", 1337)
  23. server:listen(128, function (err)
  24. assert(not err, err)
  25. local client = uv.new_tcp()
  26. server:accept(client)
  27. client:read_start(function (err, chunk)
  28. assert(not err, err)
  29. if chunk then
  30. client:write(chunk)
  31. else
  32. client:shutdown()
  33. client:close()
  34. end
  35. end)
  36. end)
  37. print("TCP server listening at 127.0.0.1 port 1337")
  38. uv.run() -- an explicit run call is necessary outside of luvit
  39. <
  40. Module Layout~
  41. The luv library contains a single Lua module referred to hereafter as `uv` for
  42. simplicity. This module consists mostly of functions with names corresponding
  43. to their original libuv versions. For example, the libuv function
  44. `uv_tcp_bind` has a luv version at |uv.tcp_bind()|. Currently, only one
  45. non-function field exists: `uv.constants`, which is a table.
  46. Functions vs Methods~
  47. In addition to having simple functions, luv provides an optional method-style
  48. API. For example, `uv.tcp_bind(server, host, port)` can alternatively be
  49. called as `server:bind(host, port)` . Note that the first argument `server`
  50. becomes the object and `tcp_` is removed from the function name. Method forms
  51. are documented below where they exist.
  52. Synchronous vs Asynchronous Functions~
  53. Functions that accept a callback are asynchronous. These functions may
  54. immediately return results to the caller to indicate their initial status, but
  55. their final execution is deferred until at least the next libuv loop
  56. iteration. After completion, their callbacks are executed with any results
  57. passed to it.
  58. Functions that do not accept a callback are synchronous. These functions
  59. immediately return their results to the caller.
  60. Some (generally FS and DNS) functions can behave either synchronously or
  61. asynchronously. If a callback is provided to these functions, they behave
  62. asynchronously; if no callback is provided, they behave synchronously.
  63. Pseudo-Types~
  64. Some unique types are defined. These are not actual types in Lua, but they are
  65. used here to facilitate documenting consistent behavior:
  66. - `fail`: an assertable `nil, string, string` tuple (see |luv-error-handling|)
  67. - `callable`: a `function`; or a `table` or `userdata` with a `__call`
  68. metamethod
  69. - `buffer`: a `string` or a sequential `table` of `string`s
  70. - `threadargs`: variable arguments (`...`) of type `nil`, `boolean`, `number`,
  71. `string`, or `userdata`
  72. ==============================================================================
  73. CONTENTS *luv-contents*
  74. This documentation is mostly a retelling of the libuv API documentation
  75. (https://docs.libuv.org/en/v1.x/api.html) within the context of luv's Lua API.
  76. Low-level implementation details and unexposed C functions and types are not
  77. documented here except for when they are relevant to behavior seen in the Lua
  78. module.
  79. - |luv-error-handling| — Error handling
  80. - |luv-version-checking| — Version checking
  81. - |uv_loop_t| — Event loop
  82. - |uv_req_t| — Base request
  83. - |uv_handle_t| — Base handle
  84. - |uv_timer_t| — Timer handle
  85. - |uv_prepare_t| — Prepare handle
  86. - |uv_check_t| — Check handle
  87. - |uv_idle_t| — Idle handle
  88. - |uv_async_t| — Async handle
  89. - |uv_poll_t| — Poll handle
  90. - |uv_signal_t| — Signal handle
  91. - |uv_process_t| — Process handle
  92. - |uv_stream_t| — Stream handle
  93. - |uv_tcp_t| — TCP handle
  94. - |uv_pipe_t| — Pipe handle
  95. - |uv_tty_t| — TTY handle
  96. - |uv_udp_t| — UDP handle
  97. - |uv_fs_event_t| — FS Event handle
  98. - |uv_fs_poll_t| — FS Poll handle
  99. - |luv-file-system-operations| — File system operations
  100. - |luv-thread-pool-work-scheduling| — Thread pool work scheduling
  101. - |luv-dns-utility-functions| — DNS utility functions
  102. - |luv-threading-and-synchronization-utilities| — Threading and
  103. synchronization utilities
  104. - |luv-miscellaneous-utilities| — Miscellaneous utilities
  105. - |luv-metrics-operations| — Metrics operations
  106. ==============================================================================
  107. ERROR HANDLING *luv-error-handling*
  108. In libuv, errors are negative numbered constants; however, these errors and
  109. the functions used to handle them are not exposed to luv users. Instead, if an
  110. internal error is encountered, the luv function will return to the caller an
  111. assertable `nil, err, name` tuple.
  112. - `nil` idiomatically indicates failure
  113. - `err` is a string with the format `{name}: {message}`
  114. - `{name}` is the error name provided internally by `uv_err_name`
  115. - `{message}` is a human-readable message provided internally by
  116. `uv_strerror`
  117. - `name` is the same string used to construct `err`
  118. This tuple is referred to below as the `fail` pseudo-type.
  119. When a function is called successfully, it will return either a value that is
  120. relevant to the operation of the function, or the integer `0` to indicate
  121. success, or sometimes nothing at all. These cases are documented below.
  122. ==============================================================================
  123. VERSION CHECKING *luv-version-checking*
  124. uv.version() *uv.version()*
  125. Returns the libuv version packed into a single integer. 8 bits
  126. are used for each component, with the patch number stored in
  127. the 8 least significant bits. For example, this would be
  128. 0x010203 in libuv 1.2.3.
  129. Returns: `integer`
  130. uv.version_string() *uv.version_string()*
  131. Returns the libuv version number as a string. For example,
  132. this would be "1.2.3" in libuv 1.2.3. For non-release
  133. versions, the version suffix is included.
  134. Returns: `string`
  135. ==============================================================================
  136. `uv_loop_t` — Event loop *luv-event-loop* *uv_loop_t*
  137. The event loop is the central part of libuv's functionality. It takes care of
  138. polling for I/O and scheduling callbacks to be run based on different sources
  139. of events.
  140. In luv, there is an implicit uv loop for every Lua state that loads the
  141. library. You can use this library in an multi-threaded environment as long as
  142. each thread has it's own Lua state with its corresponding own uv loop. This
  143. loop is not directly exposed to users in the Lua module.
  144. uv.loop_close() *uv.loop_close()*
  145. Closes all internal loop resources. In normal execution, the
  146. loop will automatically be closed when it is garbage collected
  147. by Lua, so it is not necessary to explicitly call
  148. `loop_close()`. Call this function only after the loop has
  149. finished executing and all open handles and requests have been
  150. closed, or it will return `EBUSY`.
  151. Returns: `0` or `fail`
  152. uv.run([{mode}]) *uv.run()*
  153. Parameters:
  154. - `mode`: `string` or `nil` (default: `"default"`)
  155. This function runs the event loop. It will act differently
  156. depending on the specified mode:
  157. - `"default"`: Runs the event loop until there are no more
  158. active and referenced handles or requests. Returns `true`
  159. if |uv.stop()| was called and there are still active
  160. handles or requests. Returns `false` in all other cases.
  161. - `"once"`: Poll for I/O once. Note that this function
  162. blocks if there are no pending callbacks. Returns `false`
  163. when done (no active handles or requests left), or `true`
  164. if more callbacks are expected (meaning you should run the
  165. event loop again sometime in the future).
  166. - `"nowait"`: Poll for I/O once but don't block if there are
  167. no pending callbacks. Returns `false` if done (no active
  168. handles or requests left), or `true` if more callbacks are
  169. expected (meaning you should run the event loop again
  170. sometime in the future).
  171. Returns: `boolean` or `fail`
  172. Note: Luvit will implicitly call `uv.run()` after loading user
  173. code, but if you use the luv bindings directly, you need to
  174. call this after registering your initial set of event
  175. callbacks to start the event loop.
  176. uv.loop_configure({option}, {...}) *uv.loop_configure()*
  177. Parameters:
  178. - `option`: `string`
  179. - `...`: depends on `option`, see below
  180. Set additional loop options. You should normally call this
  181. before the first call to uv_run() unless mentioned otherwise.
  182. Supported options:
  183. - `"block_signal"`: Block a signal when polling for new
  184. events. The second argument to loop_configure() is the
  185. signal name (as a lowercase string) or the signal number.
  186. This operation is currently only implemented for
  187. `"sigprof"` signals, to suppress unnecessary wakeups when
  188. using a sampling profiler. Requesting other signals will
  189. fail with `EINVAL`.
  190. - `"metrics_idle_time"`: Accumulate the amount of idle time
  191. the event loop spends in the event provider. This option
  192. is necessary to use `metrics_idle_time()`.
  193. An example of a valid call to this function is:
  194. >
  195. uv.loop_configure("block_signal", "sigprof")
  196. <
  197. Returns: `0` or `fail`
  198. Note: Be prepared to handle the `ENOSYS` error; it means the
  199. loop option is not supported by the platform.
  200. uv.loop_mode() *uv.loop_mode()*
  201. If the loop is running, returns a string indicating the mode
  202. in use. If the loop is not running, `nil` is returned instead.
  203. Returns: `string` or `nil`
  204. uv.loop_alive() *uv.loop_alive()*
  205. Returns `true` if there are referenced active handles, active
  206. requests, or closing handles in the loop; otherwise, `false`.
  207. Returns: `boolean` or `fail`
  208. uv.stop() *uv.stop()*
  209. Stop the event loop, causing |uv.run()| to end as soon as
  210. possible. This will happen not sooner than the next loop
  211. iteration. If this function was called before blocking for
  212. I/O, the loop won't block for I/O on this iteration.
  213. Returns: Nothing.
  214. uv.backend_fd() *uv.backend_fd()*
  215. Get backend file descriptor. Only kqueue, epoll, and event
  216. ports are supported.
  217. This can be used in conjunction with `uv.run("nowait")` to
  218. poll in one thread and run the event loop's callbacks in
  219. another
  220. Returns: `integer` or `nil`
  221. Note: Embedding a kqueue fd in another kqueue pollset doesn't
  222. work on all platforms. It's not an error to add the fd but it
  223. never generates events.
  224. uv.backend_timeout() *uv.backend_timeout()*
  225. Get the poll timeout. The return value is in milliseconds, or
  226. -1 for no timeout.
  227. Returns: `integer`
  228. uv.now() *uv.now()*
  229. Returns the current timestamp in milliseconds. The timestamp
  230. is cached at the start of the event loop tick, see
  231. |uv.update_time()| for details and rationale.
  232. The timestamp increases monotonically from some arbitrary
  233. point in time. Don't make assumptions about the starting
  234. point, you will only get disappointed.
  235. Returns: `integer`
  236. Note: Use |uv.hrtime()| if you need sub-millisecond
  237. granularity.
  238. uv.update_time() *uv.update_time()*
  239. Update the event loop's concept of "now". Libuv caches the
  240. current time at the start of the event loop tick in order to
  241. reduce the number of time-related system calls.
  242. You won't normally need to call this function unless you have
  243. callbacks that block the event loop for longer periods of
  244. time, where "longer" is somewhat subjective but probably on
  245. the order of a millisecond or more.
  246. Returns: Nothing.
  247. uv.walk({callback}) *uv.walk()*
  248. Parameters:
  249. - `callback`: `callable`
  250. - `handle`: `userdata` for sub-type of |uv_handle_t|
  251. Walk the list of handles: `callback` will be executed with
  252. each handle.
  253. Returns: Nothing.
  254. >
  255. -- Example usage of uv.walk to close all handles that
  256. -- aren't already closing.
  257. uv.walk(function (handle)
  258. if not handle:is_closing() then
  259. handle:close()
  260. end
  261. end)
  262. <
  263. ==============================================================================
  264. `uv_req_t` — Base request *luv-base-request* *uv_req_t*
  265. `uv_req_t` is the base type for all libuv request types.
  266. uv.cancel({req}) *uv.cancel()*
  267. > method form `req:cancel()`
  268. Parameters:
  269. - `req`: `userdata` for sub-type of |uv_req_t|
  270. Cancel a pending request. Fails if the request is executing or
  271. has finished executing. Only cancellation of |uv_fs_t|,
  272. `uv_getaddrinfo_t`, `uv_getnameinfo_t` and `uv_work_t`
  273. requests is currently supported.
  274. Returns: `0` or `fail`
  275. uv.req_get_type({req}) *uv.req_get_type()*
  276. > method form `req:get_type()`
  277. Parameters:
  278. - `req`: `userdata` for sub-type of |uv_req_t|
  279. Returns the name of the struct for a given request (e.g.
  280. `"fs"` for |uv_fs_t|) and the libuv enum integer for the
  281. request's type (`uv_req_type`).
  282. Returns: `string, integer`
  283. ==============================================================================
  284. `uv_handle_t` — Base handle *luv-base-handle* *uv_handle_t*
  285. `uv_handle_t` is the base type for all libuv handle types. All API functions
  286. defined here work with any handle type.
  287. uv.is_active({handle}) *uv.is_active()*
  288. > method form `handle:is_active()`
  289. Parameters:
  290. - `handle`: `userdata` for sub-type of |uv_handle_t|
  291. Returns `true` if the handle is active, `false` if it's
  292. inactive. What "active” means depends on the type of handle:
  293. - A |uv_async_t| handle is always active and cannot be
  294. deactivated, except by closing it with |uv.close()|.
  295. - A |uv_pipe_t|, |uv_tcp_t|, |uv_udp_t|, etc.
  296. handle - basically any handle that deals with I/O - is
  297. active when it is doing something that involves I/O, like
  298. reading, writing, connecting, accepting new connections,
  299. etc.
  300. - A |uv_check_t|, |uv_idle_t|, |uv_timer_t|,
  301. etc. handle is active when it has been started with a call
  302. to |uv.check_start()|, |uv.idle_start()|,
  303. |uv.timer_start()| etc. until it has been stopped with a
  304. call to its respective stop function.
  305. Returns: `boolean` or `fail`
  306. uv.is_closing({handle}) *uv.is_closing()*
  307. > method form `handle:is_closing()`
  308. Parameters:
  309. - `handle`: `userdata` for sub-type of |uv_handle_t|
  310. Returns `true` if the handle is closing or closed, `false`
  311. otherwise.
  312. Returns: `boolean` or `fail`
  313. Note: This function should only be used between the
  314. initialization of the handle and the arrival of the close
  315. callback.
  316. uv.close({handle} [, {callback}]) *uv.close()*
  317. > method form `handle:close([callback])`
  318. Parameters:
  319. - `handle`: `userdata` for sub-type of |uv_handle_t|
  320. - `callback`: `callable` or `nil`
  321. Request handle to be closed. `callback` will be called
  322. asynchronously after this call. This MUST be called on each
  323. handle before memory is released.
  324. Handles that wrap file descriptors are closed immediately but
  325. `callback` will still be deferred to the next iteration of the
  326. event loop. It gives you a chance to free up any resources
  327. associated with the handle.
  328. In-progress requests, like `uv_connect_t` or `uv_write_t`, are
  329. cancelled and have their callbacks called asynchronously with
  330. `ECANCELED`.
  331. Returns: Nothing.
  332. uv.ref({handle}) *uv.ref()*
  333. > method form `handle:ref()`
  334. Parameters:
  335. - `handle`: `userdata` for sub-type of |uv_handle_t|
  336. Reference the given handle. References are idempotent, that
  337. is, if a handle is already referenced calling this function
  338. again will have no effect.
  339. Returns: Nothing.
  340. See |luv-reference-counting|.
  341. uv.unref({handle}) *uv.unref()*
  342. > method form `handle:unref()`
  343. Parameters:
  344. - `handle`: `userdata` for sub-type of |uv_handle_t|
  345. Un-reference the given handle. References are idempotent, that
  346. is, if a handle is not referenced calling this function again
  347. will have no effect.
  348. Returns: Nothing.
  349. See |luv-reference-counting|.
  350. uv.has_ref({handle}) *uv.has_ref()*
  351. > method form `handle:has_ref()`
  352. Parameters:
  353. - `handle`: `userdata` for sub-type of |uv_handle_t|
  354. Returns `true` if the handle referenced, `false` if not.
  355. Returns: `boolean` or `fail`
  356. See |luv-reference-counting|.
  357. uv.send_buffer_size({handle} [, {size}]) *uv.send_buffer_size()*
  358. > method form `handle:send_buffer_size([size])`
  359. Parameters:
  360. - `handle`: `userdata` for sub-type of |uv_handle_t|
  361. - `size`: `integer` or `nil` (default: `0`)
  362. Gets or sets the size of the send buffer that the operating
  363. system uses for the socket.
  364. If `size` is omitted (or `0`), this will return the current
  365. send buffer size; otherwise, this will use `size` to set the
  366. new send buffer size.
  367. This function works for TCP, pipe and UDP handles on Unix and
  368. for TCP and UDP handles on Windows.
  369. Returns:
  370. - `integer` or `fail` (if `size` is `nil` or `0`)
  371. - `0` or `fail` (if `size` is not `nil` and not `0`)
  372. Note: Linux will set double the size and return double the
  373. size of the original set value.
  374. uv.recv_buffer_size({handle} [, {size}]) *uv.recv_buffer_size()*
  375. > method form `handle:recv_buffer_size([size])`
  376. Parameters:
  377. - `handle`: `userdata` for sub-type of |uv_handle_t|
  378. - `size`: `integer` or `nil` (default: `0`)
  379. Gets or sets the size of the receive buffer that the operating
  380. system uses for the socket.
  381. If `size` is omitted (or `0`), this will return the current
  382. send buffer size; otherwise, this will use `size` to set the
  383. new send buffer size.
  384. This function works for TCP, pipe and UDP handles on Unix and
  385. for TCP and UDP handles on Windows.
  386. Returns:
  387. - `integer` or `fail` (if `size` is `nil` or `0`)
  388. - `0` or `fail` (if `size` is not `nil` and not `0`)
  389. Note: Linux will set double the size and return double the
  390. size of the original set value.
  391. uv.fileno({handle}) *uv.fileno()*
  392. > method form `handle:fileno()`
  393. Parameters:
  394. - `handle`: `userdata` for sub-type of |uv_handle_t|
  395. Gets the platform dependent file descriptor equivalent.
  396. The following handles are supported: TCP, pipes, TTY, UDP and
  397. poll. Passing any other handle type will fail with `EINVAL`.
  398. If a handle doesn't have an attached file descriptor yet or
  399. the handle itself has been closed, this function will return
  400. `EBADF`.
  401. Returns: `integer` or `fail`
  402. WARNING: Be very careful when using this function. libuv
  403. assumes it's in control of the file descriptor so any change
  404. to it may lead to malfunction.
  405. uv.handle_get_type({handle}) *uv.handle_get_type()*
  406. > method form `handle:get_type()`
  407. Parameters:
  408. - `handle`: `userdata` for sub-type of |uv_handle_t|
  409. Returns the name of the struct for a given handle (e.g.
  410. `"pipe"` for |uv_pipe_t|) and the libuv enum integer for the
  411. handle's type (`uv_handle_type`).
  412. Returns: `string, integer`
  413. ==============================================================================
  414. REFERENCE COUNTING *luv-reference-counting*
  415. The libuv event loop (if run in the default mode) will run until there are no
  416. active and referenced handles left. The user can force the loop to exit early
  417. by unreferencing handles which are active, for example by calling |uv.unref()|
  418. after calling |uv.timer_start()|.
  419. A handle can be referenced or unreferenced, the refcounting scheme doesn't use
  420. a counter, so both operations are idempotent.
  421. All handles are referenced when active by default, see |uv.is_active()| for a
  422. more detailed explanation on what being active involves.
  423. ==============================================================================
  424. `uv_timer_t` — Timer handle *luv-timer-handle* *uv_timer_t*
  425. > |uv_handle_t| functions also apply.
  426. Timer handles are used to schedule callbacks to be called in the future.
  427. uv.new_timer() *uv.new_timer()*
  428. Creates and initializes a new |uv_timer_t|. Returns the Lua
  429. userdata wrapping it.
  430. Returns: `uv_timer_t userdata` or `fail`
  431. >
  432. -- Creating a simple setTimeout wrapper
  433. local function setTimeout(timeout, callback)
  434. local timer = uv.new_timer()
  435. timer:start(timeout, 0, function ()
  436. timer:stop()
  437. timer:close()
  438. callback()
  439. end)
  440. return timer
  441. end
  442. -- Creating a simple setInterval wrapper
  443. local function setInterval(interval, callback)
  444. local timer = uv.new_timer()
  445. timer:start(interval, interval, function ()
  446. callback()
  447. end)
  448. return timer
  449. end
  450. -- And clearInterval
  451. local function clearInterval(timer)
  452. timer:stop()
  453. timer:close()
  454. end
  455. <
  456. uv.timer_start({timer}, {timeout}, {repeat}, {callback}) *uv.timer_start()*
  457. > method form `timer:start(timeout, repeat, callback)`
  458. Parameters:
  459. - `timer`: `uv_timer_t userdata`
  460. - `timeout`: `integer`
  461. - `repeat`: `integer`
  462. - `callback`: `callable`
  463. Start the timer. `timeout` and `repeat` are in milliseconds.
  464. If `timeout` is zero, the callback fires on the next event
  465. loop iteration. If `repeat` is non-zero, the callback fires
  466. first after `timeout` milliseconds and then repeatedly after
  467. `repeat` milliseconds.
  468. Returns: `0` or `fail`
  469. uv.timer_stop({timer}) *uv.timer_stop()*
  470. > method form `timer:stop()`
  471. Parameters:
  472. - `timer`: `uv_timer_t userdata`
  473. Stop the timer, the callback will not be called anymore.
  474. Returns: `0` or `fail`
  475. uv.timer_again({timer}) *uv.timer_again()*
  476. > method form `timer:again()`
  477. Parameters:
  478. - `timer`: `uv_timer_t userdata`
  479. Stop the timer, and if it is repeating restart it using the
  480. repeat value as the timeout. If the timer has never been
  481. started before it raises `EINVAL`.
  482. Returns: `0` or `fail`
  483. uv.timer_set_repeat({timer}, {repeat}) *uv.timer_set_repeat()*
  484. > method form `timer:set_repeat(repeat)`
  485. Parameters:
  486. - `timer`: `uv_timer_t userdata`
  487. - `repeat`: `integer`
  488. Set the repeat interval value in milliseconds. The timer will
  489. be scheduled to run on the given interval, regardless of the
  490. callback execution duration, and will follow normal timer
  491. semantics in the case of a time-slice overrun.
  492. For example, if a 50 ms repeating timer first runs for 17 ms,
  493. it will be scheduled to run again 33 ms later. If other tasks
  494. consume more than the 33 ms following the first timer
  495. callback, then the callback will run as soon as possible.
  496. Returns: Nothing.
  497. uv.timer_get_repeat({timer}) *uv.timer_get_repeat()*
  498. > method form `timer:get_repeat()`
  499. Parameters:
  500. - `timer`: `uv_timer_t userdata`
  501. Get the timer repeat value.
  502. Returns: `integer`
  503. uv.timer_get_due_in({timer}) *uv.timer_get_due_in()*
  504. > method form `timer:get_due_in()`
  505. Parameters:
  506. - `timer`: `uv_timer_t userdata`
  507. Get the timer due value or 0 if it has expired. The time is
  508. relative to |uv.now()|.
  509. Returns: `integer`
  510. Note: New in libuv version 1.40.0.
  511. ==============================================================================
  512. `uv_prepare_t` — Prepare handle *luv-prepare-handle* *uv_prepare_t*
  513. > |uv_handle_t| functions also apply.
  514. Prepare handles will run the given callback once per loop iteration, right
  515. before polling for I/O.
  516. >
  517. local prepare = uv.new_prepare()
  518. prepare:start(function()
  519. print("Before I/O polling")
  520. end)
  521. <
  522. uv.new_prepare() *uv.new_prepare()*
  523. Creates and initializes a new |uv_prepare_t|. Returns the Lua
  524. userdata wrapping it.
  525. Returns: `uv_prepare_t userdata` or `fail`
  526. uv.prepare_start({prepare}, {callback}) *uv.prepare_start()*
  527. > method form `prepare:start(callback)`
  528. Parameters:
  529. - `prepare`: `uv_prepare_t userdata`
  530. - `callback`: `callable`
  531. Start the handle with the given callback.
  532. Returns: `0` or `fail`
  533. uv.prepare_stop({prepare}) *uv.prepare_stop()*
  534. > method form `prepare:stop()`
  535. Parameters:
  536. - `prepare`: `uv_prepare_t userdata`
  537. Stop the handle, the callback will no longer be called.
  538. Returns: `0` or `fail`
  539. ==============================================================================
  540. `uv_check_t` — Check handle *luv-check-handle* *uv_check_t*
  541. > |uv_handle_t| functions also apply.
  542. Check handles will run the given callback once per loop iteration, right after
  543. polling for I/O.
  544. >
  545. local check = uv.new_check()
  546. check:start(function()
  547. print("After I/O polling")
  548. end)
  549. <
  550. uv.new_check() *uv.new_check()*
  551. Creates and initializes a new |uv_check_t|. Returns the Lua
  552. userdata wrapping it.
  553. Returns: `uv_check_t userdata` or `fail`
  554. uv.check_start({check}, {callback}) *uv.check_start()*
  555. > method form `check:start(callback)`
  556. Parameters:
  557. - `check`: `uv_check_t userdata`
  558. - `callback`: `callable`
  559. Start the handle with the given callback.
  560. Returns: `0` or `fail`
  561. uv.check_stop({check}) *uv.check_stop()*
  562. > method form `check:stop()`
  563. Parameters:
  564. - `check`: `uv_check_t userdata`
  565. Stop the handle, the callback will no longer be called.
  566. Returns: `0` or `fail`
  567. ==============================================================================
  568. `uv_idle_t` — Idle handle *luv-idle-handle* *uv_idle_t*
  569. > |uv_handle_t| functions also apply.
  570. Idle handles will run the given callback once per loop iteration, right before
  571. the |uv_prepare_t| handles.
  572. Note: The notable difference with prepare handles is that when there are
  573. active idle handles, the loop will perform a zero timeout poll instead of
  574. blocking for I/O.
  575. WARNING: Despite the name, idle handles will get their callbacks called on
  576. every loop iteration, not when the loop is actually "idle".
  577. >
  578. local idle = uv.new_idle()
  579. idle:start(function()
  580. print("Before I/O polling, no blocking")
  581. end)
  582. <
  583. uv.new_idle() *uv.new_idle()*
  584. Creates and initializes a new |uv_idle_t|. Returns the Lua
  585. userdata wrapping it.
  586. Returns: `uv_idle_t userdata` or `fail`
  587. uv.idle_start({idle}, {callback}) *uv.idle_start()*
  588. > method form `idle:start(callback)`
  589. Parameters:
  590. - `idle`: `uv_idle_t userdata`
  591. - `callback`: `callable`
  592. Start the handle with the given callback.
  593. Returns: `0` or `fail`
  594. uv.idle_stop({check}) *uv.idle_stop()*
  595. > method form `idle:stop()`
  596. Parameters:
  597. - `idle`: `uv_idle_t userdata`
  598. Stop the handle, the callback will no longer be called.
  599. Returns: `0` or `fail`
  600. ==============================================================================
  601. `uv_async_t` — Async handle *luv-async-handle* *uv_async_t*
  602. > |uv_handle_t| functions also apply.
  603. Async handles allow the user to "wakeup" the event loop and get a callback
  604. called from another thread.
  605. >
  606. local async
  607. async = uv.new_async(function()
  608. print("async operation ran")
  609. async:close()
  610. end)
  611. async:send()
  612. <
  613. uv.new_async([{callback}]) *uv.new_async()*
  614. Parameters:
  615. - `callback`: `callable` or `nil`
  616. - `...`: `threadargs` passed to/from
  617. `uv.async_send(async, ...)`
  618. Creates and initializes a new |uv_async_t|. Returns the Lua
  619. userdata wrapping it. A `nil` callback is allowed.
  620. Returns: `uv_async_t userdata` or `fail`
  621. Note: Unlike other handle initialization functions, this
  622. immediately starts the handle.
  623. uv.async_send({async}, {...}) *uv.async_send()*
  624. > method form `async:send(...)`
  625. Parameters:
  626. - `async`: `uv_async_t userdata`
  627. - `...`: `threadargs`
  628. Wakeup the event loop and call the async handle's callback.
  629. Returns: `0` or `fail`
  630. Note: It's safe to call this function from any thread. The
  631. callback will be called on the loop thread.
  632. WARNING: libuv will coalesce calls to `uv.async_send(async)`,
  633. that is, not every call to it will yield an execution of the
  634. callback. For example: if `uv.async_send()` is called 5 times
  635. in a row before the callback is called, the callback will only
  636. be called once. If `uv.async_send()` is called again after the
  637. callback was called, it will be called again.
  638. ==============================================================================
  639. `uv_poll_t` — Poll handle *luv-poll-handle* *uv_poll_t*
  640. > |uv_handle_t| functions also apply.
  641. Poll handles are used to watch file descriptors for readability and
  642. writability, similar to the purpose of poll(2)
  643. (https://linux.die.net/man/2/poll).
  644. The purpose of poll handles is to enable integrating external libraries that
  645. rely on the event loop to signal it about the socket status changes, like
  646. c-ares or libssh2. Using `uv_poll_t` for any other purpose is not recommended;
  647. |uv_tcp_t|, |uv_udp_t|, etc. provide an implementation that is faster and more
  648. scalable than what can be achieved with `uv_poll_t`, especially on Windows.
  649. It is possible that poll handles occasionally signal that a file descriptor is
  650. readable or writable even when it isn't. The user should therefore always be
  651. prepared to handle EAGAIN or equivalent when it attempts to read from or write
  652. to the fd.
  653. It is not okay to have multiple active poll handles for the same socket, this
  654. can cause libuv to busyloop or otherwise malfunction.
  655. The user should not close a file descriptor while it is being polled by an
  656. active poll handle. This can cause the handle to report an error, but it might
  657. also start polling another socket. However the fd can be safely closed
  658. immediately after a call to |uv.poll_stop()| or |uv.close()|.
  659. Note: On windows only sockets can be polled with poll handles. On Unix any
  660. file descriptor that would be accepted by poll(2) can be used.
  661. uv.new_poll({fd}) *uv.new_poll()*
  662. Parameters:
  663. - `fd`: `integer`
  664. Initialize the handle using a file descriptor.
  665. The file descriptor is set to non-blocking mode.
  666. Returns: `uv_poll_t userdata` or `fail`
  667. uv.new_socket_poll({fd}) *uv.new_socket_poll()*
  668. Parameters:
  669. - `fd`: `integer`
  670. Initialize the handle using a socket descriptor. On Unix this
  671. is identical to |uv.new_poll()|. On windows it takes a SOCKET
  672. handle.
  673. The socket is set to non-blocking mode.
  674. Returns: `uv_poll_t userdata` or `fail`
  675. uv.poll_start({poll}, {events}, {callback}) *uv.poll_start()*
  676. > method form `poll:start(events, callback)`
  677. Parameters:
  678. - `poll`: `uv_poll_t userdata`
  679. - `events`: `string` or `nil` (default: `"rw"`)
  680. - `callback`: `callable`
  681. - `err`: `nil` or `string`
  682. - `events`: `string` or `nil`
  683. Starts polling the file descriptor. `events` are: `"r"`,
  684. `"w"`, `"rw"`, `"d"`, `"rd"`, `"wd"`, `"rwd"`, `"p"`, `"rp"`,
  685. `"wp"`, `"rwp"`, `"dp"`, `"rdp"`, `"wdp"`, or `"rwdp"` where
  686. `r` is `READABLE`, `w` is `WRITABLE`, `d` is `DISCONNECT`, and
  687. `p` is `PRIORITIZED`. As soon as an event is detected the
  688. callback will be called with status set to 0, and the detected
  689. events set on the events field.
  690. The user should not close the socket while the handle is
  691. active. If the user does that anyway, the callback may be
  692. called reporting an error status, but this is not guaranteed.
  693. Returns: `0` or `fail`
  694. Note Calling `uv.poll_start()` on a handle that is already
  695. active is fine. Doing so will update the events mask that is
  696. being watched for.
  697. uv.poll_stop({poll}) *uv.poll_stop()*
  698. > method form `poll:stop()`
  699. Parameters:
  700. - `poll`: `uv_poll_t userdata`
  701. Stop polling the file descriptor, the callback will no longer
  702. be called.
  703. Returns: `0` or `fail`
  704. ==============================================================================
  705. `uv_signal_t` — Signal handle *luv-signal-handle* *uv_signal_t*
  706. > |uv_handle_t| functions also apply.
  707. Signal handles implement Unix style signal handling on a per-event loop bases.
  708. Windows Notes:
  709. Reception of some signals is emulated on Windows:
  710. - SIGINT is normally delivered when the user presses CTRL+C. However, like
  711. on Unix, it is not generated when terminal raw mode is enabled.
  712. - SIGBREAK is delivered when the user pressed CTRL + BREAK.
  713. - SIGHUP is generated when the user closes the console window. On SIGHUP the
  714. program is given approximately 10 seconds to perform cleanup. After that
  715. Windows will unconditionally terminate it.
  716. - SIGWINCH is raised whenever libuv detects that the console has been
  717. resized. SIGWINCH is emulated by libuv when the program uses a uv_tty_t
  718. handle to write to the console. SIGWINCH may not always be delivered in a
  719. timely manner; libuv will only detect size changes when the cursor is
  720. being moved. When a readable |uv_tty_t| handle is used in raw mode,
  721. resizing the console buffer will also trigger a SIGWINCH signal.
  722. - Watchers for other signals can be successfully created, but these signals
  723. are never received. These signals are: SIGILL, SIGABRT, SIGFPE, SIGSEGV,
  724. SIGTERM and SIGKILL.
  725. - Calls to raise() or abort() to programmatically raise a signal are not
  726. detected by libuv; these will not trigger a signal watcher.
  727. Unix Notes:
  728. - SIGKILL and SIGSTOP are impossible to catch.
  729. - Handling SIGBUS, SIGFPE, SIGILL or SIGSEGV via libuv results into
  730. undefined behavior.
  731. - SIGABRT will not be caught by libuv if generated by abort(), e.g. through
  732. assert().
  733. - On Linux SIGRT0 and SIGRT1 (signals 32 and 33) are used by the NPTL
  734. pthreads library to manage threads. Installing watchers for those signals
  735. will lead to unpredictable behavior and is strongly discouraged. Future
  736. versions of libuv may simply reject them.
  737. >
  738. -- Create a new signal handler
  739. local signal = uv.new_signal()
  740. -- Define a handler function
  741. uv.signal_start(signal, "sigint", function(signal)
  742. print("got " .. signal .. ", shutting down")
  743. os.exit(1)
  744. end)
  745. <
  746. uv.new_signal() *uv.new_signal()*
  747. Creates and initializes a new |uv_signal_t|. Returns the Lua
  748. userdata wrapping it.
  749. Returns: `uv_signal_t userdata` or `fail`
  750. uv.signal_start({signal}, {signum}, {callback}) *uv.signal_start()*
  751. > method form `signal:start(signum, callback)`
  752. Parameters:
  753. - `signal`: `uv_signal_t userdata`
  754. - `signum`: `integer` or `string`
  755. - `callback`: `callable`
  756. - `signum`: `string`
  757. Start the handle with the given callback, watching for the
  758. given signal.
  759. Returns: `0` or `fail`
  760. *uv.signal_start_oneshot()*
  761. uv.signal_start_oneshot({signal}, {signum}, {callback})
  762. > method form `signal:start_oneshot(signum, callback)`
  763. Parameters:
  764. - `signal`: `uv_signal_t userdata`
  765. - `signum`: `integer` or `string`
  766. - `callback`: `callable`
  767. - `signum`: `string`
  768. Same functionality as |uv.signal_start()| but the signal
  769. handler is reset the moment the signal is received.
  770. Returns: `0` or `fail`
  771. uv.signal_stop({signal}) *uv.signal_stop()*
  772. > method form `signal:stop()`
  773. Parameters:
  774. - `signal`: `uv_signal_t userdata`
  775. Stop the handle, the callback will no longer be called.
  776. Returns: `0` or `fail`
  777. ==============================================================================
  778. `uv_process_t` — Process handle *luv-process-handle* *uv_process_t*
  779. > |uv_handle_t| functions also apply.
  780. Process handles will spawn a new process and allow the user to control it and
  781. establish communication channels with it using streams.
  782. uv.disable_stdio_inheritance() *uv.disable_stdio_inheritance()*
  783. Disables inheritance for file descriptors / handles that this
  784. process inherited from its parent. The effect is that child
  785. processes spawned by this process don't accidentally inherit
  786. these handles.
  787. It is recommended to call this function as early in your
  788. program as possible, before the inherited file descriptors can
  789. be closed or duplicated.
  790. Returns: Nothing.
  791. Note: This function works on a best-effort basis: there is no
  792. guarantee that libuv can discover all file descriptors that
  793. were inherited. In general it does a better job on Windows
  794. than it does on Unix.
  795. uv.spawn({path}, {options}, {on_exit}) *uv.spawn()*
  796. Parameters:
  797. - `path`: `string`
  798. - `options`: `table` (see below)
  799. - `on_exit`: `callable`
  800. - `code`: `integer`
  801. - `signal`: `integer`
  802. Initializes the process handle and starts the process. If the
  803. process is successfully spawned, this function will return the
  804. handle and pid of the child process.
  805. Possible reasons for failing to spawn would include (but not
  806. be limited to) the file to execute not existing, not having
  807. permissions to use the setuid or setgid specified, or not
  808. having enough memory to allocate for the new process.
  809. >
  810. local stdin = uv.new_pipe()
  811. local stdout = uv.new_pipe()
  812. local stderr = uv.new_pipe()
  813. print("stdin", stdin)
  814. print("stdout", stdout)
  815. print("stderr", stderr)
  816. local handle, pid = uv.spawn("cat", {
  817. stdio = {stdin, stdout, stderr}
  818. }, function(code, signal) -- on exit
  819. print("exit code", code)
  820. print("exit signal", signal)
  821. end)
  822. print("process opened", handle, pid)
  823. uv.read_start(stdout, function(err, data)
  824. assert(not err, err)
  825. if data then
  826. print("stdout chunk", stdout, data)
  827. else
  828. print("stdout end", stdout)
  829. end
  830. end)
  831. uv.read_start(stderr, function(err, data)
  832. assert(not err, err)
  833. if data then
  834. print("stderr chunk", stderr, data)
  835. else
  836. print("stderr end", stderr)
  837. end
  838. end)
  839. uv.write(stdin, "Hello World")
  840. uv.shutdown(stdin, function()
  841. print("stdin shutdown", stdin)
  842. uv.close(handle, function()
  843. print("process closed", handle, pid)
  844. end)
  845. end)
  846. <
  847. *uv.spawn-options*
  848. The `options` table accepts the following fields:
  849. - `options.args` - Command line arguments as a list of
  850. string. The first string should be the path to the
  851. program. On Windows, this uses CreateProcess which
  852. concatenates the arguments into a string. This can cause
  853. some strange errors. (See `options.verbatim` below for
  854. Windows.)
  855. - `options.stdio` - Set the file descriptors that will be
  856. made available to the child process. The convention is
  857. that the first entries are stdin, stdout, and stderr.
  858. (Note: On Windows, file descriptors after the third are
  859. available to the child process only if the child processes
  860. uses the MSVCRT runtime.)
  861. - `options.env` - Set environment variables for the new
  862. process.
  863. - `options.cwd` - Set the current working directory for the
  864. sub-process.
  865. - `options.uid` - Set the child process' user id.
  866. - `options.gid` - Set the child process' group id.
  867. - `options.verbatim` - If true, do not wrap any arguments in
  868. quotes, or perform any other escaping, when converting the
  869. argument list into a command line string. This option is
  870. only meaningful on Windows systems. On Unix it is silently
  871. ignored.
  872. - `options.detached` - If true, spawn the child process in a
  873. detached state - this will make it a process group leader,
  874. and will effectively enable the child to keep running
  875. after the parent exits. Note that the child process will
  876. still keep the parent's event loop alive unless the parent
  877. process calls |uv.unref()| on the child's process handle.
  878. - `options.hide` - If true, hide the subprocess console
  879. window that would normally be created. This option is only
  880. meaningful on Windows systems. On Unix it is silently
  881. ignored.
  882. The `options.stdio` entries can take many shapes.
  883. - If they are numbers, then the child process inherits that
  884. same zero-indexed fd from the parent process.
  885. - If |uv_stream_t| handles are passed in, those are used as
  886. a read-write pipe or inherited stream depending if the
  887. stream has a valid fd.
  888. - Including `nil` placeholders means to ignore that fd in
  889. the child process.
  890. When the child process exits, `on_exit` is called with an exit
  891. code and signal.
  892. Returns: `uv_process_t userdata`, `integer`
  893. uv.process_kill({process}, {signum}) *uv.process_kill()*
  894. > method form `process:kill(signum)`
  895. Parameters:
  896. - `process`: `uv_process_t userdata`
  897. - `signum`: `integer` or `string`
  898. Sends the specified signal to the given process handle. Check
  899. the documentation on |uv_signal_t| for signal support,
  900. specially on Windows.
  901. Returns: `0` or `fail`
  902. uv.kill({pid}, {signum}) *uv.kill()*
  903. Parameters:
  904. - `pid`: `integer`
  905. - `signum`: `integer` or `string`
  906. Sends the specified signal to the given PID. Check the
  907. documentation on |uv_signal_t| for signal support, specially
  908. on Windows.
  909. Returns: `0` or `fail`
  910. uv.process_get_pid({process}) *uv.process_get_pid()*
  911. > method form `process:get_pid()`
  912. Parameters:
  913. - `process`: `uv_process_t userdata`
  914. Returns the handle's pid.
  915. Returns: `integer`
  916. ==============================================================================
  917. `uv_stream_t` — Stream handle *luv-stream-handle* *uv_stream_t*
  918. > |uv_handle_t| functions also apply.
  919. Stream handles provide an abstraction of a duplex communication channel.
  920. `uv_stream_t` is an abstract type, libuv provides 3 stream implementations
  921. in the form of |uv_tcp_t|, |uv_pipe_t| and |uv_tty_t|.
  922. uv.shutdown({stream} [, {callback}]) *uv.shutdown()*
  923. > method form `stream:shutdown([callback])`
  924. Parameters:
  925. - `stream`: `userdata` for sub-type of |uv_stream_t|
  926. - `callback`: `callable` or `nil`
  927. - `err`: `nil` or `string`
  928. Shutdown the outgoing (write) side of a duplex stream. It
  929. waits for pending write requests to complete. The callback is
  930. called after shutdown is complete.
  931. Returns: `uv_shutdown_t userdata` or `fail`
  932. uv.listen({stream}, {backlog}, {callback}) *uv.listen()*
  933. > method form `stream:listen(backlog, callback)`
  934. Parameters:
  935. - `stream`: `userdata` for sub-type of |uv_stream_t|
  936. - `backlog`: `integer`
  937. - `callback`: `callable`
  938. - `err`: `nil` or `string`
  939. Start listening for incoming connections. `backlog` indicates
  940. the number of connections the kernel might queue, same as
  941. `listen(2)`. When a new incoming connection is received the
  942. callback is called.
  943. Returns: `0` or `fail`
  944. uv.accept({stream}, {client_stream}) *uv.accept()*
  945. > method form `stream:accept(client_stream)`
  946. Parameters:
  947. - `stream`: `userdata` for sub-type of |uv_stream_t|
  948. - `client_stream`: `userdata` for sub-type of |uv_stream_t|
  949. This call is used in conjunction with |uv.listen()| to accept
  950. incoming connections. Call this function after receiving a
  951. callback to accept the connection.
  952. When the connection callback is called it is guaranteed that
  953. this function will complete successfully the first time. If
  954. you attempt to use it more than once, it may fail. It is
  955. suggested to only call this function once per connection call.
  956. Returns: `0` or `fail`
  957. >
  958. server:listen(128, function (err)
  959. local client = uv.new_tcp()
  960. server:accept(client)
  961. end)
  962. <
  963. uv.read_start({stream}, {callback}) *uv.read_start()*
  964. > method form `stream:read_start(callback)`
  965. Parameters:
  966. - `stream`: `userdata` for sub-type of |uv_stream_t|
  967. - `callback`: `callable`
  968. - `err`: `nil` or `string`
  969. - `data`: `string` or `nil`
  970. Read data from an incoming stream. The callback will be made
  971. several times until there is no more data to read or
  972. |uv.read_stop()| is called. When we've reached EOF, `data`
  973. will be `nil`.
  974. Returns: `0` or `fail`
  975. >
  976. stream:read_start(function (err, chunk)
  977. if err then
  978. -- handle read error
  979. elseif chunk then
  980. -- handle data
  981. else
  982. -- handle disconnect
  983. end
  984. end)
  985. <
  986. uv.read_stop({stream}) *uv.read_stop()*
  987. > method form `stream:read_stop()`
  988. Parameters:
  989. - `stream`: `userdata` for sub-type of |uv_stream_t|
  990. Stop reading data from the stream. The read callback will no
  991. longer be called.
  992. This function is idempotent and may be safely called on a
  993. stopped stream.
  994. Returns: `0` or `fail`
  995. uv.write({stream}, {data} [, {callback}]) *uv.write()*
  996. > method form `stream:write(data, [callback])`
  997. Parameters:
  998. - `stream`: `userdata` for sub-type of |uv_stream_t|
  999. - `data`: `buffer`
  1000. - `callback`: `callable` or `nil`
  1001. - `err`: `nil` or `string`
  1002. Write data to stream.
  1003. `data` can either be a Lua string or a table of strings. If a
  1004. table is passed in, the C backend will use writev to send all
  1005. strings in a single system call.
  1006. The optional `callback` is for knowing when the write is
  1007. complete.
  1008. Returns: `uv_write_t userdata` or `fail`
  1009. uv.write2({stream}, {data}, {send_handle} [, {callback}]) *uv.write2()*
  1010. > method form `stream:write2(data, send_handle, [callback])`
  1011. Parameters:
  1012. - `stream`: `userdata` for sub-type of |uv_stream_t|
  1013. - `data`: `buffer`
  1014. - `send_handle`: `userdata` for sub-type of |uv_stream_t|
  1015. - `callback`: `callable` or `nil`
  1016. - `err`: `nil` or `string`
  1017. Extended write function for sending handles over a pipe. The
  1018. pipe must be initialized with `ipc` option `true`.
  1019. Returns: `uv_write_t userdata` or `fail`
  1020. Note: `send_handle` must be a TCP socket or pipe, which is a
  1021. server or a connection (listening or connected state). Bound
  1022. sockets or pipes will be assumed to be servers.
  1023. uv.try_write({stream}, {data}) *uv.try_write()*
  1024. > method form `stream:try_write(data)`
  1025. Parameters:
  1026. - `stream`: `userdata` for sub-type of |uv_stream_t|
  1027. - `data`: `buffer`
  1028. Same as |uv.write()|, but won't queue a write request if it
  1029. can't be completed immediately.
  1030. Will return number of bytes written (can be less than the
  1031. supplied buffer size).
  1032. Returns: `integer` or `fail`
  1033. uv.try_write2({stream}, {data}, {send_handle}) *uv.try_write2()*
  1034. > method form `stream:try_write2(data, send_handle)`
  1035. Parameters:
  1036. - `stream`: `userdata` for sub-type of |uv_stream_t|
  1037. - `data`: `buffer`
  1038. - `send_handle`: `userdata` for sub-type of |uv_stream_t|
  1039. Like |uv.write2()|, but with the properties of
  1040. |uv.try_write()|. Not supported on Windows, where it returns
  1041. `UV_EAGAIN`.
  1042. Will return number of bytes written (can be less than the
  1043. supplied buffer size).
  1044. Returns: `integer` or `fail`
  1045. uv.is_readable({stream}) *uv.is_readable()*
  1046. > method form `stream:is_readable()`
  1047. Parameters:
  1048. - `stream`: `userdata` for sub-type of |uv_stream_t|
  1049. Returns `true` if the stream is readable, `false` otherwise.
  1050. Returns: `boolean`
  1051. uv.is_writable({stream}) *uv.is_writable()*
  1052. > method form `stream:is_writable()`
  1053. Parameters:
  1054. - `stream`: `userdata` for sub-type of |uv_stream_t|
  1055. Returns `true` if the stream is writable, `false` otherwise.
  1056. Returns: `boolean`
  1057. uv.stream_set_blocking({stream}, {blocking}) *uv.stream_set_blocking()*
  1058. > method form `stream:set_blocking(blocking)`
  1059. Parameters:
  1060. - `stream`: `userdata` for sub-type of |uv_stream_t|
  1061. - `blocking`: `boolean`
  1062. Enable or disable blocking mode for a stream.
  1063. When blocking mode is enabled all writes complete
  1064. synchronously. The interface remains unchanged otherwise, e.g.
  1065. completion or failure of the operation will still be reported
  1066. through a callback which is made asynchronously.
  1067. Returns: `0` or `fail`
  1068. WARNING: Relying too much on this API is not recommended. It
  1069. is likely to change significantly in the future. Currently
  1070. this only works on Windows and only for |uv_pipe_t| handles.
  1071. Also libuv currently makes no ordering guarantee when the
  1072. blocking mode is changed after write requests have already
  1073. been submitted. Therefore it is recommended to set the
  1074. blocking mode immediately after opening or creating the
  1075. stream.
  1076. uv.stream_get_write_queue_size() *uv.stream_get_write_queue_size()*
  1077. > method form `stream:get_write_queue_size()`
  1078. Returns the stream's write queue size.
  1079. Returns: `integer`
  1080. ==============================================================================
  1081. `uv_tcp_t` — TCP handle *luv-tcp-handle* *uv_tcp_t*
  1082. > |uv_handle_t| and |uv_stream_t| functions also apply.
  1083. TCP handles are used to represent both TCP streams and servers.
  1084. uv.new_tcp([{flags}]) *uv.new_tcp()*
  1085. Parameters:
  1086. - `flags`: `string` or `nil`
  1087. Creates and initializes a new |uv_tcp_t|. Returns the Lua
  1088. userdata wrapping it. Flags may be a family string: `"unix"`,
  1089. `"inet"`, `"inet6"`, `"ipx"`, `"netlink"`, `"x25"`, `"ax25"`,
  1090. `"atmpvc"`, `"appletalk"`, or `"packet"`.
  1091. Returns: `uv_tcp_t userdata` or `fail`
  1092. uv.tcp_open({tcp}, {sock}) *uv.tcp_open()*
  1093. > method form `tcp:open(sock)`
  1094. Parameters:
  1095. - `tcp`: `uv_tcp_t userdata`
  1096. - `sock`: `integer`
  1097. Open an existing file descriptor or SOCKET as a TCP handle.
  1098. Returns: `0` or `fail`
  1099. Note: The passed file descriptor or SOCKET is not checked for
  1100. its type, but it's required that it represents a valid stream
  1101. socket.
  1102. uv.tcp_nodelay({tcp}, {enable}) *uv.tcp_nodelay()*
  1103. > method form `tcp:nodelay(enable)`
  1104. Parameters:
  1105. - `tcp`: `uv_tcp_t userdata`
  1106. - `enable`: `boolean`
  1107. Enable / disable Nagle's algorithm.
  1108. Returns: `0` or `fail`
  1109. uv.tcp_keepalive({tcp}, {enable} [, {delay}]) *uv.tcp_keepalive()*
  1110. > method form `tcp:keepalive(enable, [delay])`
  1111. Parameters:
  1112. - `tcp`: `uv_tcp_t userdata`
  1113. - `enable`: `boolean`
  1114. - `delay`: `integer` or `nil`
  1115. Enable / disable TCP keep-alive. `delay` is the initial delay
  1116. in seconds, ignored when enable is `false`.
  1117. Returns: `0` or `fail`
  1118. uv.tcp_simultaneous_accepts({tcp}, {enable}) *uv.tcp_simultaneous_accepts()*
  1119. > method form `tcp:simultaneous_accepts(enable)`
  1120. Parameters:
  1121. - `tcp`: `uv_tcp_t userdata`
  1122. - `enable`: `boolean`
  1123. Enable / disable simultaneous asynchronous accept requests
  1124. that are queued by the operating system when listening for new
  1125. TCP connections.
  1126. This setting is used to tune a TCP server for the desired
  1127. performance. Having simultaneous accepts can significantly
  1128. improve the rate of accepting connections (which is why it is
  1129. enabled by default) but may lead to uneven load distribution
  1130. in multi-process setups.
  1131. Returns: `0` or `fail`
  1132. uv.tcp_bind({tcp}, {host}, {port} [, {flags}]) *uv.tcp_bind()*
  1133. > method form `tcp:bind(host, port, [flags])`
  1134. Parameters:
  1135. - `tcp`: `uv_tcp_t userdata`
  1136. - `host`: `string`
  1137. - `port`: `integer`
  1138. - `flags`: `table` or `nil`
  1139. - `ipv6only`: `boolean`
  1140. Bind the handle to an host and port. `host` should be an IP
  1141. address and not a domain name. Any `flags` are set with a
  1142. table with field `ipv6only` equal to `true` or `false`.
  1143. When the port is already taken, you can expect to see an
  1144. `EADDRINUSE` error from either `uv.tcp_bind()`, |uv.listen()|
  1145. or |uv.tcp_connect()|. That is, a successful call to this
  1146. function does not guarantee that the call to |uv.listen()| or
  1147. |uv.tcp_connect()| will succeed as well.
  1148. Use a port of `0` to let the OS assign an ephemeral port. You
  1149. can look it up later using |uv.tcp_getsockname()|.
  1150. Returns: `0` or `fail`
  1151. uv.tcp_getpeername({tcp}) *uv.tcp_getpeername()*
  1152. > method form `tcp:getpeername()`
  1153. Parameters:
  1154. - `tcp`: `uv_tcp_t userdata`
  1155. Get the address of the peer connected to the handle.
  1156. Returns: `table` or `fail`
  1157. - `ip` : `string`
  1158. - `family` : `string`
  1159. - `port` : `integer`
  1160. uv.tcp_getsockname({tcp}) *uv.tcp_getsockname()*
  1161. > method form `tcp:getsockname()`
  1162. Parameters:
  1163. - `tcp`: `uv_tcp_t userdata`
  1164. Get the current address to which the handle is bound.
  1165. Returns: `table` or `fail`
  1166. - `ip` : `string`
  1167. - `family` : `string`
  1168. - `port` : `integer`
  1169. uv.tcp_connect({tcp}, {host}, {port}, {callback}) *uv.tcp_connect()*
  1170. > method form `tcp:connect(host, port, callback)`
  1171. Parameters:
  1172. - `tcp`: `uv_tcp_t userdata`
  1173. - `host`: `string`
  1174. - `port`: `integer`
  1175. - `callback`: `callable`
  1176. - `err`: `nil` or `string`
  1177. Establish an IPv4 or IPv6 TCP connection.
  1178. Returns: `uv_connect_t userdata` or `fail`
  1179. >
  1180. local client = uv.new_tcp()
  1181. client:connect("127.0.0.1", 8080, function (err)
  1182. -- check error and carry on.
  1183. end)
  1184. <
  1185. uv.tcp_write_queue_size({tcp}) *uv.tcp_write_queue_size()*
  1186. > method form `tcp:write_queue_size()`
  1187. DEPRECATED: Please use |uv.stream_get_write_queue_size()|
  1188. instead.
  1189. uv.tcp_close_reset([{callback}]) *uv.tcp_close_reset()*
  1190. > method form `tcp:close_reset([callback])`
  1191. Parameters:
  1192. - `tcp`: `uv_tcp_t userdata`
  1193. - `callback`: `callable` or `nil`
  1194. Resets a TCP connection by sending a RST packet. This is
  1195. accomplished by setting the SO_LINGER socket option with a
  1196. linger interval of zero and then calling |uv.close()|. Due to
  1197. some platform inconsistencies, mixing of |uv.shutdown()| and
  1198. `uv.tcp_close_reset()` calls is not allowed.
  1199. Returns: `0` or `fail`
  1200. *uv.socketpair()*
  1201. uv.socketpair([{socktype}, [{protocol}, [{flags1}, [{flags2}]]]])
  1202. Parameters:
  1203. - `socktype`: `string`, `integer` or `nil` (default: `stream`)
  1204. - `protocol`: `string`, `integer` or `nil` (default: 0)
  1205. - `flags1`: `table` or `nil`
  1206. - `nonblock`: `boolean` (default: `false`)
  1207. - `flags2`: `table` or `nil`
  1208. - `nonblock`: `boolean` (default: `false`)
  1209. Create a pair of connected sockets with the specified
  1210. properties. The resulting handles can be passed to
  1211. |uv.tcp_open()|, used with |uv.spawn()|, or for any other
  1212. purpose.
  1213. When specified as a string, `socktype` must be one of
  1214. `"stream"`, `"dgram"`, `"raw"`, `"rdm"`, or `"seqpacket"`.
  1215. When `protocol` is set to 0 or nil, it will be automatically
  1216. chosen based on the socket's domain and type. When `protocol`
  1217. is specified as a string, it will be looked up using the
  1218. `getprotobyname(3)` function (examples: `"ip"`, `"icmp"`,
  1219. `"tcp"`, `"udp"`, etc).
  1220. Flags:
  1221. - `nonblock`: Opens the specified socket handle for
  1222. `OVERLAPPED` or `FIONBIO`/`O_NONBLOCK` I/O usage. This is
  1223. recommended for handles that will be used by libuv, and not
  1224. usually recommended otherwise.
  1225. Equivalent to `socketpair(2)` with a domain of `AF_UNIX`.
  1226. Returns: `table` or `fail`
  1227. - `[1, 2]` : `integer` (file descriptor)
  1228. >
  1229. -- Simple read/write with tcp
  1230. local fds = uv.socketpair(nil, nil, {nonblock=true}, {nonblock=true})
  1231. local sock1 = uv.new_tcp()
  1232. sock1:open(fds[1])
  1233. local sock2 = uv.new_tcp()
  1234. sock2:open(fds[2])
  1235. sock1:write("hello")
  1236. sock2:read_start(function(err, chunk)
  1237. assert(not err, err)
  1238. print(chunk)
  1239. end)
  1240. <
  1241. ==============================================================================
  1242. `uv_pipe_t` — Pipe handle *luv-pipe-handle* *uv_pipe_t*
  1243. > |uv_handle_t| and |uv_stream_t| functions also apply.
  1244. Pipe handles provide an abstraction over local domain sockets on Unix and
  1245. named pipes on Windows.
  1246. >
  1247. local pipe = uv.new_pipe(false)
  1248. pipe:bind('/tmp/sock.test')
  1249. pipe:listen(128, function()
  1250. local client = uv.new_pipe(false)
  1251. pipe:accept(client)
  1252. client:write("hello!\n")
  1253. client:close()
  1254. end)
  1255. <
  1256. uv.new_pipe([{ipc}]) *uv.new_pipe()*
  1257. Parameters:
  1258. - `ipc`: `boolean` or `nil` (default: `false`)
  1259. Creates and initializes a new |uv_pipe_t|. Returns the Lua
  1260. userdata wrapping it. The `ipc` argument is a boolean to
  1261. indicate if this pipe will be used for handle passing between
  1262. processes.
  1263. Returns: `uv_pipe_t userdata` or `fail`
  1264. uv.pipe_open({pipe}, {fd}) *uv.pipe_open()*
  1265. > method form `pipe:open(fd)`
  1266. Parameters:
  1267. - `pipe`: `uv_pipe_t userdata`
  1268. - `fd`: `integer`
  1269. Open an existing file descriptor or |uv_handle_t| as a
  1270. pipe.
  1271. Returns: `0` or `fail`
  1272. Note: The file descriptor is set to non-blocking mode.
  1273. uv.pipe_bind({pipe}, {name}) *uv.pipe_bind()*
  1274. > method form `pipe:bind(name)`
  1275. Parameters:
  1276. - `pipe`: `uv_pipe_t userdata`
  1277. - `name`: `string`
  1278. Bind the pipe to a file path (Unix) or a name (Windows).
  1279. Returns: `0` or `fail`
  1280. Note: Paths on Unix get truncated to
  1281. sizeof(sockaddr_un.sun_path) bytes, typically between 92 and
  1282. 108 bytes.
  1283. uv.pipe_connect({pipe}, {name} [, {callback}]) *uv.pipe_connect()*
  1284. > method form `pipe:connect(name, [callback])`
  1285. Parameters:
  1286. - `pipe`: `uv_pipe_t userdata`
  1287. - `name`: `string`
  1288. - `callback`: `callable` or `nil`
  1289. - `err`: `nil` or `string`
  1290. Connect to the Unix domain socket or the named pipe.
  1291. Returns: `uv_connect_t userdata` or `fail`
  1292. Note: Paths on Unix get truncated to
  1293. sizeof(sockaddr_un.sun_path) bytes, typically between 92 and
  1294. 108 bytes.
  1295. uv.pipe_getsockname({pipe}) *uv.pipe_getsockname()*
  1296. > method form `pipe:getsockname()`
  1297. Parameters:
  1298. - `pipe`: `uv_pipe_t userdata`
  1299. Get the name of the Unix domain socket or the named pipe.
  1300. Returns: `string` or `fail`
  1301. uv.pipe_getpeername({pipe}) *uv.pipe_getpeername()*
  1302. > method form `pipe:getpeername()`
  1303. Parameters:
  1304. - `pipe`: `uv_pipe_t userdata`
  1305. Get the name of the Unix domain socket or the named pipe to
  1306. which the handle is connected.
  1307. Returns: `string` or `fail`
  1308. uv.pipe_pending_instances({pipe}, {count}) *uv.pipe_pending_instances()*
  1309. > method form `pipe:pending_instances(count)`
  1310. Parameters:
  1311. - `pipe`: `uv_pipe_t userdata`
  1312. - `count`: `integer`
  1313. Set the number of pending pipe instance handles when the pipe
  1314. server is waiting for connections.
  1315. Returns: Nothing.
  1316. Note: This setting applies to Windows only.
  1317. uv.pipe_pending_count({pipe}) *uv.pipe_pending_count()*
  1318. > method form `pipe:pending_count()`
  1319. Parameters:
  1320. - `pipe`: `uv_pipe_t userdata`
  1321. Returns the pending pipe count for the named pipe.
  1322. Returns: `integer`
  1323. uv.pipe_pending_type({pipe}) *uv.pipe_pending_type()*
  1324. > method form `pipe:pending_type()`
  1325. Parameters:
  1326. - `pipe`: `uv_pipe_t userdata`
  1327. Used to receive handles over IPC pipes.
  1328. First - call |uv.pipe_pending_count()|, if it's > 0 then
  1329. initialize a handle of the given type, returned by
  1330. `uv.pipe_pending_type()` and call `uv.accept(pipe, handle)` .
  1331. Returns: `string`
  1332. uv.pipe_chmod({pipe}, {flags}) *uv.pipe_chmod()*
  1333. > method form `pipe:chmod(flags)`
  1334. Parameters:
  1335. - `pipe`: `uv_pipe_t userdata`
  1336. - `flags`: `string`
  1337. Alters pipe permissions, allowing it to be accessed from
  1338. processes run by different users. Makes the pipe writable or
  1339. readable by all users. `flags` are: `"r"`, `"w"`, `"rw"`, or
  1340. `"wr"` where `r` is `READABLE` and `w` is `WRITABLE`. This
  1341. function is blocking.
  1342. Returns: `0` or `fail`
  1343. uv.pipe({read_flags}, {write_flags}) *uv.pipe()*
  1344. Parameters:
  1345. - `read_flags`: `table` or `nil`
  1346. - `nonblock`: `boolean` (default: `false`)
  1347. - `write_flags`: `table` or `nil`
  1348. - `nonblock`: `boolean` (default: `false`)
  1349. Create a pair of connected pipe handles. Data may be written
  1350. to the `write` fd and read from the `read` fd. The resulting
  1351. handles can be passed to `pipe_open`, used with `spawn`, or
  1352. for any other purpose.
  1353. Flags:
  1354. - `nonblock`: Opens the specified socket handle for
  1355. `OVERLAPPED` or `FIONBIO`/`O_NONBLOCK` I/O usage. This is
  1356. recommended for handles that will be used by libuv, and not
  1357. usually recommended otherwise.
  1358. Equivalent to `pipe(2)` with the `O_CLOEXEC` flag set.
  1359. Returns: `table` or `fail`
  1360. - `read` : `integer` (file descriptor)
  1361. - `write` : `integer` (file descriptor)
  1362. >
  1363. -- Simple read/write with pipe_open
  1364. local fds = uv.pipe({nonblock=true}, {nonblock=true})
  1365. local read_pipe = uv.new_pipe()
  1366. read_pipe:open(fds.read)
  1367. local write_pipe = uv.new_pipe()
  1368. write_pipe:open(fds.write)
  1369. write_pipe:write("hello")
  1370. read_pipe:read_start(function(err, chunk)
  1371. assert(not err, err)
  1372. print(chunk)
  1373. end)
  1374. <
  1375. ==============================================================================
  1376. `uv_tty_t` — TTY handle *luv-tty-handle* *uv_tty_t*
  1377. > |uv_handle_t| and |uv_stream_t| functions also apply.
  1378. TTY handles represent a stream for the console.
  1379. >
  1380. -- Simple echo program
  1381. local stdin = uv.new_tty(0, true)
  1382. local stdout = uv.new_tty(1, false)
  1383. stdin:read_start(function (err, data)
  1384. assert(not err, err)
  1385. if data then
  1386. stdout:write(data)
  1387. else
  1388. stdin:close()
  1389. stdout:close()
  1390. end
  1391. end)
  1392. <
  1393. uv.new_tty({fd}, {readable}) *uv.new_tty()*
  1394. Parameters:
  1395. - `fd`: `integer`
  1396. - `readable`: `boolean`
  1397. Initialize a new TTY stream with the given file descriptor.
  1398. Usually the file descriptor will be:
  1399. - 0 - stdin
  1400. - 1 - stdout
  1401. - 2 - stderr
  1402. On Unix this function will determine the path of the fd of the
  1403. terminal using ttyname_r(3), open it, and use it if the passed
  1404. file descriptor refers to a TTY. This lets libuv put the tty
  1405. in non-blocking mode without affecting other processes that
  1406. share the tty.
  1407. This function is not thread safe on systems that don’t support
  1408. ioctl TIOCGPTN or TIOCPTYGNAME, for instance OpenBSD and
  1409. Solaris.
  1410. Returns: `uv_tty_t userdata` or `fail`
  1411. Note: If reopening the TTY fails, libuv falls back to blocking
  1412. writes.
  1413. uv.tty_set_mode({tty}, {mode}) *uv.tty_set_mode()*
  1414. > method form `tty:set_mode(mode)`
  1415. Parameters:
  1416. - `tty`: `uv_tty_t userdata`
  1417. - `mode`: `integer`
  1418. Set the TTY using the specified terminal mode.
  1419. Parameter `mode` is a C enum with the following values:
  1420. - 0 - UV_TTY_MODE_NORMAL: Initial/normal terminal mode
  1421. - 1 - UV_TTY_MODE_RAW: Raw input mode (On Windows,
  1422. ENABLE_WINDOW_INPUT is also enabled)
  1423. - 2 - UV_TTY_MODE_IO: Binary-safe I/O mode for IPC
  1424. (Unix-only)
  1425. Returns: `0` or `fail`
  1426. uv.tty_reset_mode() *uv.tty_reset_mode()*
  1427. To be called when the program exits. Resets TTY settings to
  1428. default values for the next process to take over.
  1429. This function is async signal-safe on Unix platforms but can
  1430. fail with error code `EBUSY` if you call it when execution is
  1431. inside |uv.tty_set_mode()|.
  1432. Returns: `0` or `fail`
  1433. uv.tty_get_winsize({tty}) *uv.tty_get_winsize()*
  1434. > method form `tty:get_winsize()`
  1435. Parameters:
  1436. - `tty`: `uv_tty_t userdata`
  1437. Gets the current Window width and height.
  1438. Returns: `integer, integer` or `fail`
  1439. uv.tty_set_vterm_state({state}) *uv.tty_set_vterm_state()*
  1440. Parameters:
  1441. - `state`: `string`
  1442. Controls whether console virtual terminal sequences are
  1443. processed by libuv or console. Useful in particular for
  1444. enabling ConEmu support of ANSI X3.64 and Xterm 256 colors.
  1445. Otherwise Windows10 consoles are usually detected
  1446. automatically. State should be one of: `"supported"` or
  1447. `"unsupported"`.
  1448. This function is only meaningful on Windows systems. On Unix
  1449. it is silently ignored.
  1450. Returns: none
  1451. uv.tty_get_vterm_state() *uv.tty_get_vterm_state()*
  1452. Get the current state of whether console virtual terminal
  1453. sequences are handled by libuv or the console. The return
  1454. value is `"supported"` or `"unsupported"`.
  1455. This function is not implemented on Unix, where it returns
  1456. `ENOTSUP`.
  1457. Returns: `string` or `fail`
  1458. ==============================================================================
  1459. `uv_udp_t` — UDP handle *luv-udp-handle* *uv_udp_t*
  1460. > |uv_handle_t| functions also apply.
  1461. UDP handles encapsulate UDP communication for both clients and servers.
  1462. uv.new_udp([{flags}]) *uv.new_udp()*
  1463. Parameters:
  1464. - `flags`: `table` or `nil`
  1465. - `family`: `string` or `nil`
  1466. - `mmsgs`: `integer` or `nil` (default: `1`)
  1467. Creates and initializes a new |uv_udp_t|. Returns the Lua
  1468. userdata wrapping it. The actual socket is created lazily.
  1469. When specified, `family` must be one of `"unix"`, `"inet"`,
  1470. `"inet6"`, `"ipx"`, `"netlink"`, `"x25"`, `"ax25"`,
  1471. `"atmpvc"`, `"appletalk"`, or `"packet"`.
  1472. When specified, `mmsgs` determines the number of messages able
  1473. to be received at one time via `recvmmsg(2)` (the allocated
  1474. buffer will be sized to be able to fit the specified number of
  1475. max size dgrams). Only has an effect on platforms that support
  1476. `recvmmsg(2)`.
  1477. Note: For backwards compatibility reasons, `flags` can also be
  1478. a string or integer. When it is a string, it will be treated
  1479. like the `family` key above. When it is an integer, it will be
  1480. used directly as the `flags` parameter when calling
  1481. `uv_udp_init_ex`.
  1482. Returns: `uv_udp_t userdata` or `fail`
  1483. uv.udp_get_send_queue_size() *uv.udp_get_send_queue_size()*
  1484. > method form `udp:get_send_queue_size()`
  1485. Returns the handle's send queue size.
  1486. Returns: `integer`
  1487. uv.udp_get_send_queue_count() *uv.udp_get_send_queue_count()*
  1488. > method form `udp:get_send_queue_count()`
  1489. Returns the handle's send queue count.
  1490. Returns: `integer`
  1491. uv.udp_open({udp}, {fd}) *uv.udp_open()*
  1492. > method form `udp:open(fd)`
  1493. Parameters:
  1494. - `udp`: `uv_udp_t userdata`
  1495. - `fd`: `integer`
  1496. Opens an existing file descriptor or Windows SOCKET as a UDP
  1497. handle.
  1498. Unix only: The only requirement of the sock argument is that
  1499. it follows the datagram contract (works in unconnected mode,
  1500. supports sendmsg()/recvmsg(), etc). In other words, other
  1501. datagram-type sockets like raw sockets or netlink sockets can
  1502. also be passed to this function.
  1503. The file descriptor is set to non-blocking mode.
  1504. Note: The passed file descriptor or SOCKET is not checked for
  1505. its type, but it's required that it represents a valid
  1506. datagram socket.
  1507. Returns: `0` or `fail`
  1508. uv.udp_bind({udp}, {host}, {port} [, {flags}]) *uv.udp_bind()*
  1509. > method form `udp:bind(host, port, [flags])`
  1510. Parameters:
  1511. - `udp`: `uv_udp_t userdata`
  1512. - `host`: `string`
  1513. - `port`: `number`
  1514. - `flags`: `table` or `nil`
  1515. - `ipv6only`: `boolean`
  1516. - `reuseaddr`: `boolean`
  1517. Bind the UDP handle to an IP address and port. Any `flags` are
  1518. set with a table with fields `reuseaddr` or `ipv6only` equal
  1519. to `true` or `false`.
  1520. Returns: `0` or `fail`
  1521. uv.udp_getsockname({udp}) *uv.udp_getsockname()*
  1522. > method form `udp:getsockname()`
  1523. Parameters:
  1524. - `udp`: `uv_udp_t userdata`
  1525. Get the local IP and port of the UDP handle.
  1526. Returns: `table` or `fail`
  1527. - `ip` : `string`
  1528. - `family` : `string`
  1529. - `port` : `integer`
  1530. uv.udp_getpeername({udp}) *uv.udp_getpeername()*
  1531. > method form `udp:getpeername()`
  1532. Parameters:
  1533. - `udp`: `uv_udp_t userdata`
  1534. Get the remote IP and port of the UDP handle on connected UDP
  1535. handles.
  1536. Returns: `table` or `fail`
  1537. - `ip` : `string`
  1538. - `family` : `string`
  1539. - `port` : `integer`
  1540. *uv.udp_set_membership()*
  1541. uv.udp_set_membership({udp}, {multicast_addr}, {interface_addr}, {membership})
  1542. > method form
  1543. > `udp:set_membership(multicast_addr, interface_addr, membership)`
  1544. Parameters:
  1545. - `udp`: `uv_udp_t userdata`
  1546. - `multicast_addr`: `string`
  1547. - `interface_addr`: `string` or `nil`
  1548. - `membership`: `string`
  1549. Set membership for a multicast address. `multicast_addr` is
  1550. multicast address to set membership for. `interface_addr` is
  1551. interface address. `membership` can be the string `"leave"` or
  1552. `"join"`.
  1553. Returns: `0` or `fail`
  1554. *uv.udp_set_source_membership()*
  1555. uv.udp_set_source_membership({udp}, {multicast_addr}, {interface_addr}, {source_addr}, {membership})
  1556. > method form
  1557. > `udp:set_source_membership(multicast_addr, interface_addr, source_addr, membership)`
  1558. Parameters:
  1559. - `udp`: `uv_udp_t userdata`
  1560. - `multicast_addr`: `string`
  1561. - `interface_addr`: `string` or `nil`
  1562. - `source_addr`: `string`
  1563. - `membership`: `string`
  1564. Set membership for a source-specific multicast group.
  1565. `multicast_addr` is multicast address to set membership for.
  1566. `interface_addr` is interface address. `source_addr` is source
  1567. address. `membership` can be the string `"leave"` or `"join"`.
  1568. Returns: `0` or `fail`
  1569. uv.udp_set_multicast_loop({udp}, {on}) *uv.udp_set_multicast_loop()*
  1570. > method form `udp:set_multicast_loop(on)`
  1571. Parameters:
  1572. - `udp`: `uv_udp_t userdata`
  1573. - `on`: `boolean`
  1574. Set IP multicast loop flag. Makes multicast packets loop back
  1575. to local sockets.
  1576. Returns: `0` or `fail`
  1577. uv.udp_set_multicast_ttl({udp}, {ttl}) *uv.udp_set_multicast_ttl()*
  1578. > method form `udp:set_multicast_ttl(ttl)`
  1579. Parameters:
  1580. - `udp`: `uv_udp_t userdata`
  1581. - `ttl`: `integer`
  1582. Set the multicast ttl.
  1583. `ttl` is an integer 1 through 255.
  1584. Returns: `0` or `fail`
  1585. *uv.udp_set_multicast_interface()*
  1586. uv.udp_set_multicast_interface({udp}, {interface_addr})
  1587. > method form `udp:set_multicast_interface(interface_addr)`
  1588. Parameters:
  1589. - `udp`: `uv_udp_t userdata`
  1590. - `interface_addr`: `string`
  1591. Set the multicast interface to send or receive data on.
  1592. Returns: `0` or `fail`
  1593. uv.udp_set_broadcast({udp}, {on}) *uv.udp_set_broadcast()*
  1594. > method form `udp:set_broadcast(on)`
  1595. Parameters:
  1596. - `udp`: `uv_udp_t userdata`
  1597. - `on`: `boolean`
  1598. Set broadcast on or off.
  1599. Returns: `0` or `fail`
  1600. uv.udp_set_ttl({udp}, {ttl}) *uv.udp_set_ttl()*
  1601. > method form `udp:set_ttl(ttl)`
  1602. Parameters:
  1603. - `udp`: `uv_udp_t userdata`
  1604. - `ttl`: `integer`
  1605. Set the time to live.
  1606. `ttl` is an integer 1 through 255.
  1607. Returns: `0` or `fail`
  1608. uv.udp_send({udp}, {data}, {host}, {port}, {callback}) *uv.udp_send()*
  1609. > method form `udp:send(data, host, port, callback)`
  1610. Parameters:
  1611. - `udp`: `uv_udp_t userdata`
  1612. - `data`: `buffer`
  1613. - `host`: `string`
  1614. - `port`: `integer`
  1615. - `callback`: `callable`
  1616. - `err`: `nil` or `string`
  1617. Send data over the UDP socket. If the socket has not
  1618. previously been bound with |uv.udp_bind()| it will be bound to
  1619. `0.0.0.0` (the "all interfaces" IPv4 address) and a random
  1620. port number.
  1621. Returns: `uv_udp_send_t userdata` or `fail`
  1622. uv.udp_try_send({udp}, {data}, {host}, {port}) *uv.udp_try_send()*
  1623. > method form `udp:try_send(data, host, port)`
  1624. Parameters:
  1625. - `udp`: `uv_udp_t userdata`
  1626. - `data`: `buffer`
  1627. - `host`: `string`
  1628. - `port`: `integer`
  1629. Same as |uv.udp_send()|, but won't queue a send request if it
  1630. can't be completed immediately.
  1631. Returns: `integer` or `fail`
  1632. uv.udp_recv_start({udp}, {callback}) *uv.udp_recv_start()*
  1633. > method form `udp:recv_start(callback)`
  1634. Parameters:
  1635. - `udp`: `uv_udp_t userdata`
  1636. - `callback`: `callable`
  1637. - `err`: `nil` or `string`
  1638. - `data`: `string` or `nil`
  1639. - `addr`: `table` or `nil`
  1640. - `ip`: `string`
  1641. - `port`: `integer`
  1642. - `family`: `string`
  1643. - `flags`: `table`
  1644. - `partial`: `boolean` or `nil`
  1645. - `mmsg_chunk`: `boolean` or `nil`
  1646. Prepare for receiving data. If the socket has not previously
  1647. been bound with |uv.udp_bind()| it is bound to `0.0.0.0` (the
  1648. "all interfaces" IPv4 address) and a random port number.
  1649. Returns: `0` or `fail`
  1650. uv.udp_recv_stop({udp}) *uv.udp_recv_stop()*
  1651. > method form `udp:recv_stop()`
  1652. Parameters:
  1653. - `udp`: `uv_udp_t userdata`
  1654. Stop listening for incoming datagrams.
  1655. Returns: `0` or `fail`
  1656. uv.udp_connect({udp}, {host}, {port}) *uv.udp_connect()*
  1657. > method form `udp:connect(host, port)`
  1658. Parameters:
  1659. - `udp`: `uv_udp_t userdata`
  1660. - `host`: `string`
  1661. - `port`: `integer`
  1662. Associate the UDP handle to a remote address and port, so
  1663. every message sent by this handle is automatically sent to
  1664. that destination. Calling this function with a NULL addr
  1665. disconnects the handle. Trying to call `uv.udp_connect()` on
  1666. an already connected handle will result in an `EISCONN` error.
  1667. Trying to disconnect a handle that is not connected will
  1668. return an `ENOTCONN` error.
  1669. Returns: `0` or `fail`
  1670. ==============================================================================
  1671. `uv_fs_event_t` — FS Event handle *luv-fs-event-handle* *uv_fs_event_t*
  1672. > |uv_handle_t| functions also apply.
  1673. FS Event handles allow the user to monitor a given path for changes, for
  1674. example, if the file was renamed or there was a generic change in it. This
  1675. handle uses the best backend for the job on each platform.
  1676. uv.new_fs_event() *uv.new_fs_event()*
  1677. Creates and initializes a new |uv_fs_event_t|. Returns the Lua
  1678. userdata wrapping it.
  1679. Returns: `uv_fs_event_t userdata` or `fail`
  1680. uv.fs_event_start({fs_event}, {path}, {flags}, {callback}) *uv.fs_event_start()*
  1681. > method form `fs_event:start(path, flags, callback)`
  1682. Parameters:
  1683. - `fs_event`: `uv_fs_event_t userdata`
  1684. - `path`: `string`
  1685. - `flags`: `table`
  1686. - `watch_entry`: `boolean` or `nil` (default: `false`)
  1687. - `stat`: `boolean` or `nil` (default: `false`)
  1688. - `recursive`: `boolean` or `nil` (default: `false`)
  1689. - `callback`: `callable`
  1690. - `err`: `nil` or `string`
  1691. - `filename`: `string`
  1692. - `events`: `table`
  1693. - `change`: `boolean` or `nil`
  1694. - `rename`: `boolean` or `nil`
  1695. Start the handle with the given callback, which will watch the
  1696. specified path for changes.
  1697. Returns: `0` or `fail`
  1698. uv.fs_event_stop() *uv.fs_event_stop()*
  1699. > method form `fs_event:stop()`
  1700. Stop the handle, the callback will no longer be called.
  1701. Returns: `0` or `fail`
  1702. uv.fs_event_getpath() *uv.fs_event_getpath()*
  1703. > method form `fs_event:getpath()`
  1704. Get the path being monitored by the handle.
  1705. Returns: `string` or `fail`
  1706. ==============================================================================
  1707. `uv_fs_poll_t` — FS Poll handle *luv-fs-poll-handle* *uv_fs_poll_t*
  1708. > |uv_handle_t| functions also apply.
  1709. FS Poll handles allow the user to monitor a given path for changes. Unlike
  1710. |uv_fs_event_t|, fs poll handles use `stat` to detect when a file has changed
  1711. so they can work on file systems where fs event handles can't.
  1712. uv.new_fs_poll() *uv.new_fs_poll()*
  1713. Creates and initializes a new |uv_fs_poll_t|. Returns the Lua
  1714. userdata wrapping it.
  1715. Returns: `uv_fs_poll_t userdata` or `fail`
  1716. uv.fs_poll_start({fs_poll}, {path}, {interval}, {callback}) *uv.fs_poll_start()*
  1717. > method form `fs_poll:start(path, interval, callback)`
  1718. Parameters:
  1719. - `fs_event`: `uv_fs_event_t userdata`
  1720. - `path`: `string`
  1721. - `interval`: `integer`
  1722. - `callback`: `callable`
  1723. - `err`: `nil` or `string`
  1724. - `prev`: `table` or `nil` (see `uv.fs_stat`)
  1725. - `curr`: `table` or `nil` (see `uv.fs_stat`)
  1726. Check the file at `path` for changes every `interval`
  1727. milliseconds.
  1728. Note: For maximum portability, use multi-second intervals.
  1729. Sub-second intervals will not detect all changes on many file
  1730. systems.
  1731. Returns: `0` or `fail`
  1732. uv.fs_poll_stop() *uv.fs_poll_stop()*
  1733. > method form `fs_poll:stop()`
  1734. Stop the handle, the callback will no longer be called.
  1735. Returns: `0` or `fail`
  1736. uv.fs_poll_getpath() *uv.fs_poll_getpath()*
  1737. > method form `fs_poll:getpath()`
  1738. Get the path being monitored by the handle.
  1739. Returns: `string` or `fail`
  1740. ==============================================================================
  1741. FILE SYSTEM OPERATIONS *luv-file-system-operations* *uv_fs_t*
  1742. Most file system functions can operate synchronously or asynchronously. When a
  1743. synchronous version is called (by omitting a callback), the function will
  1744. immediately return the results of the FS call. When an asynchronous version is
  1745. called (by providing a callback), the function will immediately return a
  1746. `uv_fs_t userdata` and asynchronously execute its callback; if an error is
  1747. encountered, the first and only argument passed to the callback will be the
  1748. `err` error string; if the operation completes successfully, the first
  1749. argument will be `nil` and the remaining arguments will be the results of the
  1750. FS call.
  1751. Synchronous and asynchronous versions of `readFile` (with naive error
  1752. handling) are implemented below as an example:
  1753. >
  1754. local function readFileSync(path)
  1755. local fd = assert(uv.fs_open(path, "r", 438))
  1756. local stat = assert(uv.fs_fstat(fd))
  1757. local data = assert(uv.fs_read(fd, stat.size, 0))
  1758. assert(uv.fs_close(fd))
  1759. return data
  1760. end
  1761. local data = readFileSync("main.lua")
  1762. print("synchronous read", data)
  1763. <
  1764. >
  1765. local function readFile(path, callback)
  1766. uv.fs_open(path, "r", 438, function(err, fd)
  1767. assert(not err, err)
  1768. uv.fs_fstat(fd, function(err, stat)
  1769. assert(not err, err)
  1770. uv.fs_read(fd, stat.size, 0, function(err, data)
  1771. assert(not err, err)
  1772. uv.fs_close(fd, function(err)
  1773. assert(not err, err)
  1774. return callback(data)
  1775. end)
  1776. end)
  1777. end)
  1778. end)
  1779. end
  1780. readFile("main.lua", function(data)
  1781. print("asynchronous read", data)
  1782. end)
  1783. <
  1784. uv.fs_close({fd} [, {callback}]) *uv.fs_close()*
  1785. Parameters:
  1786. - `fd`: `integer`
  1787. - `callback`: `callable` (async version) or `nil` (sync
  1788. version)
  1789. - `err`: `nil` or `string`
  1790. - `success`: `boolean` or `nil`
  1791. Equivalent to `close(2)`.
  1792. Returns (sync version): `boolean` or `fail`
  1793. Returns (async version): `uv_fs_t userdata`
  1794. uv.fs_open({path}, {flags}, {mode} [, {callback}]) *uv.fs_open()*
  1795. Parameters:
  1796. - `path`: `string`
  1797. - `flags`: `string` or `integer`
  1798. - `mode`: `integer`
  1799. - `callback`: `callable` (async version) or `nil` (sync
  1800. version)
  1801. - `err`: `nil` or `string`
  1802. - `fd`: `integer` or `nil`
  1803. Equivalent to `open(2)`. Access `flags` may be an integer or
  1804. one of: `"r"`, `"rs"`, `"sr"`, `"r+"`, `"rs+"`, `"sr+"`,
  1805. `"w"`, `"wx"`, `"xw"`, `"w+"`, `"wx+"`, `"xw+"`, `"a"`,
  1806. `"ax"`, `"xa"`, `"a+"`, `"ax+"`, or "`xa+`".
  1807. Returns (sync version): `integer` or `fail`
  1808. Returns (async version): `uv_fs_t userdata`
  1809. Note: On Windows, libuv uses `CreateFileW` and thus the file
  1810. is always opened in binary mode. Because of this, the
  1811. `O_BINARY` and `O_TEXT` flags are not supported.
  1812. uv.fs_read({fd}, {size} [, {offset} [, {callback}]]) *uv.fs_read()*
  1813. Parameters:
  1814. - `fd`: `integer`
  1815. - `size`: `integer`
  1816. - `offset`: `integer` or `nil`
  1817. - `callback`: `callable` (async version) or `nil` (sync
  1818. version)
  1819. - `err`: `nil` or `string`
  1820. - `data`: `string` or `nil`
  1821. Equivalent to `preadv(2)`. Returns any data. An empty string
  1822. indicates EOF.
  1823. If `offset` is nil or omitted, it will default to `-1`, which
  1824. indicates 'use and update the current file offset.'
  1825. Note: When `offset` is >= 0, the current file offset will not
  1826. be updated by the read.
  1827. Returns (sync version): `string` or `fail`
  1828. Returns (async version): `uv_fs_t userdata`
  1829. uv.fs_unlink({path} [, {callback}]) *uv.fs_unlink()*
  1830. Parameters:
  1831. - `path`: `string`
  1832. - `callback`: `callable` (async version) or `nil` (sync
  1833. version)
  1834. - `err`: `nil` or `string`
  1835. - `success`: `boolean` or `nil`
  1836. Equivalent to `unlink(2)`.
  1837. Returns (sync version): `boolean` or `fail`
  1838. Returns (async version): `uv_fs_t userdata`
  1839. uv.fs_write({fd}, {data} [, {offset} [, {callback}]]) *uv.fs_write()*
  1840. Parameters:
  1841. - `fd`: `integer`
  1842. - `data`: `buffer`
  1843. - `offset`: `integer` or `nil`
  1844. - `callback`: `callable` (async version) or `nil` (sync
  1845. version)
  1846. - `err`: `nil` or `string`
  1847. - `bytes`: `integer` or `nil`
  1848. Equivalent to `pwritev(2)`. Returns the number of bytes
  1849. written.
  1850. If `offset` is nil or omitted, it will default to `-1`, which
  1851. indicates 'use and update the current file offset.'
  1852. Note: When `offset` is >= 0, the current file offset will not
  1853. be updated by the write.
  1854. Returns (sync version): `integer` or `fail`
  1855. Returns (async version): `uv_fs_t userdata`
  1856. uv.fs_mkdir({path}, {mode} [, {callback}]) *uv.fs_mkdir()*
  1857. Parameters:
  1858. - `path`: `string`
  1859. - `mode`: `integer`
  1860. - `callback`: `callable` (async version) or `nil` (sync
  1861. version)
  1862. - `err`: `nil` or `string`
  1863. - `success`: `boolean` or `nil`
  1864. Equivalent to `mkdir(2)`.
  1865. Returns (sync version): `boolean` or `fail`
  1866. Returns (async version): `uv_fs_t userdata`
  1867. uv.fs_mkdtemp({template} [, {callback}]) *uv.fs_mkdtemp()*
  1868. Parameters:
  1869. - `template`: `string`
  1870. - `callback`: `callable` (async version) or `nil` (sync
  1871. version)
  1872. - `err`: `nil` or `string`
  1873. - `path`: `string` or `nil`
  1874. Equivalent to `mkdtemp(3)`.
  1875. Returns (sync version): `string` or `fail`
  1876. Returns (async version): `uv_fs_t userdata`
  1877. uv.fs_mkstemp({template} [, {callback}]) *uv.fs_mkstemp()*
  1878. Parameters:
  1879. - `template`: `string`
  1880. - `callback`: `callable` (async version) or `nil` (sync
  1881. version)
  1882. - `err`: `nil` or `string`
  1883. - `fd`: `integer` or `nil`
  1884. - `path`: `string` or `nil`
  1885. Equivalent to `mkstemp(3)`. Returns a temporary file handle
  1886. and filename.
  1887. Returns (sync version): `integer, string` or `fail`
  1888. Returns (async version): `uv_fs_t userdata`
  1889. uv.fs_rmdir({path} [, {callback}]) *uv.fs_rmdir()*
  1890. Parameters:
  1891. - `path`: `string`
  1892. - `callback`: `callable` (async version) or `nil` (sync
  1893. version)
  1894. - `err`: `nil` or `string`
  1895. - `success`: `boolean` or `nil`
  1896. Equivalent to `rmdir(2)`.
  1897. Returns (sync version): `boolean` or `fail`
  1898. Returns (async version): `uv_fs_t userdata`
  1899. uv.fs_scandir({path} [, {callback}]) *uv.fs_scandir()*
  1900. Parameters:
  1901. - `path`: `string`
  1902. - `callback`: `callable`
  1903. - `err`: `nil` or `string`
  1904. - `success`: `uv_fs_t userdata` or `nil`
  1905. Equivalent to `scandir(3)`, with a slightly different API.
  1906. Returns a handle that the user can pass to
  1907. |uv.fs_scandir_next()|.
  1908. Note: This function can be used synchronously or
  1909. asynchronously. The request userdata is always synchronously
  1910. returned regardless of whether a callback is provided and the
  1911. same userdata is passed to the callback if it is provided.
  1912. Returns: `uv_fs_t userdata` or `fail`
  1913. uv.fs_scandir_next({fs}) *uv.fs_scandir_next()*
  1914. Parameters:
  1915. - `fs`: `uv_fs_t userdata`
  1916. Called on a |uv_fs_t| returned by |uv.fs_scandir()| to get the
  1917. next directory entry data as a `name, type` pair. When there
  1918. are no more entries, `nil` is returned.
  1919. Note: This function only has a synchronous version. See
  1920. |uv.fs_opendir()| and its related functions for an
  1921. asynchronous version.
  1922. Returns: `string, string` or `nil` or `fail`
  1923. uv.fs_stat({path} [, {callback}]) *uv.fs_stat()*
  1924. Parameters:
  1925. - `path`: `string`
  1926. - `callback`: `callable` (async version) or `nil` (sync
  1927. version)
  1928. - `err`: `nil` or `string`
  1929. - `stat`: `table` or `nil` (see below)
  1930. Equivalent to `stat(2)`.
  1931. Returns (sync version): `table` or `fail`
  1932. - `dev` : `integer`
  1933. - `mode` : `integer`
  1934. - `nlink` : `integer`
  1935. - `uid` : `integer`
  1936. - `gid` : `integer`
  1937. - `rdev` : `integer`
  1938. - `ino` : `integer`
  1939. - `size` : `integer`
  1940. - `blksize` : `integer`
  1941. - `blocks` : `integer`
  1942. - `flags` : `integer`
  1943. - `gen` : `integer`
  1944. - `atime` : `table`
  1945. - `sec` : `integer`
  1946. - `nsec` : `integer`
  1947. - `mtime` : `table`
  1948. - `sec` : `integer`
  1949. - `nsec` : `integer`
  1950. - `ctime` : `table`
  1951. - `sec` : `integer`
  1952. - `nsec` : `integer`
  1953. - `birthtime` : `table`
  1954. - `sec` : `integer`
  1955. - `nsec` : `integer`
  1956. - `type` : `string`
  1957. Returns (async version): `uv_fs_t userdata`
  1958. uv.fs_fstat({fd} [, {callback}]) *uv.fs_fstat()*
  1959. Parameters:
  1960. - `fd`: `integer`
  1961. - `callback`: `callable` (async version) or `nil` (sync
  1962. version)
  1963. - `err`: `nil` or `string`
  1964. - `stat`: `table` or `nil` (see `uv.fs_stat`)
  1965. Equivalent to `fstat(2)`.
  1966. Returns (sync version): `table` or `fail` (see `uv.fs_stat`)
  1967. Returns (async version): `uv_fs_t userdata`
  1968. uv.fs_lstat({path} [, {callback}]) *uv.fs_lstat()*
  1969. Parameters:
  1970. - `fd`: `integer`
  1971. - `callback`: `callable` (async version) or `nil` (sync
  1972. version)
  1973. - `err`: `nil` or `string`
  1974. - `stat`: `table` or `nil` (see `uv.fs_stat`)
  1975. Equivalent to `lstat(2)`.
  1976. Returns (sync version): `table` or `fail` (see |uv.fs_stat()|)
  1977. Returns (async version): `uv_fs_t userdata`
  1978. uv.fs_rename({path}, {new_path} [, {callback}]) *uv.fs_rename()*
  1979. Parameters:
  1980. - `path`: `string`
  1981. - `new_path`: `string`
  1982. - `callback`: `callable` (async version) or `nil` (sync
  1983. version)
  1984. - `err`: `nil` or `string`
  1985. - `success`: `boolean` or `nil`
  1986. Equivalent to `rename(2)`.
  1987. Returns (sync version): `boolean` or `fail`
  1988. Returns (async version): `uv_fs_t userdata`
  1989. uv.fs_fsync({fd} [, {callback}]) *uv.fs_fsync()*
  1990. Parameters:
  1991. - `fd`: `integer`
  1992. - `callback`: `callable` (async version) or `nil` (sync
  1993. version)
  1994. - `err`: `nil` or `string`
  1995. - `success`: `boolean` or `nil`
  1996. Equivalent to `fsync(2)`.
  1997. Returns (sync version): `boolean` or `fail`
  1998. Returns (async version): `uv_fs_t userdata`
  1999. uv.fs_fdatasync({fd} [, {callback}]) *uv.fs_fdatasync()*
  2000. Parameters:
  2001. - `fd`: `integer`
  2002. - `callback`: `callable` (async version) or `nil` (sync
  2003. version)
  2004. - `err`: `nil` or `string`
  2005. - `success`: `boolean` or `nil`
  2006. Equivalent to `fdatasync(2)`.
  2007. Returns (sync version): `boolean` or `fail`
  2008. Returns (async version): `uv_fs_t userdata`
  2009. uv.fs_ftruncate({fd}, {offset} [, {callback}]) *uv.fs_ftruncate()*
  2010. Parameters:
  2011. - `fd`: `integer`
  2012. - `offset`: `integer`
  2013. - `callback`: `callable` (async version) or `nil` (sync
  2014. version)
  2015. - `err`: `nil` or `string`
  2016. - `success`: `boolean` or `nil`
  2017. Equivalent to `ftruncate(2)`.
  2018. Returns (sync version): `boolean` or `fail`
  2019. Returns (async version): `uv_fs_t userdata`
  2020. *uv.fs_sendfile()*
  2021. uv.fs_sendfile({out_fd}, {in_fd}, {in_offset}, {size} [, {callback}])
  2022. Parameters:
  2023. - `out_fd`: `integer`
  2024. - `in_fd`: `integer`
  2025. - `in_offset`: `integer`
  2026. - `size`: `integer`
  2027. - `callback`: `callable` (async version) or `nil` (sync
  2028. version)
  2029. - `err`: `nil` or `string`
  2030. - `bytes`: `integer` or `nil`
  2031. Limited equivalent to `sendfile(2)`. Returns the number of
  2032. bytes written.
  2033. Returns (sync version): `integer` or `fail`
  2034. Returns (async version): `uv_fs_t userdata`
  2035. uv.fs_access({path}, {mode} [, {callback}]) *uv.fs_access()*
  2036. Parameters:
  2037. - `path`: `string`
  2038. - `mode`: `integer`
  2039. - `callback`: `callable` (async version) or `nil` (sync
  2040. version)
  2041. - `err`: `nil` or `string`
  2042. - `permission`: `boolean` or `nil`
  2043. Equivalent to `access(2)` on Unix. Windows uses
  2044. `GetFileAttributesW()`. Access `mode` can be an integer or a
  2045. string containing `"R"` or `"W"` or `"X"`. Returns `true` or
  2046. `false` indicating access permission.
  2047. Returns (sync version): `boolean` or `fail`
  2048. Returns (async version): `uv_fs_t userdata`
  2049. uv.fs_chmod({path}, {mode} [, {callback}]) *uv.fs_chmod()*
  2050. Parameters:
  2051. - `path`: `string`
  2052. - `mode`: `integer`
  2053. - `callback`: `callable` (async version) or `nil` (sync
  2054. version)
  2055. - `err`: `nil` or `string`
  2056. - `success`: `boolean` or `nil`
  2057. Equivalent to `chmod(2)`.
  2058. Returns (sync version): `boolean` or `fail`
  2059. Returns (async version): `uv_fs_t userdata`
  2060. uv.fs_fchmod({fd}, {mode} [, {callback}]) *uv.fs_fchmod()*
  2061. Parameters:
  2062. - `fd`: `integer`
  2063. - `mode`: `integer`
  2064. - `callback`: `callable` (async version) or `nil` (sync
  2065. version)
  2066. - `err`: `nil` or `string`
  2067. - `success`: `boolean` or `nil`
  2068. Equivalent to `fchmod(2)`.
  2069. Returns (sync version): `boolean` or `fail`
  2070. Returns (async version): `uv_fs_t userdata`
  2071. uv.fs_utime({path}, {atime}, {mtime} [, {callback}]) *uv.fs_utime()*
  2072. Parameters:
  2073. - `path`: `string`
  2074. - `atime`: `number`
  2075. - `mtime`: `number`
  2076. - `callback`: `callable` (async version) or `nil` (sync
  2077. version)
  2078. - `err`: `nil` or `string`
  2079. - `success`: `boolean` or `nil`
  2080. Equivalent to `utime(2)`.
  2081. Returns (sync version): `boolean` or `fail`
  2082. Returns (async version): `uv_fs_t userdata`
  2083. uv.fs_futime({fd}, {atime}, {mtime} [, {callback}]) *uv.fs_futime()*
  2084. Parameters:
  2085. - `fd`: `integer`
  2086. - `atime`: `number`
  2087. - `mtime`: `number`
  2088. - `callback`: `callable` (async version) or `nil` (sync
  2089. version)
  2090. - `err`: `nil` or `string`
  2091. - `success`: `boolean` or `nil`
  2092. Equivalent to `futime(2)`.
  2093. Returns (sync version): `boolean` or `fail`
  2094. Returns (async version): `uv_fs_t userdata`
  2095. uv.fs_lutime({path}, {atime}, {mtime} [, {callback}]) *uv.fs_lutime()*
  2096. Parameters:
  2097. - `path`: `string`
  2098. - `atime`: `number`
  2099. - `mtime`: `number`
  2100. - `callback`: `callable` (async version) or `nil` (sync
  2101. version)
  2102. - `err`: `nil` or `string`
  2103. - `success`: `boolean` or `nil`
  2104. Equivalent to `lutime(2)`.
  2105. Returns (sync version): `boolean` or `fail`
  2106. Returns (async version): `uv_fs_t userdata`
  2107. uv.fs_link({path}, {new_path} [, {callback}]) *uv.fs_link()*
  2108. Parameters:
  2109. - `path`: `string`
  2110. - `new_path`: `string`
  2111. - `callback`: `callable` (async version) or `nil` (sync
  2112. version)
  2113. - `err`: `nil` or `string`
  2114. - `success`: `boolean` or `nil`
  2115. Equivalent to `link(2)`.
  2116. Returns (sync version): `boolean` or `fail`
  2117. Returns (async version): `uv_fs_t userdata`
  2118. uv.fs_symlink({path}, {new_path} [, {flags} [, {callback}]]) *uv.fs_symlink()*
  2119. Parameters:
  2120. - `path`: `string`
  2121. - `new_path`: `string`
  2122. - `flags`: `table`, `integer`, or `nil`
  2123. - `dir`: `boolean`
  2124. - `junction`: `boolean`
  2125. - `callback`: `callable` (async version) or `nil` (sync
  2126. version)
  2127. - `err`: `nil` or `string`
  2128. - `success`: `boolean` or `nil`
  2129. Equivalent to `symlink(2)`. If the `flags` parameter is
  2130. omitted, then the 3rd parameter will be treated as the
  2131. `callback`.
  2132. Returns (sync version): `boolean` or `fail`
  2133. Returns (async version): `uv_fs_t userdata`
  2134. uv.fs_readlink({path} [, {callback}]) *uv.fs_readlink()*
  2135. Parameters:
  2136. - `path`: `string`
  2137. - `callback`: `callable` (async version) or `nil` (sync
  2138. version)
  2139. - `err`: `nil` or `string`
  2140. - `path`: `string` or `nil`
  2141. Equivalent to `readlink(2)`.
  2142. Returns (sync version): `string` or `fail`
  2143. Returns (async version): `uv_fs_t userdata`
  2144. uv.fs_realpath({path} [, {callback}]) *uv.fs_realpath()*
  2145. Parameters:
  2146. - `path`: `string`
  2147. - `callback`: `callable` (async version) or `nil` (sync
  2148. version)
  2149. - `err`: `nil` or `string`
  2150. - `path`: `string` or `nil`
  2151. Equivalent to `realpath(3)`.
  2152. Returns (sync version): `string` or `fail`
  2153. Returns (async version): `uv_fs_t userdata`
  2154. uv.fs_chown({path}, {uid}, {gid} [, {callback}]) *uv.fs_chown()*
  2155. Parameters:
  2156. - `path`: `string`
  2157. - `uid`: `integer`
  2158. - `gid`: `integer`
  2159. - `callback`: `callable` (async version) or `nil` (sync
  2160. version)
  2161. - `err`: `nil` or `string`
  2162. - `success`: `boolean` or `nil`
  2163. Equivalent to `chown(2)`.
  2164. Returns (sync version): `boolean` or `fail`
  2165. Returns (async version): `uv_fs_t userdata`
  2166. uv.fs_fchown({fd}, {uid}, {gid} [, {callback}]) *uv.fs_fchown()*
  2167. Parameters:
  2168. - `fd`: `integer`
  2169. - `uid`: `integer`
  2170. - `gid`: `integer`
  2171. - `callback`: `callable` (async version) or `nil` (sync
  2172. version)
  2173. - `err`: `nil` or `string`
  2174. - `success`: `boolean` or `nil`
  2175. Equivalent to `fchown(2)`.
  2176. Returns (sync version): `boolean` or `fail`
  2177. Returns (async version): `uv_fs_t userdata`
  2178. uv.fs_lchown({fd}, {uid}, {gid} [, {callback}]) *uv.fs_lchown()*
  2179. Parameters:
  2180. - `fd`: `integer`
  2181. - `uid`: `integer`
  2182. - `gid`: `integer`
  2183. - `callback`: `callable` (async version) or `nil` (sync
  2184. version)
  2185. - `err`: `nil` or `string`
  2186. - `success`: `boolean` or `nil`
  2187. Equivalent to `lchown(2)`.
  2188. Returns (sync version): `boolean` or `fail`
  2189. Returns (async version): `uv_fs_t userdata`
  2190. uv.fs_copyfile({path}, {new_path} [, {flags} [, {callback}]]) *uv.fs_copyfile()*
  2191. Parameters:
  2192. - `path`: `string`
  2193. - `new_path`: `string`
  2194. - `flags`: `table`, `integer`, or `nil`
  2195. - `excl`: `boolean`
  2196. - `ficlone`: `boolean`
  2197. - `ficlone_force`: `boolean`
  2198. - `callback`: `callable` (async version) or `nil` (sync
  2199. version)
  2200. - `err`: `nil` or `string`
  2201. - `success`: `boolean` or `nil`
  2202. Copies a file from path to new_path. If the `flags` parameter
  2203. is omitted, then the 3rd parameter will be treated as the
  2204. `callback`.
  2205. Returns (sync version): `boolean` or `fail`
  2206. Returns (async version): `uv_fs_t userdata`
  2207. uv.fs_opendir({path} [, {callback} [, {entries}]]) *uv.fs_opendir()*
  2208. Parameters:
  2209. - `path`: `string`
  2210. - `callback`: `callable` (async version) or `nil` (sync
  2211. version)
  2212. - `err`: `nil` or `string`
  2213. - `dir`: `luv_dir_t userdata` or `nil`
  2214. - `entries`: `integer` or `nil`
  2215. Opens path as a directory stream. Returns a handle that the
  2216. user can pass to |uv.fs_readdir()|. The `entries` parameter
  2217. defines the maximum number of entries that should be returned
  2218. by each call to |uv.fs_readdir()|.
  2219. Returns (sync version): `luv_dir_t userdata` or `fail`
  2220. Returns (async version): `uv_fs_t userdata`
  2221. uv.fs_readdir({dir} [, {callback}]) *uv.fs_readdir()*
  2222. > method form `dir:readdir([callback])`
  2223. Parameters:
  2224. - `dir`: `luv_dir_t userdata`
  2225. - `callback`: `callable` (async version) or `nil` (sync
  2226. version)
  2227. - `err`: `nil` or `string`
  2228. - `entries`: `table` or `nil` (see below)
  2229. Iterates over the directory stream `luv_dir_t` returned by a
  2230. successful |uv.fs_opendir()| call. A table of data tables is
  2231. returned where the number of entries `n` is equal to or less
  2232. than the `entries` parameter used in the associated
  2233. |uv.fs_opendir()| call.
  2234. Returns (sync version): `table` or `fail`
  2235. - `[1, 2, 3, ..., n]` : `table`
  2236. - `name` : `string`
  2237. - `type` : `string`
  2238. Returns (async version): `uv_fs_t userdata`
  2239. uv.fs_closedir({dir} [, {callback}]) *uv.fs_closedir()*
  2240. > method form `dir:closedir([callback])`
  2241. Parameters:
  2242. - `dir`: `luv_dir_t userdata`
  2243. - `callback`: `callable` (async version) or `nil` (sync
  2244. version)
  2245. - `err`: `nil` or `string`
  2246. - `success`: `boolean` or `nil`
  2247. Closes a directory stream returned by a successful
  2248. |uv.fs_opendir()| call.
  2249. Returns (sync version): `boolean` or `fail`
  2250. Returns (async version): `uv_fs_t userdata`
  2251. uv.fs_statfs({path} [, {callback}]) *uv.fs_statfs()*
  2252. Parameters:
  2253. - `path`: `string`
  2254. - `callback`: `callable` (async version) or `nil` (sync
  2255. version)
  2256. - `err`: `nil` or `string`
  2257. - `table` or `nil` (see below)
  2258. Equivalent to `statfs(2)`.
  2259. Returns `table` or `nil`
  2260. - `type` : `integer`
  2261. - `bsize` : `integer`
  2262. - `blocks` : `integer`
  2263. - `bfree` : `integer`
  2264. - `bavail` : `integer`
  2265. - `files` : `integer`
  2266. - `ffree` : `integer`
  2267. ==============================================================================
  2268. THREAD POOL WORK SCHEDULING *luv-thread-pool-work-scheduling*
  2269. Libuv provides a threadpool which can be used to run user code and get
  2270. notified in the loop thread. This threadpool is internally used to run all
  2271. file system operations, as well as `getaddrinfo` and `getnameinfo` requests.
  2272. >
  2273. local function work_callback(a, b)
  2274. return a + b
  2275. end
  2276. local function after_work_callback(c)
  2277. print("The result is: " .. c)
  2278. end
  2279. local work = uv.new_work(work_callback, after_work_callback)
  2280. work:queue(1, 2)
  2281. -- output: "The result is: 3"
  2282. <
  2283. uv.new_work({work_callback}, {after_work_callback}) *uv.new_work()*
  2284. Parameters:
  2285. - `work_callback`: `function`
  2286. - `...`: `threadargs` passed to/from
  2287. `uv.queue_work(work_ctx, ...)`
  2288. - `after_work_callback`: `function`
  2289. - `...`: `threadargs` returned from `work_callback`
  2290. Creates and initializes a new `luv_work_ctx_t` (not
  2291. `uv_work_t`). Returns the Lua userdata wrapping it.
  2292. Returns: `luv_work_ctx_t userdata`
  2293. uv.queue_work({work_ctx}, {...}) *uv.queue_work()*
  2294. > method form `work_ctx:queue(...)`
  2295. Parameters:
  2296. - `work_ctx`: `luv_work_ctx_t userdata`
  2297. - `...`: `threadargs`
  2298. Queues a work request which will run `work_callback` in a new
  2299. Lua state in a thread from the threadpool with any additional
  2300. arguments from `...`. Values returned from `work_callback` are
  2301. passed to `after_work_callback`, which is called in the main
  2302. loop thread.
  2303. Returns: `boolean` or `fail`
  2304. ==============================================================================
  2305. DNS UTILITY FUNCTIONS *luv-dns-utility-functions*
  2306. uv.getaddrinfo({host}, {service} [, {hints} [, {callback}]]) *uv.getaddrinfo()*
  2307. Parameters:
  2308. - `host`: `string` or `nil`
  2309. - `service`: `string` or `nil`
  2310. - `hints`: `table` or `nil`
  2311. - `family`: `string` or `integer` or `nil`
  2312. - `socktype`: `string` or `integer` or `nil`
  2313. - `protocol`: `string` or `integer` or `nil`
  2314. - `addrconfig`: `boolean` or `nil`
  2315. - `v4mapped`: `boolean` or `nil`
  2316. - `all`: `boolean` or `nil`
  2317. - `numerichost`: `boolean` or `nil`
  2318. - `passive`: `boolean` or `nil`
  2319. - `numericserv`: `boolean` or `nil`
  2320. - `canonname`: `boolean` or `nil`
  2321. - `callback`: `callable` (async version) or `nil` (sync
  2322. version)
  2323. - `err`: `nil` or `string`
  2324. - `addresses`: `table` or `nil` (see below)
  2325. Equivalent to `getaddrinfo(3)`. Either `node` or `service` may
  2326. be `nil` but not both.
  2327. Valid hint strings for the keys that take a string:
  2328. - `family`: `"unix"`, `"inet"`, `"inet6"`, `"ipx"`,
  2329. `"netlink"`, `"x25"`, `"ax25"`, `"atmpvc"`, `"appletalk"`,
  2330. or `"packet"`
  2331. - `socktype`: `"stream"`, `"dgram"`, `"raw"`, `"rdm"`, or
  2332. `"seqpacket"`
  2333. - `protocol`: will be looked up using the `getprotobyname(3)`
  2334. function (examples: `"ip"`, `"icmp"`, `"tcp"`, `"udp"`, etc)
  2335. Returns (sync version): `table` or `fail`
  2336. - `[1, 2, 3, ..., n]` : `table`
  2337. - `addr` : `string`
  2338. - `family` : `string`
  2339. - `port` : `integer` or `nil`
  2340. - `socktype` : `string`
  2341. - `protocol` : `string`
  2342. - `canonname` : `string` or `nil`
  2343. Returns (async version): `uv_getaddrinfo_t userdata` or `fail`
  2344. uv.getnameinfo({address} [, {callback}]) *uv.getnameinfo()*
  2345. Parameters:
  2346. - `address`: `table`
  2347. - `ip`: `string` or `nil`
  2348. - `port`: `integer` or `nil`
  2349. - `family`: `string` or `integer` or `nil`
  2350. - `callback`: `callable` (async version) or `nil` (sync
  2351. version)
  2352. - `err`: `nil` or `string`
  2353. - `host`: `string` or `nil`
  2354. - `service`: `string` or `nil`
  2355. Equivalent to `getnameinfo(3)`.
  2356. When specified, `family` must be one of `"unix"`, `"inet"`,
  2357. `"inet6"`, `"ipx"`, `"netlink"`, `"x25"`, `"ax25"`,
  2358. `"atmpvc"`, `"appletalk"`, or `"packet"`.
  2359. Returns (sync version): `string, string` or `fail`
  2360. Returns (async version): `uv_getnameinfo_t userdata` or `fail`
  2361. ==============================================================================
  2362. THREADING AND SYNCHRONIZATION UTILITIES *luv-threading-and-synchronization-utilities*
  2363. Libuv provides cross-platform implementations for multiple threading an
  2364. synchronization primitives. The API largely follows the pthreads API.
  2365. uv.new_thread([{options}, ] {entry}, {...}) *uv.new_thread()*
  2366. Parameters:
  2367. - `options`: `table` or `nil`
  2368. - `stack_size`: `integer` or `nil`
  2369. - `entry`: `function`
  2370. - `...`: `threadargs` passed to `entry`
  2371. Creates and initializes a `luv_thread_t` (not `uv_thread_t`).
  2372. Returns the Lua userdata wrapping it and asynchronously
  2373. executes `entry`, which can be either a Lua function or a Lua
  2374. function dumped to a string. Additional arguments `...` are
  2375. passed to the `entry` function and an optional `options` table
  2376. may be provided. Currently accepted `option` fields are
  2377. `stack_size`.
  2378. Returns: `luv_thread_t userdata` or `fail`
  2379. uv.thread_equal({thread}, {other_thread}) *uv.thread_equal()*
  2380. > method form `thread:equal(other_thread)`
  2381. Parameters:
  2382. - `thread`: `luv_thread_t userdata`
  2383. - `other_thread`: `luv_thread_t userdata`
  2384. Returns a boolean indicating whether two threads are the same.
  2385. This function is equivalent to the `__eq` metamethod.
  2386. Returns: `boolean`
  2387. uv.thread_self() *uv.thread_self()*
  2388. Returns the handle for the thread in which this is called.
  2389. Returns: `luv_thread_t`
  2390. uv.thread_join({thread}) *uv.thread_join()*
  2391. > method form `thread:join()`
  2392. Parameters:
  2393. - `thread`: `luv_thread_t userdata`
  2394. Waits for the `thread` to finish executing its entry function.
  2395. Returns: `boolean` or `fail`
  2396. uv.sleep({msec}) *uv.sleep()*
  2397. Parameters:
  2398. - `msec`: `integer`
  2399. Pauses the thread in which this is called for a number of
  2400. milliseconds.
  2401. Returns: Nothing.
  2402. ==============================================================================
  2403. MISCELLANEOUS UTILITIES *luv-miscellaneous-utilities*
  2404. uv.exepath() *uv.exepath()*
  2405. Returns the executable path.
  2406. Returns: `string` or `fail`
  2407. uv.cwd() *uv.cwd()*
  2408. Returns the current working directory.
  2409. Returns: `string` or `fail`
  2410. uv.chdir({cwd}) *uv.chdir()*
  2411. Parameters:
  2412. - `cwd`: `string`
  2413. Sets the current working directory with the string `cwd`.
  2414. Returns: `0` or `fail`
  2415. uv.get_process_title() *uv.get_process_title()*
  2416. Returns the title of the current process.
  2417. Returns: `string` or `fail`
  2418. uv.set_process_title({title}) *uv.set_process_title()*
  2419. Parameters:
  2420. - `title`: `string`
  2421. Sets the title of the current process with the string `title`.
  2422. Returns: `0` or `fail`
  2423. uv.get_total_memory() *uv.get_total_memory()*
  2424. Returns the current total system memory in bytes.
  2425. Returns: `number`
  2426. uv.get_free_memory() *uv.get_free_memory()*
  2427. Returns the current free system memory in bytes.
  2428. Returns: `number`
  2429. uv.get_constrained_memory() *uv.get_constrained_memory()*
  2430. Gets the amount of memory available to the process in bytes
  2431. based on limits imposed by the OS. If there is no such
  2432. constraint, or the constraint is unknown, 0 is returned. Note
  2433. that it is not unusual for this value to be less than or
  2434. greater than the total system memory.
  2435. Returns: `number`
  2436. uv.resident_set_memory() *uv.resident_set_memory()*
  2437. Returns the resident set size (RSS) for the current process.
  2438. Returns: `integer` or `fail`
  2439. uv.getrusage() *uv.getrusage()*
  2440. Returns the resource usage.
  2441. Returns: `table` or `fail`
  2442. - `utime` : `table` (user CPU time used)
  2443. - `sec` : `integer`
  2444. - `usec` : `integer`
  2445. - `stime` : `table` (system CPU time used)
  2446. - `sec` : `integer`
  2447. - `usec` : `integer`
  2448. - `maxrss` : `integer` (maximum resident set size)
  2449. - `ixrss` : `integer` (integral shared memory size)
  2450. - `idrss` : `integer` (integral unshared data size)
  2451. - `isrss` : `integer` (integral unshared stack size)
  2452. - `minflt` : `integer` (page reclaims (soft page faults))
  2453. - `majflt` : `integer` (page faults (hard page faults))
  2454. - `nswap` : `integer` (swaps)
  2455. - `inblock` : `integer` (block input operations)
  2456. - `oublock` : `integer` (block output operations)
  2457. - `msgsnd` : `integer` (IPC messages sent)
  2458. - `msgrcv` : `integer` (IPC messages received)
  2459. - `nsignals` : `integer` (signals received)
  2460. - `nvcsw` : `integer` (voluntary context switches)
  2461. - `nivcsw` : `integer` (involuntary context switches)
  2462. uv.available_parallelism() *uv.available_parallelism()*
  2463. Returns an estimate of the default amount of parallelism a
  2464. program should use. Always returns a non-zero value.
  2465. On Linux, inspects the calling thread’s CPU affinity mask to
  2466. determine if it has been pinned to specific CPUs.
  2467. On Windows, the available parallelism may be underreported on
  2468. systems with more than 64 logical CPUs.
  2469. On other platforms, reports the number of CPUs that the
  2470. operating system considers to be online.
  2471. Returns: `integer`
  2472. uv.cpu_info() *uv.cpu_info()*
  2473. Returns information about the CPU(s) on the system as a table
  2474. of tables for each CPU found.
  2475. Returns: `table` or `fail`
  2476. - `[1, 2, 3, ..., n]` : `table`
  2477. - `model` : `string`
  2478. - `speed` : `number`
  2479. - `times` : `table`
  2480. - `user` : `number`
  2481. - `nice` : `number`
  2482. - `sys` : `number`
  2483. - `idle` : `number`
  2484. - `irq` : `number`
  2485. uv.getpid() *uv.getpid()*
  2486. DEPRECATED: Please use |uv.os_getpid()| instead.
  2487. uv.getuid() *uv.getuid()*
  2488. Returns the user ID of the process.
  2489. Returns: `integer`
  2490. Note: This is not a libuv function and is not supported on
  2491. Windows.
  2492. uv.getgid() *uv.getgid()*
  2493. Returns the group ID of the process.
  2494. Returns: `integer`
  2495. Note: This is not a libuv function and is not supported on
  2496. Windows.
  2497. uv.setuid({id}) *uv.setuid()*
  2498. Parameters:
  2499. - `id`: `integer`
  2500. Sets the user ID of the process with the integer `id`.
  2501. Returns: Nothing.
  2502. Note: This is not a libuv function and is not supported on
  2503. Windows.
  2504. uv.setgid({id}) *uv.setgid()*
  2505. Parameters:
  2506. - `id`: `integer`
  2507. Sets the group ID of the process with the integer `id`.
  2508. Returns: Nothing.
  2509. Note: This is not a libuv function and is not supported on
  2510. Windows.
  2511. uv.hrtime() *uv.hrtime()*
  2512. Returns a current high-resolution time in nanoseconds as a
  2513. number. This is relative to an arbitrary time in the past. It
  2514. is not related to the time of day and therefore not subject to
  2515. clock drift. The primary use is for measuring time between
  2516. intervals.
  2517. Returns: `number`
  2518. uv.uptime() *uv.uptime()*
  2519. Returns the current system uptime in seconds.
  2520. Returns: `number` or `fail`
  2521. uv.print_all_handles() *uv.print_all_handles()*
  2522. Prints all handles associated with the main loop to stderr.
  2523. The format is `[flags] handle-type handle-address` . Flags are
  2524. `R` for referenced, `A` for active and `I` for internal.
  2525. Returns: Nothing.
  2526. Note: This is not available on Windows.
  2527. WARNING: This function is meant for ad hoc debugging, there
  2528. are no API/ABI stability guarantees.
  2529. uv.print_active_handles() *uv.print_active_handles()*
  2530. The same as |uv.print_all_handles()| except only active
  2531. handles are printed.
  2532. Returns: Nothing.
  2533. Note: This is not available on Windows.
  2534. WARNING: This function is meant for ad hoc debugging, there
  2535. are no API/ABI stability guarantees.
  2536. uv.guess_handle({fd}) *uv.guess_handle()*
  2537. Parameters:
  2538. - `fd`: `integer`
  2539. Used to detect what type of stream should be used with a given
  2540. file descriptor `fd`. Usually this will be used during
  2541. initialization to guess the type of the stdio streams.
  2542. Returns: `string`
  2543. uv.gettimeofday() *uv.gettimeofday()*
  2544. Cross-platform implementation of `gettimeofday(2)`. Returns
  2545. the seconds and microseconds of a unix time as a pair.
  2546. Returns: `integer, integer` or `fail`
  2547. uv.interface_addresses() *uv.interface_addresses()*
  2548. Returns address information about the network interfaces on
  2549. the system in a table. Each table key is the name of the
  2550. interface while each associated value is an array of address
  2551. information where fields are `ip`, `family`, `netmask`,
  2552. `internal`, and `mac`.
  2553. Returns: `table`
  2554. - `[name(s)]` : `table`
  2555. - `ip` : `string`
  2556. - `family` : `string`
  2557. - `netmask` : `string`
  2558. - `internal` : `boolean`
  2559. - `mac` : `string`
  2560. uv.if_indextoname({ifindex}) *uv.if_indextoname()*
  2561. Parameters:
  2562. - `ifindex`: `integer`
  2563. IPv6-capable implementation of `if_indextoname(3)`.
  2564. Returns: `string` or `fail`
  2565. uv.if_indextoiid({ifindex}) *uv.if_indextoiid()*
  2566. Parameters:
  2567. - `ifindex`: `integer`
  2568. Retrieves a network interface identifier suitable for use in
  2569. an IPv6 scoped address. On Windows, returns the numeric
  2570. `ifindex` as a string. On all other platforms,
  2571. |uv.if_indextoname()| is used.
  2572. Returns: `string` or `fail`
  2573. uv.loadavg() *uv.loadavg()*
  2574. Returns the load average as a triad. Not supported on Windows.
  2575. Returns: `number, number, number`
  2576. uv.os_uname() *uv.os_uname()*
  2577. Returns system information.
  2578. Returns: `table`
  2579. - `sysname` : `string`
  2580. - `release` : `string`
  2581. - `version` : `string`
  2582. - `machine` : `string`
  2583. uv.os_gethostname() *uv.os_gethostname()*
  2584. Returns the hostname.
  2585. Returns: `string`
  2586. uv.os_getenv({name} [, {size}]) *uv.os_getenv()*
  2587. Parameters:
  2588. - `name`: `string`
  2589. - `size`: `integer` (default = `LUAL_BUFFERSIZE`)
  2590. Returns the environment variable specified by `name` as
  2591. string. The internal buffer size can be set by defining
  2592. `size`. If omitted, `LUAL_BUFFERSIZE` is used. If the
  2593. environment variable exceeds the storage available in the
  2594. internal buffer, `ENOBUFS` is returned. If no matching
  2595. environment variable exists, `ENOENT` is returned.
  2596. Returns: `string` or `fail`
  2597. WARNING: This function is not thread safe.
  2598. uv.os_setenv({name}, {value}) *uv.os_setenv()*
  2599. Parameters:
  2600. - `name`: `string`
  2601. - `value`: `string`
  2602. Sets the environmental variable specified by `name` with the
  2603. string `value`.
  2604. Returns: `boolean` or `fail`
  2605. WARNING: This function is not thread safe.
  2606. uv.os_unsetenv() *uv.os_unsetenv()*
  2607. Returns: `boolean` or `fail`
  2608. WARNING: This function is not thread safe.
  2609. uv.os_environ() *uv.os_environ()*
  2610. Returns all environmental variables as a dynamic table of
  2611. names associated with their corresponding values.
  2612. Returns: `table`
  2613. WARNING: This function is not thread safe.
  2614. uv.os_homedir() *uv.os_homedir()*
  2615. Returns: `string` or `fail`
  2616. WARNING: This function is not thread safe.
  2617. uv.os_tmpdir() *uv.os_tmpdir()*
  2618. Returns: `string` or `fail`
  2619. WARNING: This function is not thread safe.
  2620. uv.os_get_passwd() *uv.os_get_passwd()*
  2621. Returns password file information.
  2622. Returns: `table`
  2623. - `username` : `string`
  2624. - `uid` : `integer`
  2625. - `gid` : `integer`
  2626. - `shell` : `string`
  2627. - `homedir` : `string`
  2628. uv.os_getpid() *uv.os_getpid()*
  2629. Returns the current process ID.
  2630. Returns: `number`
  2631. uv.os_getppid() *uv.os_getppid()*
  2632. Returns the parent process ID.
  2633. Returns: `number`
  2634. uv.os_getpriority({pid}) *uv.os_getpriority()*
  2635. Parameters:
  2636. - `pid`: `integer`
  2637. Returns the scheduling priority of the process specified by
  2638. `pid`.
  2639. Returns: `number` or `fail`
  2640. uv.os_setpriority({pid}, {priority}) *uv.os_setpriority()*
  2641. Parameters:
  2642. - `pid`: `integer`
  2643. - `priority`: `integer`
  2644. Sets the scheduling priority of the process specified by
  2645. `pid`. The `priority` range is between -20 (high priority) and
  2646. 19 (low priority).
  2647. Returns: `boolean` or `fail`
  2648. uv.random({len}, {flags} [, {callback}]) *uv.random()*
  2649. Parameters:
  2650. - `len`: `integer`
  2651. - `flags`: `nil` (see below)
  2652. - `callback`: `callable` (async version) or `nil` (sync
  2653. version)
  2654. - `err`: `nil` or `string`
  2655. - `bytes`: `string` or `nil`
  2656. Fills a string of length `len` with cryptographically strong
  2657. random bytes acquired from the system CSPRNG. `flags` is
  2658. reserved for future extension and must currently be `nil` or
  2659. `0` or `{}`.
  2660. Short reads are not possible. When less than `len` random
  2661. bytes are available, a non-zero error value is returned or
  2662. passed to the callback. If the callback is omitted, this
  2663. function is completed synchronously.
  2664. The synchronous version may block indefinitely when not enough
  2665. entropy is available. The asynchronous version may not ever
  2666. finish when the system is low on entropy.
  2667. Returns (sync version): `string` or `fail`
  2668. Returns (async version): `0` or `fail`
  2669. uv.translate_sys_error({errcode}) *uv.translate_sys_error()*
  2670. Parameters:
  2671. - `errcode`: `integer`
  2672. Returns the libuv error message and error name (both in string
  2673. form, see `err` and `name` in |luv-error-handling|) equivalent
  2674. to the given platform dependent error code: POSIX error codes
  2675. on Unix (the ones stored in errno), and Win32 error codes on
  2676. Windows (those returned by GetLastError() or
  2677. WSAGetLastError()).
  2678. Returns: `string, string` or `nil`
  2679. ==============================================================================
  2680. METRICS OPERATIONS *luv-metrics-operations*
  2681. uv.metrics_idle_time() *uv.metrics_idle_time()*
  2682. Retrieve the amount of time the event loop has been idle in
  2683. the kernel’s event provider (e.g. `epoll_wait`). The call is
  2684. thread safe.
  2685. The return value is the accumulated time spent idle in the
  2686. kernel’s event provider starting from when the |uv_loop_t| was
  2687. configured to collect the idle time.
  2688. Note: The event loop will not begin accumulating the event
  2689. provider’s idle time until calling `loop_configure` with
  2690. `"metrics_idle_time"`.
  2691. Returns: `number`
  2692. ==============================================================================
  2693. CREDITS *luv-credits*
  2694. This document is a reformatted version of the LUV documentation, based on
  2695. commit c51e705 (5 May 2022) of the luv repository
  2696. https://github.com/luvit/luv/commit/c51e7052ec4f0a25058f70c1b4ee99dd36180e59.
  2697. Included from https://github.com/nanotee/luv-vimdocs with kind permission.
  2698. vim:tw=78:ts=8:ft=help:norl: