mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: remove space in front of ? and ! (#14366)
This commit is contained in:
@ -162,7 +162,7 @@ fn (mut s Server) send_connect_event(mut c ServerClient) ?bool {
|
||||
return true
|
||||
}
|
||||
fun := s.accept_client_callbacks[0]
|
||||
res := fun(mut c) ?
|
||||
res := fun(mut c)?
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -34,15 +34,15 @@ fn (mut ws Client) handshake() ? {
|
||||
}
|
||||
handshake_bytes := handshake.bytes()
|
||||
ws.debug_log('sending handshake: $handshake')
|
||||
ws.socket_write(handshake_bytes) ?
|
||||
ws.read_handshake(seckey) ?
|
||||
ws.socket_write(handshake_bytes)?
|
||||
ws.read_handshake(seckey)?
|
||||
unsafe { handshake_bytes.free() }
|
||||
}
|
||||
|
||||
// handle_server_handshake manages websocket server handshake process
|
||||
fn (mut s Server) handle_server_handshake(mut c Client) ?(string, &ServerClient) {
|
||||
msg := c.read_handshake_str() ?
|
||||
handshake_response, client := s.parse_client_handshake(msg, mut c) ?
|
||||
msg := c.read_handshake_str()?
|
||||
handshake_response, client := s.parse_client_handshake(msg, mut c)?
|
||||
unsafe { msg.free() }
|
||||
return handshake_response, client
|
||||
}
|
||||
@ -81,7 +81,7 @@ fn (mut s Server) parse_client_handshake(client_handshake string, mut c Client)
|
||||
'Sec-WebSocket-Key', 'sec-websocket-key' {
|
||||
key = keys[1].trim_space()
|
||||
s.logger.debug('server-> got key: $key')
|
||||
seckey = create_key_challenge_response(key) ?
|
||||
seckey = create_key_challenge_response(key)?
|
||||
s.logger.debug('server-> challenge: $seckey, response: ${keys[1]}')
|
||||
flags << .has_accept
|
||||
}
|
||||
@ -117,7 +117,7 @@ fn (mut ws Client) read_handshake_str() ?string {
|
||||
mut msg := [1024]u8{}
|
||||
mut buffer := [1]u8{}
|
||||
for total_bytes_read < 1024 {
|
||||
bytes_read := ws.socket_read_ptr(&buffer[0], 1) ?
|
||||
bytes_read := ws.socket_read_ptr(&buffer[0], 1)?
|
||||
if bytes_read == 0 {
|
||||
return error_with_code('unexpected no response from handshake', 5)
|
||||
}
|
||||
@ -135,8 +135,8 @@ fn (mut ws Client) read_handshake_str() ?string {
|
||||
|
||||
// read_handshake reads the handshake result and check if valid
|
||||
fn (mut ws Client) read_handshake(seckey string) ? {
|
||||
mut msg := ws.read_handshake_str() ?
|
||||
ws.check_handshake_response(msg, seckey) ?
|
||||
mut msg := ws.read_handshake_str()?
|
||||
ws.check_handshake_response(msg, seckey)?
|
||||
unsafe { msg.free() }
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ fn (mut ws Client) check_handshake_response(handshake_response string, seckey st
|
||||
}
|
||||
'Sec-WebSocket-Accept', 'sec-websocket-accept' {
|
||||
ws.debug_log('seckey: $seckey')
|
||||
challenge := create_key_challenge_response(seckey) ?
|
||||
challenge := create_key_challenge_response(seckey)?
|
||||
ws.debug_log('challenge: $challenge, response: ${keys[1]}')
|
||||
if keys[1].trim_space() != challenge {
|
||||
return error_with_code('handshake_handler: Sec-WebSocket-Accept header does not match computed sha1/base64 response.',
|
||||
@ -179,7 +179,7 @@ fn (mut ws Client) check_handshake_response(handshake_response string, seckey st
|
||||
}
|
||||
unsafe { lines.free() }
|
||||
if ws.flags.len < 3 {
|
||||
ws.close(1002, 'invalid websocket HTTP headers') ?
|
||||
ws.close(1002, 'invalid websocket HTTP headers')?
|
||||
return error_with_code('invalid websocket HTTP headers', 8)
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ fn (mut ws Client) socket_read(mut buffer []u8) ?int {
|
||||
return error('socket_read: trying to read a closed socket')
|
||||
}
|
||||
if ws.is_ssl {
|
||||
r := ws.ssl_conn.read(mut buffer) ?
|
||||
r := ws.ssl_conn.read(mut buffer)?
|
||||
return r
|
||||
} else {
|
||||
for {
|
||||
@ -34,7 +34,7 @@ fn (mut ws Client) socket_read_ptr(buf_ptr &u8, len int) ?int {
|
||||
return error('socket_read_ptr: trying to read a closed socket')
|
||||
}
|
||||
if ws.is_ssl {
|
||||
r := ws.ssl_conn.socket_read_into_ptr(buf_ptr, len) ?
|
||||
r := ws.ssl_conn.socket_read_into_ptr(buf_ptr, len)?
|
||||
return r
|
||||
} else {
|
||||
for {
|
||||
@ -79,22 +79,22 @@ fn (mut ws Client) socket_write(bytes []u8) ?int {
|
||||
fn (mut ws Client) shutdown_socket() ? {
|
||||
ws.debug_log('shutting down socket')
|
||||
if ws.is_ssl {
|
||||
ws.ssl_conn.shutdown() ?
|
||||
ws.ssl_conn.shutdown()?
|
||||
} else {
|
||||
ws.conn.close() ?
|
||||
ws.conn.close()?
|
||||
}
|
||||
}
|
||||
|
||||
// dial_socket connects tcp socket and initializes default configurations
|
||||
fn (mut ws Client) dial_socket() ?&net.TcpConn {
|
||||
tcp_address := '$ws.uri.hostname:$ws.uri.port'
|
||||
mut t := net.dial_tcp(tcp_address) ?
|
||||
mut t := net.dial_tcp(tcp_address)?
|
||||
optval := int(1)
|
||||
t.sock.set_option_int(.keep_alive, optval) ?
|
||||
t.sock.set_option_int(.keep_alive, optval)?
|
||||
t.set_read_timeout(30 * time.second)
|
||||
t.set_write_timeout(30 * time.second)
|
||||
if ws.is_ssl {
|
||||
ws.ssl_conn.connect(mut t, ws.uri.hostname) ?
|
||||
ws.ssl_conn.connect(mut t, ws.uri.hostname)?
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
@ -39,33 +39,33 @@ const (
|
||||
// validate_client validates client frame rules from RFC6455
|
||||
pub fn (mut ws Client) validate_frame(frame &Frame) ? {
|
||||
if frame.rsv1 || frame.rsv2 || frame.rsv3 {
|
||||
ws.close(1002, 'rsv cannot be other than 0, not negotiated') ?
|
||||
ws.close(1002, 'rsv cannot be other than 0, not negotiated')?
|
||||
return error('rsv cannot be other than 0, not negotiated')
|
||||
}
|
||||
if (int(frame.opcode) >= 3 && int(frame.opcode) <= 7)
|
||||
|| (int(frame.opcode) >= 11 && int(frame.opcode) <= 15) {
|
||||
ws.close(1002, 'use of reserved opcode') ?
|
||||
ws.close(1002, 'use of reserved opcode')?
|
||||
return error('use of reserved opcode')
|
||||
}
|
||||
if frame.has_mask && !ws.is_server {
|
||||
// server should never send masked frames
|
||||
// to client, close connection
|
||||
ws.close(1002, 'client got masked frame') ?
|
||||
ws.close(1002, 'client got masked frame')?
|
||||
return error('client sent masked frame')
|
||||
}
|
||||
if is_control_frame(frame.opcode) {
|
||||
if !frame.fin {
|
||||
ws.close(1002, 'control message must not be fragmented') ?
|
||||
ws.close(1002, 'control message must not be fragmented')?
|
||||
return error('unexpected control frame with no fin')
|
||||
}
|
||||
if frame.payload_len > 125 {
|
||||
ws.close(1002, 'control frames must not exceed 125 bytes') ?
|
||||
ws.close(1002, 'control frames must not exceed 125 bytes')?
|
||||
return error('unexpected control frame payload length')
|
||||
}
|
||||
}
|
||||
if frame.fin == false && ws.fragments.len == 0 && frame.opcode == .continuation {
|
||||
err_msg := 'unexecpected continuation, there are no frames to continue, $frame'
|
||||
ws.close(1002, err_msg) ?
|
||||
ws.close(1002, err_msg)?
|
||||
return error(err_msg)
|
||||
}
|
||||
}
|
||||
@ -89,7 +89,7 @@ fn (mut ws Client) read_payload(frame &Frame) ?[]u8 {
|
||||
mut read_buf := [1]u8{}
|
||||
mut bytes_read := 0
|
||||
for bytes_read < frame.payload_len {
|
||||
len := ws.socket_read_ptr(&read_buf[0], 1) ?
|
||||
len := ws.socket_read_ptr(&read_buf[0], 1)?
|
||||
if len != 1 {
|
||||
return error('expected read all message, got zero')
|
||||
}
|
||||
@ -113,7 +113,7 @@ fn (mut ws Client) validate_utf_8(opcode OPCode, payload []u8) ? {
|
||||
if opcode in [.text_frame, .close] && !utf8.validate(payload.data, payload.len) {
|
||||
ws.logger.error('malformed utf8 payload, payload len: ($payload.len)')
|
||||
ws.send_error_event('Recieved malformed utf8.')
|
||||
ws.close(1007, 'malformed utf8 payload') ?
|
||||
ws.close(1007, 'malformed utf8 payload')?
|
||||
return error('malformed utf8 payload')
|
||||
}
|
||||
}
|
||||
@ -121,9 +121,9 @@ fn (mut ws Client) validate_utf_8(opcode OPCode, payload []u8) ? {
|
||||
// read_next_message reads 1 to n frames to compose a message
|
||||
pub fn (mut ws Client) read_next_message() ?Message {
|
||||
for {
|
||||
frame := ws.parse_frame_header() ?
|
||||
ws.validate_frame(&frame) ?
|
||||
frame_payload := ws.read_payload(&frame) ?
|
||||
frame := ws.parse_frame_header()?
|
||||
ws.validate_frame(&frame)?
|
||||
frame_payload := ws.read_payload(&frame)?
|
||||
if is_control_frame(frame.opcode) {
|
||||
// Control frames can interject other frames
|
||||
// and need to be returned immediately
|
||||
@ -161,12 +161,12 @@ pub fn (mut ws Client) read_next_message() ?Message {
|
||||
ws.fragments = []
|
||||
}
|
||||
if is_data_frame(frame.opcode) {
|
||||
ws.close(0, '') ?
|
||||
ws.close(0, '')?
|
||||
return error('Unexpected frame opcode')
|
||||
}
|
||||
payload := ws.payload_from_fragments(frame_payload) ?
|
||||
payload := ws.payload_from_fragments(frame_payload)?
|
||||
opcode := ws.opcode_from_fragments()
|
||||
ws.validate_utf_8(opcode, payload) ?
|
||||
ws.validate_utf_8(opcode, payload)?
|
||||
msg := Message{
|
||||
opcode: opcode
|
||||
payload: payload.clone()
|
||||
@ -215,7 +215,7 @@ pub fn (mut ws Client) parse_frame_header() ?Frame {
|
||||
mut rbuff := [1]u8{}
|
||||
mut mask_end_byte := 0
|
||||
for ws.state == .open {
|
||||
read_bytes := ws.socket_read_ptr(&rbuff[0], 1) ?
|
||||
read_bytes := ws.socket_read_ptr(&rbuff[0], 1)?
|
||||
if read_bytes == 0 {
|
||||
// this is probably a timeout or close
|
||||
continue
|
||||
|
@ -10,17 +10,17 @@ fn main() {
|
||||
}
|
||||
// update the reports
|
||||
uri := 'ws://autobahn_server:9001/updateReports?agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'ws://autobahn_server:9001/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.on_message(on_message)
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
|
@ -11,18 +11,18 @@ fn main() {
|
||||
// update the reports
|
||||
// uri := 'wss://localhost:9002/updateReports?agent=v-client'
|
||||
uri := 'wss://autobahn_server_wss:9002/updateReports?agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'wss://autobahn_server_wss:9002/runCase?case=$case_nr&agent=v-client'
|
||||
// uri := 'wss://localhost:9002/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.on_message(on_message)
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
|
@ -11,10 +11,10 @@ fn main() {
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'ws://localhost:9002/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.on_message(on_message)
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
|
@ -10,17 +10,17 @@ fn main() {
|
||||
}
|
||||
// update the reports
|
||||
uri := 'ws://localhost:9001/updateReports?agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'ws://localhost:9001/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.on_message(on_message)
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
|
@ -11,18 +11,18 @@ fn main() {
|
||||
// update the reports
|
||||
// uri := 'wss://localhost:9002/updateReports?agent=v-client'
|
||||
uri := 'wss://autobahn_server_wss:9002/updateReports?agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'wss://autobahn_server_wss:9002/runCase?case=$case_nr&agent=v-client'
|
||||
// uri := 'wss://localhost:9002/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.on_message(on_message)
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
|
@ -75,7 +75,7 @@ pub enum OPCode {
|
||||
|
||||
// new_client instance a new websocket client
|
||||
pub fn new_client(address string) ?&Client {
|
||||
uri := parse_uri(address) ?
|
||||
uri := parse_uri(address)?
|
||||
return &Client{
|
||||
conn: 0
|
||||
is_server: false
|
||||
@ -93,14 +93,14 @@ pub fn new_client(address string) ?&Client {
|
||||
|
||||
// connect connects to remote websocket server
|
||||
pub fn (mut ws Client) connect() ? {
|
||||
ws.assert_not_connected() ?
|
||||
ws.assert_not_connected()?
|
||||
ws.set_state(.connecting)
|
||||
ws.logger.info('connecting to host $ws.uri')
|
||||
ws.conn = ws.dial_socket() ?
|
||||
ws.conn = ws.dial_socket()?
|
||||
// Todo: make setting configurable
|
||||
ws.conn.set_read_timeout(time.second * 30)
|
||||
ws.conn.set_write_timeout(time.second * 30)
|
||||
ws.handshake() ?
|
||||
ws.handshake()?
|
||||
ws.set_state(.open)
|
||||
ws.logger.info('successfully connected to host $ws.uri')
|
||||
ws.send_open_event()
|
||||
@ -174,30 +174,30 @@ pub fn (mut ws Client) listen() ? {
|
||||
}
|
||||
if msg.payload.len > 0 {
|
||||
if msg.payload.len == 1 {
|
||||
ws.close(1002, 'close payload cannot be 1 byte') ?
|
||||
ws.close(1002, 'close payload cannot be 1 byte')?
|
||||
return error('close payload cannot be 1 byte')
|
||||
}
|
||||
code := u16(msg.payload[0]) << 8 | u16(msg.payload[1])
|
||||
if code in invalid_close_codes {
|
||||
ws.close(1002, 'invalid close code: $code') ?
|
||||
ws.close(1002, 'invalid close code: $code')?
|
||||
return error('invalid close code: $code')
|
||||
}
|
||||
reason := if msg.payload.len > 2 { msg.payload[2..] } else { []u8{} }
|
||||
if reason.len > 0 {
|
||||
ws.validate_utf_8(.close, reason) ?
|
||||
ws.validate_utf_8(.close, reason)?
|
||||
}
|
||||
if ws.state !in [.closing, .closed] {
|
||||
// sending close back according to spec
|
||||
ws.debug_log('close with reason, code: $code, reason: $reason')
|
||||
r := reason.bytestr()
|
||||
ws.close(code, r) ?
|
||||
ws.close(code, r)?
|
||||
}
|
||||
unsafe { msg.free() }
|
||||
} else {
|
||||
if ws.state !in [.closing, .closed] {
|
||||
ws.debug_log('close with reason, no code')
|
||||
// sending close back according to spec
|
||||
ws.close(1000, 'normal') ?
|
||||
ws.close(1000, 'normal')?
|
||||
}
|
||||
unsafe { msg.free() }
|
||||
}
|
||||
@ -206,7 +206,7 @@ pub fn (mut ws Client) listen() ? {
|
||||
.continuation {
|
||||
ws.logger.error('unexpected opcode continuation, nothing to continue')
|
||||
ws.send_error_event('unexpected opcode continuation, nothing to continue')
|
||||
ws.close(1002, 'nothing to continue') ?
|
||||
ws.close(1002, 'nothing to continue')?
|
||||
return error('unexpected opcode continuation, nothing to continue')
|
||||
}
|
||||
}
|
||||
@ -220,12 +220,12 @@ fn (mut ws Client) manage_clean_close() {
|
||||
|
||||
// ping sends ping message to server
|
||||
pub fn (mut ws Client) ping() ? {
|
||||
ws.send_control_frame(.ping, 'PING', []) ?
|
||||
ws.send_control_frame(.ping, 'PING', [])?
|
||||
}
|
||||
|
||||
// pong sends pong message to server,
|
||||
pub fn (mut ws Client) pong() ? {
|
||||
ws.send_control_frame(.pong, 'PONG', []) ?
|
||||
ws.send_control_frame(.pong, 'PONG', [])?
|
||||
}
|
||||
|
||||
// write_ptr writes len bytes provided a byteptr with a websocket messagetype
|
||||
@ -279,7 +279,7 @@ pub fn (mut ws Client) write_ptr(bytes &u8, payload_len int, code OPCode) ?int {
|
||||
header[12] = masking_key[2]
|
||||
header[13] = masking_key[3]
|
||||
} else {
|
||||
ws.close(1009, 'frame too large') ?
|
||||
ws.close(1009, 'frame too large')?
|
||||
return error('frame too large')
|
||||
}
|
||||
}
|
||||
@ -296,7 +296,7 @@ pub fn (mut ws Client) write_ptr(bytes &u8, payload_len int, code OPCode) ?int {
|
||||
frame_buf[header_len + i] ^= masking_key[i % 4] & 0xff
|
||||
}
|
||||
}
|
||||
written_len := ws.socket_write(frame_buf) ?
|
||||
written_len := ws.socket_write(frame_buf)?
|
||||
unsafe {
|
||||
frame_buf.free()
|
||||
masking_key.free()
|
||||
@ -339,10 +339,10 @@ pub fn (mut ws Client) close(code int, message string) ? {
|
||||
for i in 0 .. message.len {
|
||||
close_frame[i + 2] = message[i]
|
||||
}
|
||||
ws.send_control_frame(.close, 'CLOSE', close_frame) ?
|
||||
ws.send_control_frame(.close, 'CLOSE', close_frame)?
|
||||
unsafe { close_frame.free() }
|
||||
} else {
|
||||
ws.send_control_frame(.close, 'CLOSE', []) ?
|
||||
ws.send_control_frame(.close, 'CLOSE', [])?
|
||||
}
|
||||
ws.fragments = []
|
||||
}
|
||||
@ -409,7 +409,7 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []u
|
||||
|
||||
// parse_uri parses the url to a Uri
|
||||
fn parse_uri(url string) ?&Uri {
|
||||
u := urllib.parse(url) ?
|
||||
u := urllib.parse(url)?
|
||||
request_uri := u.request_uri()
|
||||
v := request_uri.split('?')
|
||||
mut port := u.port()
|
||||
|
@ -55,7 +55,7 @@ pub fn (mut s Server) set_ping_interval(seconds int) {
|
||||
// listen start listen and process to incoming connections from websocket clients
|
||||
pub fn (mut s Server) listen() ? {
|
||||
s.logger.info('websocket server: start listen on port $s.port')
|
||||
s.ls = net.listen_tcp(s.family, ':$s.port') ?
|
||||
s.ls = net.listen_tcp(s.family, ':$s.port')?
|
||||
s.set_state(.open)
|
||||
go s.handle_ping()
|
||||
for {
|
||||
@ -108,15 +108,15 @@ fn (mut s Server) serve_client(mut c Client) ? {
|
||||
defer {
|
||||
c.logger.debug('server-> End serve client ($c.id)')
|
||||
}
|
||||
mut handshake_response, mut server_client := s.handle_server_handshake(mut c) ?
|
||||
accept := s.send_connect_event(mut server_client) ?
|
||||
mut handshake_response, mut server_client := s.handle_server_handshake(mut c)?
|
||||
accept := s.send_connect_event(mut server_client)?
|
||||
if !accept {
|
||||
s.logger.debug('server-> client not accepted')
|
||||
c.shutdown_socket() ?
|
||||
c.shutdown_socket()?
|
||||
return
|
||||
}
|
||||
// the client is accepted
|
||||
c.socket_write(handshake_response.bytes()) ?
|
||||
c.socket_write(handshake_response.bytes())?
|
||||
lock {
|
||||
s.clients[server_client.client.id] = server_client
|
||||
}
|
||||
@ -158,7 +158,7 @@ fn (mut s Server) setup_callbacks(mut sc ServerClient) {
|
||||
|
||||
// accept_new_client creates a new client instance for client that connects to the socket
|
||||
fn (mut s Server) accept_new_client() ?&Client {
|
||||
mut new_conn := s.ls.accept() ?
|
||||
mut new_conn := s.ls.accept()?
|
||||
c := &Client{
|
||||
is_server: true
|
||||
conn: new_conn
|
||||
|
@ -51,7 +51,7 @@ fn start_server(family net.AddrFamily, listen_port int) ? {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}) ?
|
||||
})?
|
||||
s.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
match msg.opcode {
|
||||
.pong { ws.write_string('pong') or { panic(err) } }
|
||||
@ -70,9 +70,9 @@ fn ws_test(family net.AddrFamily, uri string) ? {
|
||||
eprintln('connecting to $uri ...')
|
||||
|
||||
mut test_results := WebsocketTestResults{}
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.on_open(fn (mut ws websocket.Client) ? {
|
||||
ws.pong() ?
|
||||
ws.pong()?
|
||||
assert true
|
||||
})
|
||||
ws.on_error(fn (mut ws websocket.Client, err string) ? {
|
||||
|
Reference in New Issue
Block a user