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:
@@ -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]
|
||||
}
|
||||
|
||||
|
@@ -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++ {
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user