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:
@@ -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()
|
||||
|
Reference in New Issue
Block a user