1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/net/websocket/ssl.v

27 lines
549 B
V
Raw Normal View History

module websocket
import net.openssl
2020-05-26 13:50:37 +03:00
const (
is_used = openssl.is_used
)
2020-05-26 13:50:37 +03:00
fn (mut ws Client) connect_ssl() {
l.i('Using secure SSL connection')
C.SSL_load_error_strings()
ws.sslctx = C.SSL_CTX_new(C.SSLv23_client_method())
2020-05-26 13:50:37 +03:00
if ws.sslctx == 0 {
l.f("Couldn't get ssl context")
}
ws.ssl = C.SSL_new(ws.sslctx)
2020-05-26 13:50:37 +03:00
if ws.ssl == 0 {
l.f("Couldn't create OpenSSL instance.")
}
if C.SSL_set_fd(ws.ssl, ws.socket.sockfd) != 1 {
l.f("Couldn't assign ssl to socket.")
}
if C.SSL_connect(ws.ssl) != 1 {
l.f("Couldn't connect using SSL.")
}
2020-05-26 13:50:37 +03:00
}