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:
parent
07df2d3484
commit
b1209aac1b
4
.github/workflows/websockets.yml
vendored
4
.github/workflows/websockets.yml
vendored
@ -23,11 +23,11 @@ jobs:
|
|||||||
echo $VFLAGS
|
echo $VFLAGS
|
||||||
sudo ln -s $PWD/thirdparty/tcc/tcc.exe /usr/local/bin/tcc ## TODO: remove
|
sudo ln -s $PWD/thirdparty/tcc/tcc.exe /usr/local/bin/tcc ## TODO: remove
|
||||||
make -j4
|
make -j4
|
||||||
./v -cg -cflags -Werror -o v cmd/v
|
./v -g -o v cmd/v
|
||||||
- name: v doctor
|
- name: v doctor
|
||||||
run: ./v doctor
|
run: ./v doctor
|
||||||
- name: Run websockets tests
|
- name: Run websockets tests
|
||||||
run: ./v -cflags "-Werror" test vlib/x/websocket/
|
run: ./v -g test vlib/x/websocket/
|
||||||
|
|
||||||
autobahn_tests:
|
autobahn_tests:
|
||||||
name: Autobahn integrations tests
|
name: Autobahn integrations tests
|
||||||
|
@ -36,7 +36,7 @@ fn new_addr(addr C.sockaddr) ?Addr {
|
|||||||
socket_error(-1) ?
|
socket_error(-1) ?
|
||||||
}
|
}
|
||||||
} $else {
|
} $else {
|
||||||
res := C.inet_ntop(SocketFamily.inet, &addr, buf.data, buf.len)
|
res := charptr(C.inet_ntop(SocketFamily.inet, &addr, buf.data, buf.len))
|
||||||
if res == 0 {
|
if res == 0 {
|
||||||
socket_error(-1) ?
|
socket_error(-1) ?
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ module openssl
|
|||||||
#include <openssl/rand.h> # Please install OpenSSL development headers
|
#include <openssl/rand.h> # Please install OpenSSL development headers
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
|
||||||
pub struct C.SSL {
|
pub struct C.SSL {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,11 +60,11 @@ fn C.SSL_CTX_load_verify_locations() int
|
|||||||
|
|
||||||
fn C.SSL_CTX_free()
|
fn C.SSL_CTX_free()
|
||||||
|
|
||||||
fn C.SSL_new() &C.SSL
|
fn C.SSL_new(&C.SSL_CTX) &C.SSL
|
||||||
|
|
||||||
fn C.SSL_set_fd() int
|
fn C.SSL_set_fd(&C.SSL) int
|
||||||
|
|
||||||
fn C.SSL_connect() int
|
fn C.SSL_connect(&C.SSL) int
|
||||||
|
|
||||||
fn C.SSL_set_cipher_list() int
|
fn C.SSL_set_cipher_list() int
|
||||||
|
|
||||||
@ -77,17 +78,17 @@ fn C.SSL_get_verify_result() int
|
|||||||
|
|
||||||
fn C.SSL_set_tlsext_host_name() int
|
fn C.SSL_set_tlsext_host_name() int
|
||||||
|
|
||||||
fn C.SSL_shutdown() int
|
fn C.SSL_shutdown(&C.SSL) int
|
||||||
|
|
||||||
fn C.SSL_free()
|
fn C.SSL_free(&C.SSL)
|
||||||
|
|
||||||
fn C.SSL_write() int
|
fn C.SSL_write(ssl &C.SSL, buf voidptr, buflen int) int
|
||||||
|
|
||||||
fn C.SSL_read() int
|
fn C.SSL_read(ssl &C.SSL, buf voidptr, buflen int) int
|
||||||
|
|
||||||
fn C.SSL_load_error_strings()
|
fn C.SSL_load_error_strings()
|
||||||
|
|
||||||
fn C.SSL_library_init()
|
fn C.SSL_library_init() int
|
||||||
|
|
||||||
fn C.SSLv23_client_method() &C.SSL_METHOD
|
fn C.SSLv23_client_method() &C.SSL_METHOD
|
||||||
|
|
||||||
|
@ -157,11 +157,11 @@ pub fn (c &TcpConn) peer_ip() ?string {
|
|||||||
peeraddr := C.sockaddr_in{}
|
peeraddr := C.sockaddr_in{}
|
||||||
speeraddr := sizeof(peeraddr)
|
speeraddr := sizeof(peeraddr)
|
||||||
socket_error(C.getpeername(c.sock.handle, unsafe { &C.sockaddr(&peeraddr) }, &speeraddr)) ?
|
socket_error(C.getpeername(c.sock.handle, unsafe { &C.sockaddr(&peeraddr) }, &speeraddr)) ?
|
||||||
cstr := C.inet_ntop(C.AF_INET, &peeraddr.sin_addr, buf, sizeof(buf))
|
cstr := charptr(C.inet_ntop(C.AF_INET, &peeraddr.sin_addr, buf, sizeof(buf)))
|
||||||
if cstr == 0 {
|
if cstr == 0 {
|
||||||
return error('net.peer_ip: inet_ntop failed')
|
return error('net.peer_ip: inet_ntop failed')
|
||||||
}
|
}
|
||||||
res := unsafe {cstring_to_vstring(cstr)}
|
res := unsafe { cstring_to_vstring(cstr) }
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,14 +34,14 @@ pub fn (mut s SSLConn) shutdown() ? {
|
|||||||
if s.ssl != 0 {
|
if s.ssl != 0 {
|
||||||
mut res := 0
|
mut res := 0
|
||||||
for {
|
for {
|
||||||
res = C.SSL_shutdown(s.ssl)
|
res = C.SSL_shutdown(voidptr(s.ssl))
|
||||||
if res < 0 {
|
if res < 0 {
|
||||||
err_res := openssl.ssl_error(res, s.ssl) or {
|
err_res := openssl.ssl_error(res, s.ssl) or {
|
||||||
break // We break to free rest of resources
|
break // We break to free rest of resources
|
||||||
}
|
}
|
||||||
if err_res == .ssl_error_want_read {
|
if err_res == .ssl_error_want_read {
|
||||||
for {
|
for {
|
||||||
ready := @select(s.handle, .read, s.duration)?
|
ready := @select(s.handle, .read, s.duration) ?
|
||||||
if ready {
|
if ready {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -49,21 +49,21 @@ pub fn (mut s SSLConn) shutdown() ? {
|
|||||||
continue
|
continue
|
||||||
} else if err_res == .ssl_error_want_write {
|
} else if err_res == .ssl_error_want_write {
|
||||||
for {
|
for {
|
||||||
ready := @select(s.handle, .write, s.duration)?
|
ready := @select(s.handle, .write, s.duration) ?
|
||||||
if ready {
|
if ready {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
C.SSL_free(s.ssl)
|
unsafe { C.SSL_free(voidptr(s.ssl)) }
|
||||||
if s.sslctx != 0 {
|
if s.sslctx != 0 {
|
||||||
C.SSL_CTX_free(s.sslctx)
|
C.SSL_CTX_free(s.sslctx)
|
||||||
}
|
}
|
||||||
return error('unexepedted ssl error $err_res')
|
return error('unexepedted ssl error $err_res')
|
||||||
}
|
}
|
||||||
if s.ssl != 0 {
|
if s.ssl != 0 {
|
||||||
C.SSL_free(s.ssl)
|
unsafe { C.SSL_free(voidptr(s.ssl)) }
|
||||||
}
|
}
|
||||||
if s.sslctx != 0 {
|
if s.sslctx != 0 {
|
||||||
C.SSL_CTX_free(s.sslctx)
|
C.SSL_CTX_free(s.sslctx)
|
||||||
@ -75,7 +75,7 @@ pub fn (mut s SSLConn) shutdown() ? {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
C.SSL_free(s.ssl)
|
C.SSL_free(voidptr(s.ssl))
|
||||||
}
|
}
|
||||||
if s.sslctx != 0 {
|
if s.sslctx != 0 {
|
||||||
C.SSL_CTX_free(s.sslctx)
|
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.handle = tcp_conn.sock.handle
|
||||||
s.duration = tcp_conn.read_timeout()
|
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 {
|
if s.sslctx == 0 {
|
||||||
return error("Couldn't get ssl context")
|
return error("Couldn't get ssl context")
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? {
|
|||||||
// C.SSL_CTX_set_options(s.sslctx, flags)
|
// C.SSL_CTX_set_options(s.sslctx, flags)
|
||||||
// mut res := C.SSL_CTX_load_verify_locations(s.sslctx, 'random-org-chain.pem', 0)
|
// 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 {
|
if s.ssl == 0 {
|
||||||
return error("Couldn't create OpenSSL instance.")
|
return error("Couldn't create OpenSSL instance.")
|
||||||
}
|
}
|
||||||
@ -113,21 +113,21 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? {
|
|||||||
// println('http: openssl: cipher failed')
|
// 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 {
|
if res != 1 {
|
||||||
return error('cannot set host name')
|
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.")
|
return error("Couldn't assign ssl to socket.")
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
res = C.SSL_connect(s.ssl)
|
res = C.SSL_connect(voidptr(s.ssl))
|
||||||
if res != 1 {
|
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 {
|
if err_res == .ssl_error_want_read {
|
||||||
for {
|
for {
|
||||||
ready := @select(s.handle, .read, s.duration)?
|
ready := @select(s.handle, .read, s.duration) ?
|
||||||
if ready {
|
if ready {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? {
|
|||||||
continue
|
continue
|
||||||
} else if err_res == .ssl_error_want_write {
|
} else if err_res == .ssl_error_want_write {
|
||||||
for {
|
for {
|
||||||
ready := @select(s.handle, .write, s.duration)?
|
ready := @select(s.handle, .write, s.duration) ?
|
||||||
if ready {
|
if ready {
|
||||||
break
|
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 {
|
pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr byteptr, len int) ?int {
|
||||||
mut res := 0
|
mut res := 0
|
||||||
for {
|
for {
|
||||||
res = C.SSL_read(s.ssl, buf_ptr, len)
|
res = C.SSL_read(voidptr(s.ssl), buf_ptr, len)
|
||||||
if res < 0 {
|
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 {
|
if err_res == .ssl_error_want_read {
|
||||||
for {
|
for {
|
||||||
ready := @select(s.handle, .read, s.duration)?
|
ready := @select(s.handle, .read, s.duration) ?
|
||||||
if ready {
|
if ready {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr byteptr, len int) ?int {
|
|||||||
continue
|
continue
|
||||||
} else if err_res == .ssl_error_want_write {
|
} else if err_res == .ssl_error_want_write {
|
||||||
for {
|
for {
|
||||||
ready := @select(s.handle, .write, s.duration)?
|
ready := @select(s.handle, .write, s.duration) ?
|
||||||
if ready {
|
if ready {
|
||||||
break
|
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 {
|
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
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,9 +193,9 @@ pub fn (mut s SSLConn) write(bytes []byte) ? {
|
|||||||
for total_sent < bytes.len {
|
for total_sent < bytes.len {
|
||||||
ptr := ptr_base + total_sent
|
ptr := ptr_base + total_sent
|
||||||
remaining := bytes.len - 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 {
|
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 {
|
if err_res == .ssl_error_want_read {
|
||||||
for {
|
for {
|
||||||
ready := @select(s.handle, .read, s.duration) ?
|
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 {
|
} else if err_res == .ssl_error_want_write {
|
||||||
for {
|
for {
|
||||||
ready := @select(s.handle, .write, s.duration)?
|
ready := @select(s.handle, .write, s.duration) ?
|
||||||
if ready {
|
if ready {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -254,13 +254,13 @@ fn @select(handle int, test Select, timeout time.Duration) ?bool {
|
|||||||
|
|
||||||
match test {
|
match test {
|
||||||
.read {
|
.read {
|
||||||
net.socket_error(C.@select(handle+1, &set, C.NULL, C.NULL, timeval_timeout))?
|
net.socket_error(C.@select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout)) ?
|
||||||
}
|
}
|
||||||
.write {
|
.write {
|
||||||
net.socket_error(C.@select(handle+1, C.NULL, &set, C.NULL, timeval_timeout))?
|
net.socket_error(C.@select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout)) ?
|
||||||
}
|
}
|
||||||
.except {
|
.except {
|
||||||
net.socket_error(C.@select(handle+1, C.NULL, C.NULL, &set, timeval_timeout))?
|
net.socket_error(C.@select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout)) ?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user