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

net.websocket: make thread safe/concurrent (#18179)

This commit is contained in:
kbkpbot
2023-05-18 17:27:00 +08:00
committed by GitHub
parent 1e88b1ab3e
commit c8d2098a14
8 changed files with 109 additions and 73 deletions

View File

@ -50,7 +50,7 @@ fn start_server(family net.AddrFamily, listen_port int) ! {
eprintln('> start_server family:${family} | listen_port: ${listen_port}')
mut s := websocket.new_server(family, listen_port, '')
// make that in execution test time give time to execute at least one time
s.ping_interval = 1
s.set_ping_interval(1)
s.on_connect(fn (mut s websocket.ServerClient) !bool {
// here you can look att the client info and accept or not accept
@ -80,7 +80,7 @@ fn start_server_in_thread_and_wait_till_it_is_ready_to_accept_connections(mut ws
spawn fn [mut ws] () {
ws.listen() or { panic('websocket server could not listen, err: ${err}') }
}()
for ws.state != .open {
for ws.get_state() != .open {
time.sleep(10 * time.millisecond)
}
eprintln('-----------------------------------------------------------------------------')