diff options
author | Wim Lewis <wiml@hhhh.org> | 2015-04-10 15:51:39 -0700 |
---|---|---|
committer | Wim Lewis <wiml@hhhh.org> | 2015-04-23 20:45:33 -0700 |
commit | 9c19ce0698fe8bf5baad5cebf78776c161dceb8e (patch) | |
tree | d2aeb2f810eb3150e2ed87c7d24fc4524fcbe214 /lib/pure/asyncnet.nim | |
parent | 0c947f31baab5cdded3b089ef33fc83fc9717026 (diff) | |
download | Nim-9c19ce0698fe8bf5baad5cebf78776c161dceb8e.tar.gz |
Add a handshake parameter to wrapSocket() to allow it to work on an already-connected socket.
Diffstat (limited to 'lib/pure/asyncnet.nim')
-rw-r--r-- | lib/pure/asyncnet.nim | 16 |
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. |