test-cleancode: add the rest of vlib/x/websocket/
parent
b65353794c
commit
b7a5dbf7b4
|
@ -69,8 +69,7 @@ const (
|
|||
'vlib/strings/',
|
||||
'vlib/time/',
|
||||
'vlib/vweb/',
|
||||
'vlib/x/websocket/websocket_server.v',
|
||||
'vlib/x/websocket/websocket_client.v',
|
||||
'vlib/x/websocket/',
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -18,8 +18,10 @@ struct Fragment {
|
|||
// Frame represents a data frame header
|
||||
struct Frame {
|
||||
mut:
|
||||
header_len int = 2 // length of the websocket header part
|
||||
frame_size int = 2 // size of total frame
|
||||
// length of the websocket header part
|
||||
header_len int = 2
|
||||
// size of total frame
|
||||
frame_size int = 2
|
||||
fin bool // true if final fragment of message
|
||||
rsv1 bool // reserved for future use in websocket RFC
|
||||
rsv2 bool // reserved for future use in websocket RFC
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// use this test to test the websocket client in the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
@ -7,9 +6,7 @@ import x.websocket
|
|||
fn main() {
|
||||
for i in 1 .. 304 {
|
||||
println('\ncase: $i')
|
||||
handle_case(i) or {
|
||||
println('error should be ok: $err')
|
||||
}
|
||||
handle_case(i) or { println('error should be ok: $err') }
|
||||
}
|
||||
// update the reports
|
||||
uri := 'ws://autobahn_server:9001/updateReports?agent=v-client'
|
||||
|
@ -32,7 +29,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
|||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// use this test to test the websocket client in the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
@ -7,9 +6,7 @@ import x.websocket
|
|||
fn main() {
|
||||
for i in 1 .. 304 {
|
||||
println('\ncase: $i')
|
||||
handle_case(i) or {
|
||||
println('error should be ok: $err')
|
||||
}
|
||||
handle_case(i) or { println('error should be ok: $err') }
|
||||
}
|
||||
// update the reports
|
||||
// uri := 'wss://localhost:9002/updateReports?agent=v-client'
|
||||
|
@ -34,7 +31,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
|||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// use this to test websocket server to the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
@ -24,7 +23,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
|||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// use this test to test the websocket client in the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
@ -7,9 +6,7 @@ import x.websocket
|
|||
fn main() {
|
||||
for i in 1 .. 304 {
|
||||
println('\ncase: $i')
|
||||
handle_case(i) or {
|
||||
println('error should be ok: $err')
|
||||
}
|
||||
handle_case(i) or { println('error should be ok: $err') }
|
||||
}
|
||||
// update the reports
|
||||
uri := 'ws://localhost:9001/updateReports?agent=v-client'
|
||||
|
@ -32,7 +29,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
|||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// use this test to test the websocket client in the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
@ -7,9 +6,7 @@ import x.websocket
|
|||
fn main() {
|
||||
for i in 1 .. 304 {
|
||||
println('\ncase: $i')
|
||||
handle_case(i) or {
|
||||
println('error should be ok: $err')
|
||||
}
|
||||
handle_case(i) or { println('error should be ok: $err') }
|
||||
}
|
||||
// update the reports
|
||||
// uri := 'wss://localhost:9002/updateReports?agent=v-client'
|
||||
|
@ -34,7 +31,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
|||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
|
|
|
@ -5,9 +5,7 @@ import time
|
|||
fn test_ws() {
|
||||
go start_server()
|
||||
time.sleep_ms(100)
|
||||
ws_test('ws://localhost:30000') or {
|
||||
assert false
|
||||
}
|
||||
ws_test('ws://localhost:30000') or { assert false }
|
||||
}
|
||||
|
||||
fn start_server() ? {
|
||||
|
@ -24,9 +22,7 @@ fn start_server() ? {
|
|||
return true
|
||||
}) ?
|
||||
s.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
})
|
||||
s.on_close(fn (mut ws websocket.Client, code int, reason string) ? {
|
||||
// not used
|
||||
|
@ -61,15 +57,11 @@ fn ws_test(uri string) ? {
|
|||
println('Binary message: $msg')
|
||||
}
|
||||
})
|
||||
ws.connect() or {
|
||||
panic('fail to connect')
|
||||
}
|
||||
ws.connect() or { panic('fail to connect') }
|
||||
go ws.listen()
|
||||
text := ['a'].repeat(2)
|
||||
for msg in text {
|
||||
ws.write(msg.bytes(), .text_frame) or {
|
||||
panic('fail to write to websocket')
|
||||
}
|
||||
ws.write(msg.bytes(), .text_frame) or { panic('fail to write to websocket') }
|
||||
// sleep to give time to recieve response before send a new one
|
||||
time.sleep_ms(100)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue