summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/asyncnet.nim16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/pure/asyncnet.nim b/lib/pure/asyncnet.nim
index 39d05d36b..1b11aaffc 100644
--- a/lib/pure/asyncnet.nim
+++ b/lib/pure/asyncnet.nim
@@ -87,6 +87,12 @@ type
     of false: nil
   AsyncSocket* = ref AsyncSocketDesc
 
+when defined(ssl):
+  type HandshakeType* = enum
+    handshakeNone,
+    handshakeAsClient,
+    handshakeAsServer
+
 {.deprecated: [PAsyncSocket: AsyncSocket].}
 
 # TODO: Save AF, domain etc info and reuse it in procs which need it like connect.
@@ -418,7 +424,7 @@ proc close*(socket: AsyncSocket) =
   socket.closed = true # TODO: Add extra debugging checks for this.
 
 when defined(ssl):
-  proc wrapSocket*(ctx: SslContext, socket: AsyncSocket) =
+  proc wrapSocket*(ctx: SslContext, socket: AsyncSocket, handshake: HandshakeType = handshakeNone) =
     ## Wraps a socket in an SSL context. This function effectively turns
     ## ``socket`` into an SSL socket.
     ##
@@ -434,6 +440,14 @@ when defined(ssl):
     socket.bioOut = bioNew(bio_s_mem())
     sslSetBio(socket.sslHandle, socket.bioIn, socket.bioOut)
 
+    case handshake
+    of handshakeNone:
+      discard
+    of handshakeAsClient:
+      sslSetConnectState(socket.sslHandle)
+    of handshakeAsServer:
+      sslSetAcceptState(socket.sslHandle)
+
 proc getSockOpt*(socket: AsyncSocket, opt: SOBool, level = SOL_SOCKET): bool {.
   tags: [ReadIOEffect].} =
   ## Retrieves option ``opt`` as a boolean value.