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

tcp/udp: fix mutability

This commit is contained in:
Alexander Medvednikov
2020-09-27 03:40:59 +02:00
parent fca344d1fb
commit 3d5292b63f
6 changed files with 16 additions and 8 deletions

View File

@@ -109,8 +109,8 @@ pub fn (c TcpConn) read_into(mut buf []byte) ?int {
}
pub fn (c TcpConn) read() ?[]byte {
buf := []byte { len: 1024 }
read := c.read_into(buf)?
mut buf := []byte { len: 1024 }
read := c.read_into(mut buf)?
return buf[..read]
}

View File

@@ -12,7 +12,7 @@ fn handle_conn(_c net.TcpConn) {
c.set_read_timeout(10 * time.second)
c.set_write_timeout(10 * time.second)
for {
buf := []byte{len: 100, init: 0}
mut buf := []byte{len: 100, init: 0}
read := c.read_into(mut buf) or {
println('Server: connection dropped')
return
@@ -45,7 +45,7 @@ fn echo() ? {
c.set_write_timeout(10 * time.second)
data := 'Hello from vlib/net!'
c.write_string(data)?
buf := []byte{len: 100, init: 0}
mut buf := []byte{len: 100, init: 0}
read := c.read_into(mut buf)?
assert read == data.len
for i := 0; i < read; i++ {

View File

@@ -115,7 +115,7 @@ pub fn (c UdpConn) read_into(mut buf []byte) ?(int, Addr) {
}
pub fn (c UdpConn) read() ?([]byte, Addr) {
buf := []byte { len: 1024 }
mut buf := []byte { len: 1024 }
read, addr := c.read_into(mut buf)?
return buf[..read], addr
}