@@ -468,6 +468,48 @@ proc send*(socket: AsyncSocket, data: string,
468468 else :
469469 await send (socket.fd.AsyncFD , data, flags)
470470
471+ proc acceptAddr * (socket: AsyncSocket , flags = {SocketFlag .SafeDisconn },
472+ inheritable = defined (nimInheritHandles)):
473+ owned (Future [tuple [address: string , client: AsyncSocket ]]) =
474+ # # Accepts a new connection. Returns a future containing the client socket
475+ # # corresponding to that connection and the remote address of the client.
476+ # #
477+ # # If `inheritable` is false (the default), the resulting client socket will
478+ # # not be inheritable by child processes.
479+ # #
480+ # # The future will complete when the connection is successfully accepted.
481+ var retFuture = newFuture [tuple [address: string , client: AsyncSocket ]](" asyncnet.acceptAddr" )
482+ var fut = acceptAddr (socket.fd.AsyncFD , flags, inheritable)
483+ fut.callback =
484+ proc (future: Future [tuple [address: string , client: AsyncFD ]]) =
485+ assert future.finished
486+ if future.failed:
487+ retFuture.fail (future.readError)
488+ else :
489+ let resultTup = (future.read.address,
490+ newAsyncSocket (future.read.client, socket.domain,
491+ socket.sockType, socket.protocol, socket.isBuffered, inheritable))
492+ retFuture.complete (resultTup)
493+ return retFuture
494+
495+ proc accept * (socket: AsyncSocket ,
496+ flags = {SocketFlag .SafeDisconn }): owned (Future [AsyncSocket ]) =
497+ # # Accepts a new connection. Returns a future containing the client socket
498+ # # corresponding to that connection.
499+ # # If `inheritable` is false (the default), the resulting client socket will
500+ # # not be inheritable by child processes.
501+ # # The future will complete when the connection is successfully accepted.
502+ var retFut = newFuture [AsyncSocket ](" asyncnet.accept" )
503+ var fut = acceptAddr (socket, flags)
504+ fut.callback =
505+ proc (future: Future [tuple [address: string , client: AsyncSocket ]]) =
506+ assert future.finished
507+ if future.failed:
508+ retFut.fail (future.readError)
509+ else :
510+ retFut.complete (future.read.client)
511+ return retFut
512+
471513proc recvLineInto * (socket: AsyncSocket , resString: FutureVar [string ],
472514 flags = {SocketFlag .SafeDisconn }, maxLength = MaxLineLength ) {.async .} =
473515 # # Reads a line of data from `socket` into `resString`.
@@ -766,48 +808,6 @@ when defineSsl:
766808 else :
767809 result = getPeerCertificates (socket.sslHandle)
768810
769- proc acceptAddr * (socket: AsyncSocket , flags = {SocketFlag .SafeDisconn },
770- inheritable = defined (nimInheritHandles)):
771- owned (Future [tuple [address: string , client: AsyncSocket ]]) {.async .} =
772- # # Accepts a new connection. Returns a future containing the client socket
773- # # corresponding to that connection and the remote address of the client.
774- # #
775- # # If `inheritable` is false (the default), the resulting client socket will
776- # # not be inheritable by child processes.
777- # #
778- # # The future will complete when the connection is successfully accepted.
779- let (address, fd) = await acceptAddr (socket.fd.AsyncFD , flags, inheritable)
780- let client = newAsyncSocket (fd, socket.domain, socket.sockType,
781- socket.protocol, socket.isBuffered, inheritable)
782- result = (address, client)
783- if socket.isSsl:
784- when defineSsl:
785- if socket.sslContext == nil :
786- raiseSSLError (" The SSL Context is closed/unset" )
787- wrapSocket (socket.sslContext, result .client)
788- if result .client.sslHandle == nil :
789- raiseSslHandleError ()
790- let flags = {SocketFlag .SafeDisconn }
791- sslLoop (result .client, flags, SSL_accept (result .client.sslHandle))
792-
793- proc accept * (socket: AsyncSocket ,
794- flags = {SocketFlag .SafeDisconn }): owned (Future [AsyncSocket ]) =
795- # # Accepts a new connection. Returns a future containing the client socket
796- # # corresponding to that connection.
797- # # If `inheritable` is false (the default), the resulting client socket will
798- # # not be inheritable by child processes.
799- # # The future will complete when the connection is successfully accepted.
800- var retFut = newFuture [AsyncSocket ](" asyncnet.accept" )
801- var fut = acceptAddr (socket, flags)
802- fut.callback =
803- proc (future: Future [tuple [address: string , client: AsyncSocket ]]) =
804- assert future.finished
805- if future.failed:
806- retFut.fail (future.readError)
807- else :
808- retFut.complete (future.read.client)
809- return retFut
810-
811811proc getSockOpt * (socket: AsyncSocket , opt: SOBool , level = SOL_SOCKET ): bool {.
812812 tags : [ReadIOEffect ].} =
813813 # # Retrieves option `opt` as a boolean value.
0 commit comments