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