mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +00:00
Add a handshake parameter to wrapSocket() to allow it to work on an already-connected socket.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user