1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

x.websockets: new websockets module on top of x.net (#6189)

This commit is contained in:
Tomas Hellström
2020-08-22 00:50:38 +02:00
committed by GitHub
parent 1b914d217e
commit fb148e0b61
29 changed files with 2302 additions and 1 deletions

View File

@@ -92,4 +92,4 @@ fn C.FD_SET()
fn C.FD_ISSET() bool
[typedef]
struct C.fd_set {}
pub struct C.fd_set {}

View File

@@ -70,6 +70,25 @@ pub fn (c TcpConn) write_string(s string) ? {
return c.write_ptr(s.str, s.len)
}
pub fn (c TcpConn) read_into_ptr(buf_ptr byteptr, len int) ?int {
res := C.recv(c.sock.handle, buf_ptr, len, 0)
if res >= 0 {
return res
}
code := error_code()
match code {
error_ewouldblock {
c.wait_for_read()?
return socket_error(C.recv(c.sock.handle, buf_ptr, len, 0))
}
else {
wrap_error(code)?
}
}
}
pub fn (c TcpConn) read_into(mut buf []byte) ?int {
res := C.recv(c.sock.handle, buf.data, buf.len, 0)