mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: check (mut f Foo)
syntax
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
module websocket
|
||||
|
||||
fn (ws mut Client) read_handshake(seckey string){
|
||||
fn (mut ws Client) read_handshake(seckey string){
|
||||
l.d("reading handshake...")
|
||||
mut bytes_read := 0
|
||||
max_buffer := 1024
|
||||
@ -9,7 +9,7 @@ fn (ws mut Client) read_handshake(seckey string){
|
||||
|
||||
for bytes_read <= max_buffer {
|
||||
res := ws.read_from_server(buffer + bytes_read, buffer_size)
|
||||
if res == 0 || res == -1 {
|
||||
if res == 0 || res == -1 {
|
||||
l.f("read_handshake: Failed to read handshake.")
|
||||
}
|
||||
if buffer[bytes_read] == `\n` && buffer[bytes_read-1] == `\r` && buffer[bytes_read-2] == `\n` && buffer[bytes_read-3] == `\r` {
|
||||
@ -21,10 +21,10 @@ fn (ws mut Client) read_handshake(seckey string){
|
||||
ws.handshake_handler(string(byteptr(buffer)), seckey)
|
||||
}
|
||||
|
||||
fn (ws mut Client) handshake_handler(handshake_response, seckey string){
|
||||
fn (mut ws Client) handshake_handler(handshake_response, seckey string){
|
||||
l.d("handshake_handler:\r\n${handshake_response}")
|
||||
lines := handshake_response.split_into_lines()
|
||||
|
||||
|
||||
header := lines[0]
|
||||
if !header.starts_with("HTTP/1.1 101") && !header.starts_with("HTTP/1.0 101") {
|
||||
l.f("handshake_handler: invalid HTTP status response code")
|
||||
|
@ -2,13 +2,13 @@ module websocket
|
||||
|
||||
fn C.write() int
|
||||
|
||||
fn (ws mut Client) write_to_server(buf voidptr, len int) int {
|
||||
fn (mut ws Client) write_to_server(buf voidptr, len int) int {
|
||||
mut bytes_written := 0
|
||||
ws.write_lock.lock()
|
||||
bytes_written = if ws.is_ssl {
|
||||
C.SSL_write(ws.ssl, buf, len)
|
||||
} else {
|
||||
C.write(ws.socket.sockfd, buf, len)
|
||||
C.write(ws.socket.sockfd, buf, len)
|
||||
}
|
||||
ws.write_lock.unlock()
|
||||
return bytes_written
|
||||
|
@ -21,7 +21,7 @@ fn C.SSL_CTX_free()
|
||||
fn C.SSL_write() int
|
||||
fn C.SSL_read() int
|
||||
|
||||
fn (ws mut Client) connect_ssl(){
|
||||
fn (mut ws Client) connect_ssl(){
|
||||
l.i("Using secure SSL connection")
|
||||
C.SSL_load_error_strings()
|
||||
C.SSL_library_init()
|
||||
|
@ -23,7 +23,7 @@ pub fn utf8_validate(data byteptr, len int) bool {
|
||||
return !state.failed && state.subindex <= 0
|
||||
}
|
||||
|
||||
fn (s mut Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
|
||||
fn (mut s Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
|
||||
if s.subindex == 0 || (s.index > 1 && s.subindex == 1) || (s.index >= 6 && s.subindex == 2) {
|
||||
if (s.subindex == 0 && r0) || (s.subindex == 1 && r1) || (s.subindex == 2 && is_tail) {
|
||||
s.subindex++
|
||||
@ -46,7 +46,7 @@ fn (s mut Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
fn (s mut Utf8State) next_state (c byte) {
|
||||
fn (mut s Utf8State) next_state (c byte) {
|
||||
//sequence 1
|
||||
if s.index == 0 {
|
||||
if (c >= 0x00 + 1 && c <= 0x7F) || c == 0x00 {
|
||||
@ -58,7 +58,7 @@ fn (s mut Utf8State) next_state (c byte) {
|
||||
is_tail := c >= 0x80 && c <= 0xBF
|
||||
//sequence 2
|
||||
if s.index == 1 && s.seq(c >= 0xC2 && c <= 0xDF, false, is_tail) {return}
|
||||
|
||||
|
||||
//sequence 3
|
||||
if s.index == 2 && s.seq(c == 0xE0, c >= 0xA0 && c <= 0xBF, is_tail) {return}
|
||||
if s.index == 3 && s.seq(c >= 0xE1 && c <= 0xEC, c >= 0x80 && c <= 0xBF, is_tail) {return}
|
||||
|
@ -115,7 +115,7 @@ fn (ws &Client) parse_uri() &Uri {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (ws mut Client) connect() int {
|
||||
pub fn (mut ws Client) connect() int {
|
||||
match ws.state {
|
||||
.connected {
|
||||
l.f("connect: websocket already connected")
|
||||
@ -191,7 +191,7 @@ pub fn (ws mut Client) connect() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub fn (ws mut Client) close(code int, message string){
|
||||
pub fn (mut ws Client) close(code int, message string){
|
||||
if ws.state != .closed && ws.socket.sockfd > 1 {
|
||||
|
||||
ws.lock.lock()
|
||||
@ -248,7 +248,7 @@ pub fn (ws mut Client) close(code int, message string){
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (ws mut Client) write(payload byteptr, payload_len int, code OPCode) int {
|
||||
pub fn (mut ws Client) write(payload byteptr, payload_len int, code OPCode) int {
|
||||
if ws.state != .open {
|
||||
ws.send_error_event("WebSocket closed. Cannot write.")
|
||||
goto free_data
|
||||
@ -319,7 +319,7 @@ pub fn (ws mut Client) write(payload byteptr, payload_len int, code OPCode) int
|
||||
return bytes_written
|
||||
}
|
||||
|
||||
pub fn (ws mut Client) listen() {
|
||||
pub fn (mut ws Client) listen() {
|
||||
l.i("Starting listener...")
|
||||
for ws.state == .open {
|
||||
ws.read()
|
||||
@ -327,7 +327,7 @@ pub fn (ws mut Client) listen() {
|
||||
l.i("Listener stopped as websocket was closed.")
|
||||
}
|
||||
|
||||
pub fn (ws mut Client) read() int {
|
||||
pub fn (mut ws Client) read() int {
|
||||
mut bytes_read := u64(0)
|
||||
|
||||
initial_buffer := u64(256)
|
||||
@ -601,7 +601,7 @@ pub fn (ws mut Client) read() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
fn (ws mut Client) send_control_frame(code OPCode, frame_typ string, payload []byte) int {
|
||||
fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []byte) int {
|
||||
if ws.socket.sockfd <= 0 {
|
||||
l.e("No socket opened.")
|
||||
goto free_data
|
||||
|
Reference in New Issue
Block a user