@@ -94,25 +94,25 @@ pub fn (mut c UdpConn) write_to_string(addr Addr, s string) !int {
9494 return c.write_to_ptr (addr, s.str, s.len)
9595}
9696
97- // read reads from the socket into buf up to buf. len returning the number of bytes read
98- pub fn (mut c UdpConn) read ( mut buf [] u8 ) ! (int , Addr) {
97+ // read_ptr reads from the socket into `buf_ptr` up to ` len` bytes, returning the number of bytes read and the `Addr` read from.
98+ pub fn (c & UdpConn) read_ptr (buf_ptr & u8 , len int ) ! (int , Addr) {
9999 mut addr := Addr{
100100 addr: AddrData{
101101 Ip6 : Ip6 {}
102102 }
103103 }
104- len := sizeof (Addr)
105- mut res := wrap_read_result (C.recvfrom (c.sock.handle, voidptr (buf.data ), buf. len,
106- 0 , voidptr ( & addr), & len ))!
104+ addr_len := sizeof (Addr)
105+ mut res := wrap_read_result (C.recvfrom (c.sock.handle, voidptr (buf_ptr ), len, 0 , voidptr ( & addr) ,
106+ & addr_len ))!
107107 if res > 0 {
108108 return res, addr
109109 }
110110 code := error_code ()
111111 if code == int (error_ewouldblock) {
112112 c.wait_for_read ()!
113113 // same setup as in tcp
114- res = wrap_read_result (C.recvfrom (c.sock.handle, voidptr (buf.data ), buf. len, 0 ,
115- voidptr ( & addr), & len ))!
114+ res = wrap_read_result (C.recvfrom (c.sock.handle, voidptr (buf_ptr ), len, 0 , voidptr ( & addr) ,
115+ & addr_len ))!
116116 res2 := socket_error (res)!
117117 return res2 , addr
118118 } else {
@@ -121,6 +121,11 @@ pub fn (mut c UdpConn) read(mut buf []u8) !(int, Addr) {
121121 return error ('none' )
122122}
123123
124+ // read reads from the socket into buf up to buf.len returning the number of bytes read
125+ pub fn (mut c UdpConn) read (mut buf []u8 ) ! (int , Addr) {
126+ return c.read_ptr (buf.data, buf.len)!
127+ }
128+
124129pub fn (c &UdpConn) read_deadline () ! time.Time {
125130 if c.read_deadline.unix () == 0 {
126131 return c.read_deadline
@@ -160,7 +165,7 @@ pub fn (mut c UdpConn) set_write_timeout(t time.Duration) {
160165}
161166
162167@[inline]
163- pub fn (mut c UdpConn) wait_for_read () ! {
168+ pub fn (c & UdpConn) wait_for_read () ! {
164169 return wait_for_read (c.sock.handle, c.read_deadline, c.read_timeout)
165170}
166171
0 commit comments