123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>std/asyncnet</title>
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- Favicon -->
- <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
- <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
- <!-- CSS -->
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
- <!-- JS -->
- <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
- </head>
- <body>
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">std/asyncnet</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-select-wrapper">
- <label for="theme-select">Theme: </label>
- <select id="theme-select" onchange="setTheme(this.value)">
- <option value="auto">🌗 Match OS</option>
- <option value="dark">🌑 Dark</option>
- <option value="light">🌕 Light</option>
- </select>
- </div>
- <div id="global-links">
- <ul class="simple-boot">
- <li><a href="manual.html">Manual</a></li>
- <li><a href="lib.html">Standard library</a></li>
- <li> <a id="indexLink" href="theindex.html">Index</a></li>
- <li><a href="compiler/theindex.html">Compiler docs</a></li>
- <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
- <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="search" id="searchInput"
- oninput="search()" />
- </div>
-
- <ul class="simple simple-toc" id="toc-list">
- <li><a class="reference" id="asynchronous-io-in-nim_toc" href="#asynchronous-io-in-nim">Asynchronous IO in Nim</a></li>
- <li><a class="reference" id="ssl_toc" href="#ssl">SSL</a></li>
- <li><a class="reference" id="examples_toc" href="#examples">Examples</a></li>
- <ul class="simple"><li><a class="reference" id="examples-chat-server_toc" href="#examples-chat-server">Chat server</a></li>
- </ul><li>
- <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#AsyncSocket" title="AsyncSocket = ref AsyncSocketDesc">AsyncSocket</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">accept
- <li><a class="reference" href="#accept%2CAsyncSocket" title="accept(socket: AsyncSocket; flags = {SafeDisconn}): owned(Future[AsyncSocket])">accept(socket: AsyncSocket; flags = {SafeDisconn}): owned(Future[AsyncSocket])</a></li>
- </ul>
- <ul class="simple nested-toc-section">acceptAddr
- <li><a class="reference" href="#acceptAddr%2CAsyncSocket" title="acceptAddr(socket: AsyncSocket; flags = {SafeDisconn};
- inheritable = defined(nimInheritHandles)): owned(
- Future[tuple[address: string, client: AsyncSocket]])">acceptAddr(socket: AsyncSocket; flags = {SafeDisconn};
- inheritable = defined(nimInheritHandles)): owned(
- Future[tuple[address: string, client: AsyncSocket]])</a></li>
- </ul>
- <ul class="simple nested-toc-section">bindAddr
- <li><a class="reference" href="#bindAddr%2CAsyncSocket%2Cstring" title="bindAddr(socket: AsyncSocket; port = Port(0); address = "")">bindAddr(socket: AsyncSocket; port = Port(0); address = "")</a></li>
- </ul>
- <ul class="simple nested-toc-section">bindUnix
- <li><a class="reference" href="#bindUnix%2CAsyncSocket%2Cstring" title="bindUnix(socket: AsyncSocket; path: string)">bindUnix(socket: AsyncSocket; path: string)</a></li>
- </ul>
- <ul class="simple nested-toc-section">close
- <li><a class="reference" href="#close%2CAsyncSocket" title="close(socket: AsyncSocket)">close(socket: AsyncSocket)</a></li>
- </ul>
- <ul class="simple nested-toc-section">connect
- <li><a class="reference" href="#connect%2CAsyncSocket%2Cstring%2CPort" title="connect(socket: AsyncSocket; address: string; port: Port): owned(
- Future[void])">connect(socket: AsyncSocket; address: string; port: Port): owned(
- Future[void])</a></li>
- </ul>
- <ul class="simple nested-toc-section">connectUnix
- <li><a class="reference" href="#connectUnix%2CAsyncSocket%2Cstring" title="connectUnix(socket: AsyncSocket; path: string): owned(Future[void])">connectUnix(socket: AsyncSocket; path: string): owned(Future[void])</a></li>
- </ul>
- <ul class="simple nested-toc-section">dial
- <li><a class="reference" href="#dial%2Cstring%2CPort" title="dial(address: string; port: Port; protocol = IPPROTO_TCP; buffered = true): owned(
- Future[AsyncSocket])">dial(address: string; port: Port; protocol = IPPROTO_TCP; buffered = true): owned(
- Future[AsyncSocket])</a></li>
- </ul>
- <ul class="simple nested-toc-section">getFd
- <li><a class="reference" href="#getFd%2CAsyncSocket" title="getFd(socket: AsyncSocket): SocketHandle">getFd(socket: AsyncSocket): SocketHandle</a></li>
- </ul>
- <ul class="simple nested-toc-section">getLocalAddr
- <li><a class="reference" href="#getLocalAddr%2CAsyncSocket" title="getLocalAddr(socket: AsyncSocket): (string, Port)">getLocalAddr(socket: AsyncSocket): (string, Port)</a></li>
- </ul>
- <ul class="simple nested-toc-section">getPeerAddr
- <li><a class="reference" href="#getPeerAddr%2CAsyncSocket" title="getPeerAddr(socket: AsyncSocket): (string, Port)">getPeerAddr(socket: AsyncSocket): (string, Port)</a></li>
- </ul>
- <ul class="simple nested-toc-section">getPeerCertificates
- <li><a class="reference" href="#getPeerCertificates%2CAsyncSocket" title="getPeerCertificates(socket: AsyncSocket): seq[Certificate]">getPeerCertificates(socket: AsyncSocket): seq[Certificate]</a></li>
- </ul>
- <ul class="simple nested-toc-section">getSockOpt
- <li><a class="reference" href="#getSockOpt%2CAsyncSocket%2CSOBool" title="getSockOpt(socket: AsyncSocket; opt: SOBool; level = SOL_SOCKET): bool">getSockOpt(socket: AsyncSocket; opt: SOBool; level = SOL_SOCKET): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">hasDataBuffered
- <li><a class="reference" href="#hasDataBuffered%2CAsyncSocket" title="hasDataBuffered(s: AsyncSocket): bool">hasDataBuffered(s: AsyncSocket): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">isClosed
- <li><a class="reference" href="#isClosed%2CAsyncSocket" title="isClosed(socket: AsyncSocket): bool">isClosed(socket: AsyncSocket): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">isSsl
- <li><a class="reference" href="#isSsl%2CAsyncSocket" title="isSsl(socket: AsyncSocket): bool">isSsl(socket: AsyncSocket): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">listen
- <li><a class="reference" href="#listen%2CAsyncSocket" title="listen(socket: AsyncSocket; backlog = SOMAXCONN)">listen(socket: AsyncSocket; backlog = SOMAXCONN)</a></li>
- </ul>
- <ul class="simple nested-toc-section">newAsyncSocket
- <li><a class="reference" href="#newAsyncSocket%2Ccint%2Ccint%2Ccint" title="newAsyncSocket(domain, sockType, protocol: cint; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(AsyncSocket)">newAsyncSocket(domain, sockType, protocol: cint; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(AsyncSocket)</a></li>
- <li><a class="reference" href="#newAsyncSocket%2CDomain%2CSockType%2CProtocol" title="newAsyncSocket(domain: Domain = AF_INET; sockType: SockType = SOCK_STREAM;
- protocol: Protocol = IPPROTO_TCP; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(AsyncSocket)">newAsyncSocket(domain: Domain = AF_INET; sockType: SockType = SOCK_STREAM;
- protocol: Protocol = IPPROTO_TCP; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(AsyncSocket)</a></li>
- <li><a class="reference" href="#newAsyncSocket%2CAsyncFD%2CDomain%2CSockType%2CProtocol" title="newAsyncSocket(fd: AsyncFD; domain: Domain = AF_INET;
- sockType: SockType = SOCK_STREAM;
- protocol: Protocol = IPPROTO_TCP; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(AsyncSocket)">newAsyncSocket(fd: AsyncFD; domain: Domain = AF_INET;
- sockType: SockType = SOCK_STREAM;
- protocol: Protocol = IPPROTO_TCP; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(AsyncSocket)</a></li>
- </ul>
- <ul class="simple nested-toc-section">recv
- <li><a class="reference" href="#recv%2CAsyncSocket%2Cint" title="recv(socket: AsyncSocket; size: int; flags = {SafeDisconn}): owned(
- Future[string])">recv(socket: AsyncSocket; size: int; flags = {SafeDisconn}): owned(
- Future[string])</a></li>
- </ul>
- <ul class="simple nested-toc-section">recvFrom
- <li><a class="reference" href="#recvFrom%2CAsyncSocket%2CFutureVar%5Bstring%5D%2Cint%2CFutureVar%5Bstring%5D%2CFutureVar%5BPort%5D" title="recvFrom(socket: AsyncSocket; data: FutureVar[string]; size: int;
- address: FutureVar[string]; port: FutureVar[Port];
- flags = {SafeDisconn}): owned(Future[int])">recvFrom(socket: AsyncSocket; data: FutureVar[string]; size: int;
- address: FutureVar[string]; port: FutureVar[Port];
- flags = {SafeDisconn}): owned(Future[int])</a></li>
- <li><a class="reference" href="#recvFrom%2CAsyncSocket%2Cint" title="recvFrom(socket: AsyncSocket; size: int; flags = {SafeDisconn}): owned(
- Future[tuple[data: string, address: string, port: Port]])">recvFrom(socket: AsyncSocket; size: int; flags = {SafeDisconn}): owned(
- Future[tuple[data: string, address: string, port: Port]])</a></li>
- </ul>
- <ul class="simple nested-toc-section">recvInto
- <li><a class="reference" href="#recvInto%2CAsyncSocket%2Cpointer%2Cint" title="recvInto(socket: AsyncSocket; buf: pointer; size: int; flags = {SafeDisconn}): owned(
- Future[int])">recvInto(socket: AsyncSocket; buf: pointer; size: int; flags = {SafeDisconn}): owned(
- Future[int])</a></li>
- </ul>
- <ul class="simple nested-toc-section">recvLine
- <li><a class="reference" href="#recvLine%2CAsyncSocket" title="recvLine(socket: AsyncSocket; flags = {SafeDisconn}; maxLength = MaxLineLength): owned(
- Future[string])">recvLine(socket: AsyncSocket; flags = {SafeDisconn}; maxLength = MaxLineLength): owned(
- Future[string])</a></li>
- </ul>
- <ul class="simple nested-toc-section">recvLineInto
- <li><a class="reference" href="#recvLineInto%2CAsyncSocket%2CFutureVar%5Bstring%5D" title="recvLineInto(socket: AsyncSocket; resString: FutureVar[string];
- flags = {SafeDisconn}; maxLength = MaxLineLength): owned(
- Future[void])">recvLineInto(socket: AsyncSocket; resString: FutureVar[string];
- flags = {SafeDisconn}; maxLength = MaxLineLength): owned(
- Future[void])</a></li>
- </ul>
- <ul class="simple nested-toc-section">send
- <li><a class="reference" href="#send%2CAsyncSocket%2Cpointer%2Cint" title="send(socket: AsyncSocket; buf: pointer; size: int; flags = {SafeDisconn}): owned(
- Future[void])">send(socket: AsyncSocket; buf: pointer; size: int; flags = {SafeDisconn}): owned(
- Future[void])</a></li>
- <li><a class="reference" href="#send%2CAsyncSocket%2Cstring" title="send(socket: AsyncSocket; data: string; flags = {SafeDisconn}): owned(
- Future[void])">send(socket: AsyncSocket; data: string; flags = {SafeDisconn}): owned(
- Future[void])</a></li>
- </ul>
- <ul class="simple nested-toc-section">sendTo
- <li><a class="reference" href="#sendTo%2CAsyncSocket%2Cstring%2CPort%2Cstring" title="sendTo(socket: AsyncSocket; address: string; port: Port; data: string;
- flags = {SafeDisconn}): owned(Future[void])">sendTo(socket: AsyncSocket; address: string; port: Port; data: string;
- flags = {SafeDisconn}): owned(Future[void])</a></li>
- </ul>
- <ul class="simple nested-toc-section">setSockOpt
- <li><a class="reference" href="#setSockOpt%2CAsyncSocket%2CSOBool%2Cbool" title="setSockOpt(socket: AsyncSocket; opt: SOBool; value: bool; level = SOL_SOCKET)">setSockOpt(socket: AsyncSocket; opt: SOBool; value: bool; level = SOL_SOCKET)</a></li>
- </ul>
- <ul class="simple nested-toc-section">sslHandle
- <li><a class="reference" href="#sslHandle%2CAsyncSocket" title="sslHandle(self: AsyncSocket): SslPtr">sslHandle(self: AsyncSocket): SslPtr</a></li>
- </ul>
- <ul class="simple nested-toc-section">wrapConnectedSocket
- <li><a class="reference" href="#wrapConnectedSocket%2CSslContext%2CAsyncSocket%2CSslHandshakeType%2Cstring" title="wrapConnectedSocket(ctx: SslContext; socket: AsyncSocket;
- handshake: SslHandshakeType; hostname: string = "")">wrapConnectedSocket(ctx: SslContext; socket: AsyncSocket;
- handshake: SslHandshakeType; hostname: string = "")</a></li>
- </ul>
- <ul class="simple nested-toc-section">wrapSocket
- <li><a class="reference" href="#wrapSocket%2CSslContext%2CAsyncSocket" title="wrapSocket(ctx: SslContext; socket: AsyncSocket)">wrapSocket(ctx: SslContext; socket: AsyncSocket)</a></li>
- </ul>
- </ul>
- </details>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L1" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
- <div id="tocRoot"></div>
-
- <p class="module-desc">This module implements a high-level asynchronous sockets API based on the asynchronous dispatcher defined in the <tt class="docutils literal"><span class="pre"><span class="Identifier">asyncdispatch</span></span></tt> module.
- <h1><a class="toc-backref" id="asynchronous-io-in-nim" href="#asynchronous-io-in-nim">Asynchronous IO in Nim</a></h1><p>Async IO in Nim consists of multiple layers (from highest to lowest):</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre"><span class="Identifier">asyncnet</span></span></tt> module</li>
- <li>Async await</li>
- <li><tt class="docutils literal"><span class="pre"><span class="Identifier">asyncdispatch</span></span></tt> module (event loop)</li>
- <li><tt class="docutils literal"><span class="pre"><span class="Identifier">selectors</span></span></tt> module</li>
- </ul>
- <p>Each builds on top of the layers below it. The selectors module is an abstraction for the various system <tt class="docutils literal"><span class="pre"><span class="Identifier">select</span><span class="Punctuation">(</span><span class="Punctuation">)</span></span></tt> mechanisms such as epoll or kqueue. If you wish you can use it directly, and some people have done so <a class="reference external" href="https://goran.krampe.se/2014/10/25/nim-socketserver/">successfully</a>. But you must be aware that on Windows it only supports <tt class="docutils literal"><span class="pre"><span class="Identifier">select</span><span class="Punctuation">(</span><span class="Punctuation">)</span></span></tt>.</p>
- <p>The async dispatcher implements the proactor pattern and also has an implementation of IOCP. It implements the proactor pattern for other OS' via the selectors module. Futures are also implemented here, and indeed all the procedures return a future.</p>
- <p>The final layer is the async await transformation. This allows you to write asynchronous code in a synchronous style and works similar to C#'s await. The transformation works by converting any async procedures into an iterator.</p>
- <p>This is all single threaded, fully non-blocking and does give you a lot of control. In theory you should be able to work with any of these layers interchangeably (as long as you only care about non-Windows platforms).</p>
- <p>For most applications using <tt class="docutils literal"><span class="pre"><span class="Identifier">asyncnet</span></span></tt> is the way to go as it builds over all the layers, providing some extra features such as buffering.</p>
- <h1><a class="toc-backref" id="ssl" href="#ssl">SSL</a></h1><p>SSL can be enabled by compiling with the <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="Identifier">d</span><span class="Punctuation">:</span><span class="Identifier">ssl</span></span></tt> flag.</p>
- <p>You must create a new SSL context with the <tt class="docutils literal"><span class="pre"><span class="Identifier">newContext</span></span></tt> function defined in the <tt class="docutils literal"><span class="pre"><span class="Identifier">net</span></span></tt> module. You may then call <tt class="docutils literal"><span class="pre"><span class="Identifier">wrapSocket</span></span></tt> on your socket using the newly created SSL context to get an SSL socket.</p>
- <h1><a class="toc-backref" id="examples" href="#examples">Examples</a></h1>
- <h2><a class="toc-backref" id="examples-chat-server" href="#examples-chat-server">Chat server</a></h2><p>The following example demonstrates a simple chat server.</p>
- <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">asyncnet</span><span class="Punctuation">,</span> <span class="Identifier">asyncdispatch</span><span class="Punctuation">]</span>
- <span class="Keyword">var</span> <span class="Identifier">clients</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">threadvar</span><span class="Operator">.</span><span class="Punctuation">}</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">AsyncSocket</span><span class="Punctuation">]</span>
- <span class="Keyword">proc</span> <span class="Identifier">processClient</span><span class="Punctuation">(</span><span class="Identifier">client</span><span class="Punctuation">:</span> <span class="Identifier">AsyncSocket</span><span class="Punctuation">)</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">async</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span>
- <span class="Keyword">while</span> <span class="Identifier">true</span><span class="Punctuation">:</span>
- <span class="Keyword">let</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="Identifier">await</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">recvLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">if</span> <span class="Identifier">line</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">0</span><span class="Punctuation">:</span> <span class="Keyword">break</span>
- <span class="Keyword">for</span> <span class="Identifier">c</span> <span class="Keyword">in</span> <span class="Identifier">clients</span><span class="Punctuation">:</span>
- <span class="Identifier">await</span> <span class="Identifier">c</span><span class="Operator">.</span><span class="Identifier">send</span><span class="Punctuation">(</span><span class="Identifier">line</span> <span class="Operator">&</span> <span class="StringLit">"</span><span class="EscapeSequence">\c</span><span class="EscapeSequence">\L</span><span class="StringLit">"</span><span class="Punctuation">)</span>
- <span class="Keyword">proc</span> <span class="Identifier">serve</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">async</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span>
- <span class="Identifier">clients</span> <span class="Operator">=</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">]</span>
- <span class="Keyword">var</span> <span class="Identifier">server</span> <span class="Operator">=</span> <span class="Identifier">newAsyncSocket</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">setSockOpt</span><span class="Punctuation">(</span><span class="Identifier">OptReuseAddr</span><span class="Punctuation">,</span> <span class="Identifier">true</span><span class="Punctuation">)</span>
- <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">bindAddr</span><span class="Punctuation">(</span><span class="Identifier">Port</span><span class="Punctuation">(</span><span class="DecNumber">12345</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
- <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">listen</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
-
- <span class="Keyword">while</span> <span class="Identifier">true</span><span class="Punctuation">:</span>
- <span class="Keyword">let</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">await</span> <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">accept</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">clients</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Identifier">client</span>
-
- <span class="Identifier">asyncCheck</span> <span class="Identifier">processClient</span><span class="Punctuation">(</span><span class="Identifier">client</span><span class="Punctuation">)</span>
- <span class="Identifier">asyncCheck</span> <span class="Identifier">serve</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">runForever</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
- </p>
- <div class="section" id="6">
- <h1><a class="toc-backref" href="#6">Imports</a></h1>
- <dl class="item">
- <a class="reference external" href="since.html">since</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="syncio.html">syncio</a>, <a class="reference external" href="asyncdispatch.html">asyncdispatch</a>, <a class="reference external" href="nativesockets.html">nativesockets</a>, <a class="reference external" href="net.html">net</a>, <a class="reference external" href="os.html">os</a>, <a class="reference external" href="openssl.html">openssl</a>
- </dl>
- </div>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="AsyncSocket">
- <dt><pre><a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Identifier">AsyncSocketDesc</span></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L135" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L135" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <div id="accept-procs-all">
- <div id="accept,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#accept%2CAsyncSocket"><span class="Identifier">accept</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span>
- <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Accepts a new connection. Returns a future containing the client socket corresponding to that connection. If <tt class="docutils literal"><span class="pre"><span class="Identifier">inheritable</span></span></tt> is false (the default), the resulting client socket will not be inheritable by child processes. The future will complete when the connection is successfully accepted.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L495" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L495" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="acceptAddr-procs-all">
- <div id="acceptAddr,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#acceptAddr%2CAsyncSocket"><span class="Identifier">acceptAddr</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">;</span>
- <span class="Identifier">inheritable</span> <span class="Other">=</span> <span class="Identifier">defined</span><span class="Other">(</span><span class="Identifier">nimInheritHandles</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span>
- <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <span class="Identifier">client</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">]</span><span class="Other">]</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Accepts a new connection. Returns a future containing the client socket corresponding to that connection and the remote address of the client.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">inheritable</span></span></tt> is false (the default), the resulting client socket will not be inheritable by child processes.</p>
- <p>The future will complete when the connection is successfully accepted.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L471" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L471" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="bindAddr-procs-all">
- <div id="bindAddr,AsyncSocket,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#bindAddr%2CAsyncSocket%2Cstring"><span class="Identifier">bindAddr</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">port</span> <span class="Other">=</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">(</span><span class="DecNumber">0</span><span class="Other">)</span><span class="Other">;</span> <span class="Identifier">address</span> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Binds <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt>:<tt class="docutils literal"><span class="pre"><span class="Identifier">port</span></span></tt> to the socket.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> is "" then ADDR_ANY will be bound.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L643" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L643" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="bindUnix-procs-all">
- <div id="bindUnix,AsyncSocket,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#bindUnix%2CAsyncSocket%2Cstring"><span class="Identifier">bindUnix</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">path</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Binds Unix socket to <tt class="docutils literal"><span class="pre"><span class="Identifier">path</span></span></tt>. This only works on Unix-style systems: Mac OS X, BSD and Linux
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L701" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L701" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="close-procs-all">
- <div id="close,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#close%2CAsyncSocket"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">LibraryError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Closes the socket.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L723" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L723" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="connect-procs-all">
- <div id="connect,AsyncSocket,string,Port">
- <dt><pre><span class="Keyword">proc</span> <a href="#connect%2CAsyncSocket%2Cstring%2CPort"><span class="Identifier">connect</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#owned"><span class="Identifier">owned</span></a><span class="Other">(</span>
- <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">,</span>
- <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Connects <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> to server at <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span><span class="Punctuation">:</span><span class="Identifier">port</span></span></tt>.</p>
- <p>Returns a <tt class="docutils literal"><span class="pre"><span class="Identifier">Future</span></span></tt> which will complete when the connection succeeds or an error occurs.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L301" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L301" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="connectUnix-procs-all">
- <div id="connectUnix,AsyncSocket,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#connectUnix%2CAsyncSocket%2Cstring"><span class="Identifier">connectUnix</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">path</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Binds Unix socket to <tt class="docutils literal"><span class="pre"><span class="Identifier">path</span></span></tt>. This only works on Unix-style systems: Mac OS X, BSD and Linux
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L670" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L670" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="dial-procs-all">
- <div id="dial,string,Port">
- <dt><pre><span class="Keyword">proc</span> <a href="#dial%2Cstring%2CPort"><span class="Identifier">dial</span></a><span class="Other">(</span><span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span> <span class="Identifier">protocol</span> <span class="Other">=</span> <span class="Identifier">IPPROTO_TCP</span><span class="Other">;</span> <span class="Identifier">buffered</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span>
- <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Establishes connection to the specified <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt>:<tt class="docutils literal"><span class="pre"><span class="Identifier">port</span></span></tt> pair via the specified protocol. The procedure iterates through possible resolutions of the <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> until it succeeds, meaning that it seamlessly works with both IPv4 and IPv6. Returns AsyncSocket ready to send or receive data.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L290" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L290" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getFd-procs-all">
- <div id="getFd,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getFd%2CAsyncSocket"><span class="Identifier">getFd</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="winlean.html#SocketHandle"><span class="Identifier">SocketHandle</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the socket's file descriptor.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L824" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L824" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getLocalAddr-procs-all">
- <div id="getLocalAddr,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getLocalAddr%2CAsyncSocket"><span class="Identifier">getLocalAddr</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Get the socket's local address and port number.</p>
- <p>This is high-level interface for <span id="getsockname_1">getsockname</span>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L180" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L180" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getPeerAddr-procs-all">
- <div id="getPeerAddr,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getPeerAddr%2CAsyncSocket"><span class="Identifier">getPeerAddr</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Get the socket's peer address and port number.</p>
- <p>This is high-level interface for <span id="getpeername_1">getpeername</span>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L187" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L187" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getPeerCertificates-procs-all">
- <div id="getPeerCertificates,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getPeerCertificates%2CAsyncSocket"><span class="Identifier">getPeerCertificates</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span><a href="net.html#Certificate"><span class="Identifier">Certificate</span></a><span class="Other">]</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the certificate chain received by the peer we are connected to through the given socket. The handshake must have been completed and the certificate chain must have been verified successfully or else an empty sequence is returned. The chain is ordered from leaf certificate to root certificate.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L797" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L797" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getSockOpt-procs-all">
- <div id="getSockOpt,AsyncSocket,SOBool">
- <dt><pre><span class="Keyword">proc</span> <a href="#getSockOpt%2CAsyncSocket%2CSOBool"><span class="Identifier">getSockOpt</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">opt</span><span class="Other">:</span> <a href="net.html#SOBool"><span class="Identifier">SOBool</span></a><span class="Other">;</span> <span class="Identifier">level</span> <span class="Other">=</span> <span class="Identifier">SOL_SOCKET</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Retrieves option <tt class="docutils literal"><span class="pre"><span class="Identifier">opt</span></span></tt> as a boolean value.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L808" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L808" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="hasDataBuffered-procs-all">
- <div id="hasDataBuffered,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#hasDataBuffered%2CAsyncSocket"><span class="Identifier">hasDataBuffered</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Determines whether an AsyncSocket has data buffered.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L663" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L663" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="isClosed-procs-all">
- <div id="isClosed,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#isClosed%2CAsyncSocket"><span class="Identifier">isClosed</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Determines whether the socket has been closed.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L828" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L828" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="isSsl-procs-all">
- <div id="isSsl,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#isSsl%2CAsyncSocket"><span class="Identifier">isSsl</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Determines whether <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> is a SSL socket.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L820" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L820" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="listen-procs-all">
- <div id="listen,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#listen%2CAsyncSocket"><span class="Identifier">listen</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">backlog</span> <span class="Other">=</span> <span class="Identifier">SOMAXCONN</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Marks <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> as accepting connections. <tt class="docutils literal"><span class="pre"><span class="Identifier">Backlog</span></span></tt> specifies the maximum length of the queue of pending connections.</p>
- <p>Raises an OSError error upon failure.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L634" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L634" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="newAsyncSocket-procs-all">
- <div id="newAsyncSocket,cint,cint,cint">
- <dt><pre><span class="Keyword">proc</span> <a href="#newAsyncSocket%2Ccint%2Ccint%2Ccint"><span class="Identifier">newAsyncSocket</span></a><span class="Other">(</span><span class="Identifier">domain</span><span class="Other">,</span> <span class="Identifier">sockType</span><span class="Other">,</span> <span class="Identifier">protocol</span><span class="Other">:</span> <a href="ctypes.html#cint"><span class="Identifier">cint</span></a><span class="Other">;</span> <span class="Identifier">buffered</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">;</span>
- <span class="Identifier">inheritable</span> <span class="Other">=</span> <span class="Identifier">defined</span><span class="Other">(</span><span class="Identifier">nimInheritHandles</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">AsyncSocket</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates a new asynchronous socket.</p>
- <p>This procedure will also create a brand new file descriptor for this socket.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">inheritable</span></span></tt> is false (the default), the new file descriptor will not be inheritable by child processes.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L193" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L193" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="newAsyncSocket,Domain,SockType,Protocol">
- <dt><pre><span class="Keyword">proc</span> <a href="#newAsyncSocket%2CDomain%2CSockType%2CProtocol"><span class="Identifier">newAsyncSocket</span></a><span class="Other">(</span><span class="Identifier">domain</span><span class="Other">:</span> <a href="nativesockets.html#Domain"><span class="Identifier">Domain</span></a> <span class="Other">=</span> <span class="Identifier">AF_INET</span><span class="Other">;</span> <span class="Identifier">sockType</span><span class="Other">:</span> <a href="nativesockets.html#SockType"><span class="Identifier">SockType</span></a> <span class="Other">=</span> <span class="Identifier">SOCK_STREAM</span><span class="Other">;</span>
- <span class="Identifier">protocol</span><span class="Other">:</span> <a href="nativesockets.html#Protocol"><span class="Identifier">Protocol</span></a> <span class="Other">=</span> <span class="Identifier">IPPROTO_TCP</span><span class="Other">;</span> <span class="Identifier">buffered</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">;</span>
- <span class="Identifier">inheritable</span> <span class="Other">=</span> <span class="Identifier">defined</span><span class="Other">(</span><span class="Identifier">nimInheritHandles</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">AsyncSocket</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates a new asynchronous socket.</p>
- <p>This procedure will also create a brand new file descriptor for this socket.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">inheritable</span></span></tt> is false (the default), the new file descriptor will not be inheritable by child processes.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L165" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L165" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="newAsyncSocket,AsyncFD,Domain,SockType,Protocol">
- <dt><pre><span class="Keyword">proc</span> <a href="#newAsyncSocket%2CAsyncFD%2CDomain%2CSockType%2CProtocol"><span class="Identifier">newAsyncSocket</span></a><span class="Other">(</span><span class="Identifier">fd</span><span class="Other">:</span> <a href="asyncdispatch.html#AsyncFD"><span class="Identifier">AsyncFD</span></a><span class="Other">;</span> <span class="Identifier">domain</span><span class="Other">:</span> <a href="nativesockets.html#Domain"><span class="Identifier">Domain</span></a> <span class="Other">=</span> <span class="Identifier">AF_INET</span><span class="Other">;</span>
- <span class="Identifier">sockType</span><span class="Other">:</span> <a href="nativesockets.html#SockType"><span class="Identifier">SockType</span></a> <span class="Other">=</span> <span class="Identifier">SOCK_STREAM</span><span class="Other">;</span>
- <span class="Identifier">protocol</span><span class="Other">:</span> <a href="nativesockets.html#Protocol"><span class="Identifier">Protocol</span></a> <span class="Other">=</span> <span class="Identifier">IPPROTO_TCP</span><span class="Other">;</span> <span class="Identifier">buffered</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">;</span>
- <span class="Identifier">inheritable</span> <span class="Other">=</span> <span class="Identifier">defined</span><span class="Other">(</span><span class="Identifier">nimInheritHandles</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">AsyncSocket</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates a new <tt class="docutils literal"><span class="pre"><span class="Identifier">AsyncSocket</span></span></tt> based on the supplied params.</p>
- <p>The supplied <tt class="docutils literal"><span class="pre"><span class="Identifier">fd</span></span></tt>'s non-blocking state will be enabled implicitly.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">inheritable</span></span></tt> is false (the default), the supplied <tt class="docutils literal"><span class="pre"><span class="Identifier">fd</span></span></tt> will not be inheritable by child processes.</p>
- <p><strong>Note</strong>: This procedure will <strong>NOT</strong> register <tt class="docutils literal"><span class="pre"><span class="Identifier">fd</span></span></tt> with the global async dispatcher. You need to do this manually. If you have used <tt class="docutils literal"><span class="pre"><span class="Identifier">newAsyncNativeSocket</span></span></tt> to create <tt class="docutils literal"><span class="pre"><span class="Identifier">fd</span></span></tt> then it's already registered.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L137" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L137" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="recv-procs-all">
- <div id="recv,AsyncSocket,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#recv%2CAsyncSocket%2Cint"><span class="Identifier">recv</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span>
- <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Reads <strong>up to</strong> <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> bytes from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>.</p>
- <p>For buffered sockets this function will attempt to read all the requested data. It will read this data in <tt class="docutils literal"><span class="pre"><span class="Identifier">BufferSize</span></span></tt> chunks.</p>
- <p>For unbuffered sockets this function makes no effort to read all the data requested. It will return as much data as the operating system gives it.</p>
- <p>If socket is disconnected during the recv operation then the future may complete with only a part of the requested data.</p>
- <p>If socket is disconnected and no data is available to be read then the future will complete with a value of <tt class="docutils literal"><span class="pre"><span class="StringLit">""</span></span></tt>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L391" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L391" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="recvFrom-procs-all">
- <div id="recvFrom,AsyncSocket,FutureVar[string],int,FutureVar[string],FutureVar[Port]">
- <dt><pre><span class="Keyword">proc</span> <a href="#recvFrom%2CAsyncSocket%2CFutureVar%5Bstring%5D%2Cint%2CFutureVar%5Bstring%5D%2CFutureVar%5BPort%5D"><span class="Identifier">recvFrom</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="asyncfutures.html#FutureVar"><span class="Identifier">FutureVar</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span>
- <span class="Identifier">address</span><span class="Other">:</span> <a href="asyncfutures.html#FutureVar"><span class="Identifier">FutureVar</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="asyncfutures.html#FutureVar"><span class="Identifier">FutureVar</span></a><span class="Other">[</span><a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">]</span><span class="Other">;</span>
- <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Receives a datagram data from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> into <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt>, which must be at least of size <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt>. The address and port of datagram's sender will be stored into <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">port</span></span></tt>, respectively. Returned future will complete once one datagram has been received, and will return size of packet received.</p>
- <p>If an error occurs an OSError exception will be raised.</p>
- <p>This proc is normally used with connectionless sockets (UDP sockets).</p>
- <p><strong>Notes</strong></p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt> must be initialized to the length of <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt>.</li>
- <li><tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> must be initialized to 46 in length.</li>
- </ul>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L881" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L881" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="recvFrom,AsyncSocket,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#recvFrom%2CAsyncSocket%2Cint"><span class="Identifier">recvFrom</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span>
- <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">]</span><span class="Other">]</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Receives a datagram data from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>, which must be at least of size <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt>. Returned future will complete once one datagram has been received and will return tuple with: data of packet received; and address and port of datagram's sender.</p>
- <p>If an error occurs an OSError exception will be raised.</p>
- <p>This proc is normally used with connectionless sockets (UDP sockets).</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L935" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L935" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="recvInto-procs-all">
- <div id="recvInto,AsyncSocket,pointer,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#recvInto%2CAsyncSocket%2Cpointer%2Cint"><span class="Identifier">recvInto</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span>
- <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Reads <strong>up to</strong> <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> bytes from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> into <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt>.</p>
- <p>For buffered sockets this function will attempt to read all the requested data. It will read this data in <tt class="docutils literal"><span class="pre"><span class="Identifier">BufferSize</span></span></tt> chunks.</p>
- <p>For unbuffered sockets this function makes no effort to read all the data requested. It will return as much data as the operating system gives it.</p>
- <p>If socket is disconnected during the recv operation then the future may complete with only a part of the requested data.</p>
- <p>If socket is disconnected and no data is available to be read then the future will complete with a value of <tt class="docutils literal"><span class="pre"><span class="DecNumber">0</span></span></tt>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L343" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L343" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="recvLine-procs-all">
- <div id="recvLine,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#recvLine%2CAsyncSocket"><span class="Identifier">recvLine</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">;</span>
- <span class="Identifier">maxLength</span> <span class="Other">=</span> <span class="Identifier">MaxLineLength</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Reads a line of data from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>. Returned future will complete once a full line is read or an error occurs.</p>
- <p>If a full line is read <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is not added to <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt>, however if solely <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is read then <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> will be set to it.</p>
- <p>If the socket is disconnected, <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> will be set to <tt class="docutils literal"><span class="pre"><span class="StringLit">""</span></span></tt>.</p>
- <p>If the socket is disconnected in the middle of a line (before <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is read) then line will be set to <tt class="docutils literal"><span class="pre"><span class="StringLit">""</span></span></tt>. The partial line <strong>will be lost</strong>.</p>
- <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">maxLength</span></span></tt> parameter determines the maximum amount of characters that can be read. The result is truncated after that.</p>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- The <tt class="docutils literal"><span class="pre"><span class="Identifier">Peek</span></span></tt> flag is not yet implemented.</div>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- <tt class="docutils literal"><span class="pre"><span class="Identifier">recvLine</span></span></tt> on unbuffered sockets assumes that the protocol uses <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> to delimit a new line.</div>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L606" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L606" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="recvLineInto-procs-all">
- <div id="recvLineInto,AsyncSocket,FutureVar[string]">
- <dt><pre><span class="Keyword">proc</span> <a href="#recvLineInto%2CAsyncSocket%2CFutureVar%5Bstring%5D"><span class="Identifier">recvLineInto</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">resString</span><span class="Other">:</span> <a href="asyncfutures.html#FutureVar"><span class="Identifier">FutureVar</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">;</span>
- <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">;</span> <span class="Identifier">maxLength</span> <span class="Other">=</span> <span class="Identifier">MaxLineLength</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#owned"><span class="Identifier">owned</span></a><span class="Other">(</span>
- <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Reads a line of data from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> into <tt class="docutils literal"><span class="pre"><span class="Identifier">resString</span></span></tt>.</p>
- <p>If a full line is read <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is not added to <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt>, however if solely <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is read then <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> will be set to it.</p>
- <p>If the socket is disconnected, <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> will be set to <tt class="docutils literal"><span class="pre"><span class="StringLit">""</span></span></tt>.</p>
- <p>If the socket is disconnected in the middle of a line (before <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is read) then line will be set to <tt class="docutils literal"><span class="pre"><span class="StringLit">""</span></span></tt>. The partial line <strong>will be lost</strong>.</p>
- <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">maxLength</span></span></tt> parameter determines the maximum amount of characters that can be read. <tt class="docutils literal"><span class="pre"><span class="Identifier">resString</span></span></tt> will be truncated after that.</p>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- The <tt class="docutils literal"><span class="pre"><span class="Identifier">Peek</span></span></tt> flag is not yet implemented.</div>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- <tt class="docutils literal"><span class="pre"><span class="Identifier">recvLineInto</span></span></tt> on unbuffered sockets assumes that the protocol uses <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> to delimit a new line.</div>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L514" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L514" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="send-procs-all">
- <div id="send,AsyncSocket,pointer,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#send%2CAsyncSocket%2Cpointer%2Cint"><span class="Identifier">send</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#owned"><span class="Identifier">owned</span></a><span class="Other">(</span>
- <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Sends <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> bytes from <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>. The returned future will complete once all data has been sent.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L444" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L444" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="send,AsyncSocket,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#send%2CAsyncSocket%2Cstring"><span class="Identifier">send</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#owned"><span class="Identifier">owned</span></a><span class="Other">(</span>
- <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Sends <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>. The returned future will complete once all data has been sent.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L458" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L458" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="sendTo-procs-all">
- <div id="sendTo,AsyncSocket,string,Port,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#sendTo%2CAsyncSocket%2Cstring%2CPort%2Cstring"><span class="Identifier">sendTo</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
- <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>This proc sends <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt> to the specified <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt>, which may be an IP address or a hostname. If a hostname is specified this function will try each IP of that hostname. The returned future will complete once all data has been sent.</p>
- <p>If an error occurs an OSError exception will be raised.</p>
- <p>This proc is normally used with connectionless sockets (UDP sockets).</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L834" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L834" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="setSockOpt-procs-all">
- <div id="setSockOpt,AsyncSocket,SOBool,bool">
- <dt><pre><span class="Keyword">proc</span> <a href="#setSockOpt%2CAsyncSocket%2CSOBool%2Cbool"><span class="Identifier">setSockOpt</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span> <span class="Identifier">opt</span><span class="Other">:</span> <a href="net.html#SOBool"><span class="Identifier">SOBool</span></a><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a><span class="Other">;</span>
- <span class="Identifier">level</span> <span class="Other">=</span> <span class="Identifier">SOL_SOCKET</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Sets option <tt class="docutils literal"><span class="pre"><span class="Identifier">opt</span></span></tt> to a boolean value specified by <tt class="docutils literal"><span class="pre"><span class="Identifier">value</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L814" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L814" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="sslHandle-procs-all">
- <div id="sslHandle,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#sslHandle%2CAsyncSocket"><span class="Identifier">sslHandle</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="openssl.html#SslPtr"><span class="Identifier">SslPtr</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Retrieve the ssl pointer of <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>. Useful for interfacing with <tt class="docutils literal"><span class="pre"><span class="Identifier">openssl</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L749" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L749" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="wrapConnectedSocket-procs-all">
- <div id="wrapConnectedSocket,SslContext,AsyncSocket,SslHandshakeType,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#wrapConnectedSocket%2CSslContext%2CAsyncSocket%2CSslHandshakeType%2Cstring"><span class="Identifier">wrapConnectedSocket</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">;</span>
- <span class="Identifier">handshake</span><span class="Other">:</span> <a href="net.html#SslHandshakeType"><span class="Identifier">SslHandshakeType</span></a><span class="Other">;</span> <span class="Identifier">hostname</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Wraps a connected socket in an SSL context. This function effectively turns <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> into an SSL socket. <tt class="docutils literal"><span class="pre"><span class="Identifier">hostname</span></span></tt> should be specified so that the client knows which hostname the server certificate should be validated against.</p>
- <p>This should be called on a connected socket, and will perform an SSL handshake immediately.</p>
- <p><strong>Disclaimer</strong>: This code is not well tested, may be very unsafe and prone to security vulnerabilities.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L772" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L772" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="wrapSocket-procs-all">
- <div id="wrapSocket,SslContext,AsyncSocket">
- <dt><pre><span class="Keyword">proc</span> <a href="#wrapSocket%2CSslContext%2CAsyncSocket"><span class="Identifier">wrapSocket</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">socket</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Wraps a socket in an SSL context. This function effectively turns <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> into an SSL socket.</p>
- <p><strong>Disclaimer</strong>: This code is not well tested, may be very unsafe and prone to security vulnerabilities.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncnet.nim#L754" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncnet.nim#L754" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- </div>
- </div>
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br>
- <small style="color: var(--hint);">Made with Nim. Generated: 2025-03-12 16:39:39 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|