luvref.txt 158 KB

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