2020-04-08 20:44:30 +03:00
|
|
|
module websocket
|
2020-04-08 15:22:31 +03:00
|
|
|
|
|
|
|
fn C.write() int
|
|
|
|
|
2020-05-17 14:51:18 +03:00
|
|
|
fn (mut ws Client) write_to_server(buf voidptr, len int) int {
|
2020-04-08 15:22:31 +03:00
|
|
|
mut bytes_written := 0
|
|
|
|
ws.write_lock.lock()
|
|
|
|
bytes_written = if ws.is_ssl {
|
|
|
|
C.SSL_write(ws.ssl, buf, len)
|
|
|
|
} else {
|
2020-05-17 14:51:18 +03:00
|
|
|
C.write(ws.socket.sockfd, buf, len)
|
2020-04-08 15:22:31 +03:00
|
|
|
}
|
|
|
|
ws.write_lock.unlock()
|
|
|
|
return bytes_written
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (ws &Client) read_from_server(buffer byteptr, buffer_size int) int {
|
|
|
|
return if ws.is_ssl {
|
|
|
|
C.SSL_read(ws.ssl, buffer, buffer_size)
|
|
|
|
} else {
|
|
|
|
C.read(ws.socket.sockfd, buffer, buffer_size)
|
|
|
|
}
|
2020-05-26 13:50:37 +03:00
|
|
|
}
|