mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ci: fix building of vlib/x/websocket/websocket_test.v
This commit is contained in:
@ -34,14 +34,14 @@ pub fn (mut s SSLConn) shutdown() ? {
|
||||
if s.ssl != 0 {
|
||||
mut res := 0
|
||||
for {
|
||||
res = C.SSL_shutdown(s.ssl)
|
||||
res = C.SSL_shutdown(voidptr(s.ssl))
|
||||
if res < 0 {
|
||||
err_res := openssl.ssl_error(res, s.ssl) or {
|
||||
break // We break to free rest of resources
|
||||
}
|
||||
if err_res == .ssl_error_want_read {
|
||||
for {
|
||||
ready := @select(s.handle, .read, s.duration)?
|
||||
ready := @select(s.handle, .read, s.duration) ?
|
||||
if ready {
|
||||
break
|
||||
}
|
||||
@ -49,21 +49,21 @@ pub fn (mut s SSLConn) shutdown() ? {
|
||||
continue
|
||||
} else if err_res == .ssl_error_want_write {
|
||||
for {
|
||||
ready := @select(s.handle, .write, s.duration)?
|
||||
ready := @select(s.handle, .write, s.duration) ?
|
||||
if ready {
|
||||
break
|
||||
}
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
C.SSL_free(s.ssl)
|
||||
unsafe { C.SSL_free(voidptr(s.ssl)) }
|
||||
if s.sslctx != 0 {
|
||||
C.SSL_CTX_free(s.sslctx)
|
||||
}
|
||||
return error('unexepedted ssl error $err_res')
|
||||
}
|
||||
if s.ssl != 0 {
|
||||
C.SSL_free(s.ssl)
|
||||
unsafe { C.SSL_free(voidptr(s.ssl)) }
|
||||
}
|
||||
if s.sslctx != 0 {
|
||||
C.SSL_CTX_free(s.sslctx)
|
||||
@ -75,7 +75,7 @@ pub fn (mut s SSLConn) shutdown() ? {
|
||||
break
|
||||
}
|
||||
}
|
||||
C.SSL_free(s.ssl)
|
||||
C.SSL_free(voidptr(s.ssl))
|
||||
}
|
||||
if s.sslctx != 0 {
|
||||
C.SSL_CTX_free(s.sslctx)
|
||||
@ -87,7 +87,7 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? {
|
||||
s.handle = tcp_conn.sock.handle
|
||||
s.duration = tcp_conn.read_timeout()
|
||||
|
||||
s.sslctx = C.SSL_CTX_new(C.SSLv23_client_method())
|
||||
s.sslctx = unsafe { C.SSL_CTX_new(C.SSLv23_client_method()) }
|
||||
if s.sslctx == 0 {
|
||||
return error("Couldn't get ssl context")
|
||||
}
|
||||
@ -101,8 +101,8 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? {
|
||||
// flags := C.SSL_OP_NO_SSLv2 | C.SSL_OP_NO_SSLv3 | C.SSL_OP_NO_COMPRESSION
|
||||
// C.SSL_CTX_set_options(s.sslctx, flags)
|
||||
// mut res := C.SSL_CTX_load_verify_locations(s.sslctx, 'random-org-chain.pem', 0)
|
||||
|
||||
s.ssl = C.SSL_new(s.sslctx)
|
||||
|
||||
s.ssl = unsafe { &C.SSL(C.SSL_new(voidptr(s.sslctx))) }
|
||||
if s.ssl == 0 {
|
||||
return error("Couldn't create OpenSSL instance.")
|
||||
}
|
||||
@ -112,22 +112,22 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? {
|
||||
// if res != 1 {
|
||||
// println('http: openssl: cipher failed')
|
||||
// }
|
||||
|
||||
mut res := C.SSL_set_tlsext_host_name(s.ssl, hostname.str)
|
||||
|
||||
mut res := C.SSL_set_tlsext_host_name(voidptr(s.ssl), voidptr(hostname.str))
|
||||
if res != 1 {
|
||||
return error('cannot set host name')
|
||||
}
|
||||
|
||||
if C.SSL_set_fd(s.ssl, tcp_conn.sock.handle) != 1 {
|
||||
if C.SSL_set_fd(voidptr(s.ssl), tcp_conn.sock.handle) != 1 {
|
||||
return error("Couldn't assign ssl to socket.")
|
||||
}
|
||||
for {
|
||||
res = C.SSL_connect(s.ssl)
|
||||
res = C.SSL_connect(voidptr(s.ssl))
|
||||
if res != 1 {
|
||||
err_res := openssl.ssl_error(res, s.ssl)?
|
||||
err_res := openssl.ssl_error(res, s.ssl) ?
|
||||
if err_res == .ssl_error_want_read {
|
||||
for {
|
||||
ready := @select(s.handle, .read, s.duration)?
|
||||
ready := @select(s.handle, .read, s.duration) ?
|
||||
if ready {
|
||||
break
|
||||
}
|
||||
@ -135,7 +135,7 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? {
|
||||
continue
|
||||
} else if err_res == .ssl_error_want_write {
|
||||
for {
|
||||
ready := @select(s.handle, .write, s.duration)?
|
||||
ready := @select(s.handle, .write, s.duration) ?
|
||||
if ready {
|
||||
break
|
||||
}
|
||||
@ -151,12 +151,12 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? {
|
||||
pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr byteptr, len int) ?int {
|
||||
mut res := 0
|
||||
for {
|
||||
res = C.SSL_read(s.ssl, buf_ptr, len)
|
||||
res = C.SSL_read(voidptr(s.ssl), buf_ptr, len)
|
||||
if res < 0 {
|
||||
err_res := openssl.ssl_error(res, s.ssl)?
|
||||
err_res := openssl.ssl_error(res, s.ssl) ?
|
||||
if err_res == .ssl_error_want_read {
|
||||
for {
|
||||
ready := @select(s.handle, .read, s.duration)?
|
||||
ready := @select(s.handle, .read, s.duration) ?
|
||||
if ready {
|
||||
break
|
||||
}
|
||||
@ -164,7 +164,7 @@ pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr byteptr, len int) ?int {
|
||||
continue
|
||||
} else if err_res == .ssl_error_want_write {
|
||||
for {
|
||||
ready := @select(s.handle, .write, s.duration)?
|
||||
ready := @select(s.handle, .write, s.duration) ?
|
||||
if ready {
|
||||
break
|
||||
}
|
||||
@ -181,7 +181,7 @@ pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr byteptr, len int) ?int {
|
||||
}
|
||||
|
||||
pub fn (mut s SSLConn) read_into(mut buffer []byte) ?int {
|
||||
res := s.socket_read_into_ptr(byteptr(buffer.data), buffer.len)?
|
||||
res := s.socket_read_into_ptr(byteptr(buffer.data), buffer.len) ?
|
||||
return res
|
||||
}
|
||||
|
||||
@ -193,9 +193,9 @@ pub fn (mut s SSLConn) write(bytes []byte) ? {
|
||||
for total_sent < bytes.len {
|
||||
ptr := ptr_base + total_sent
|
||||
remaining := bytes.len - total_sent
|
||||
mut sent := C.SSL_write(s.ssl, ptr, remaining)
|
||||
mut sent := C.SSL_write(voidptr(s.ssl), ptr, remaining)
|
||||
if sent <= 0 {
|
||||
err_res := openssl.ssl_error(sent, s.ssl)?
|
||||
err_res := openssl.ssl_error(sent, s.ssl) ?
|
||||
if err_res == .ssl_error_want_read {
|
||||
for {
|
||||
ready := @select(s.handle, .read, s.duration) ?
|
||||
@ -205,7 +205,7 @@ pub fn (mut s SSLConn) write(bytes []byte) ? {
|
||||
}
|
||||
} else if err_res == .ssl_error_want_write {
|
||||
for {
|
||||
ready := @select(s.handle, .write, s.duration)?
|
||||
ready := @select(s.handle, .write, s.duration) ?
|
||||
if ready {
|
||||
break
|
||||
}
|
||||
@ -232,37 +232,37 @@ pub struct C.fd_set {
|
||||
|
||||
// Select waits for an io operation (specified by parameter `test`) to be available
|
||||
fn @select(handle int, test Select, timeout time.Duration) ?bool {
|
||||
set := C.fd_set{}
|
||||
set := C.fd_set{}
|
||||
|
||||
C.FD_ZERO(&set)
|
||||
C.FD_SET(handle, &set)
|
||||
C.FD_ZERO(&set)
|
||||
C.FD_SET(handle, &set)
|
||||
|
||||
seconds := timeout.milliseconds() / 1000
|
||||
microseconds := timeout - (seconds * time.second)
|
||||
mut tt := C.timeval{
|
||||
tv_sec: u64(seconds)
|
||||
tv_usec: u64(microseconds)
|
||||
}
|
||||
seconds := timeout.milliseconds() / 1000
|
||||
microseconds := timeout - (seconds * time.second)
|
||||
mut tt := C.timeval{
|
||||
tv_sec: u64(seconds)
|
||||
tv_usec: u64(microseconds)
|
||||
}
|
||||
|
||||
mut timeval_timeout := &tt
|
||||
mut timeval_timeout := &tt
|
||||
|
||||
// infinite timeout is signaled by passing null as the timeout to
|
||||
// select
|
||||
if timeout == net.infinite_timeout {
|
||||
timeval_timeout = &C.timeval(0)
|
||||
}
|
||||
// infinite timeout is signaled by passing null as the timeout to
|
||||
// select
|
||||
if timeout == net.infinite_timeout {
|
||||
timeval_timeout = &C.timeval(0)
|
||||
}
|
||||
|
||||
match test {
|
||||
.read {
|
||||
net.socket_error(C.@select(handle+1, &set, C.NULL, C.NULL, timeval_timeout))?
|
||||
}
|
||||
.write {
|
||||
net.socket_error(C.@select(handle+1, C.NULL, &set, C.NULL, timeval_timeout))?
|
||||
}
|
||||
.except {
|
||||
net.socket_error(C.@select(handle+1, C.NULL, C.NULL, &set, timeval_timeout))?
|
||||
}
|
||||
}
|
||||
match test {
|
||||
.read {
|
||||
net.socket_error(C.@select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout)) ?
|
||||
}
|
||||
.write {
|
||||
net.socket_error(C.@select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout)) ?
|
||||
}
|
||||
.except {
|
||||
net.socket_error(C.@select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout)) ?
|
||||
}
|
||||
}
|
||||
|
||||
return C.FD_ISSET(handle, &set)
|
||||
return C.FD_ISSET(handle, &set)
|
||||
}
|
||||
|
Reference in New Issue
Block a user