mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
io: migrate the Reader API to Result instead of Option (#15229)
This commit is contained in:
@@ -8,9 +8,9 @@ mut:
|
||||
place int
|
||||
}
|
||||
|
||||
fn (mut s StringReader) read(mut buf []u8) ?int {
|
||||
fn (mut s StringReader) read(mut buf []u8) !int {
|
||||
if s.place >= s.text.len {
|
||||
return none
|
||||
return IError(io.Eof{})
|
||||
}
|
||||
max_bytes := 100
|
||||
end := if s.place + max_bytes >= s.text.len { s.text.len } else { s.place + max_bytes }
|
||||
|
||||
@@ -180,8 +180,8 @@ pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr &u8, len int) ?int {
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (mut s SSLConn) read(mut buffer []u8) ?int {
|
||||
res := s.socket_read_into_ptr(&u8(buffer.data), buffer.len)?
|
||||
pub fn (mut s SSLConn) read(mut buffer []u8) !int {
|
||||
res := s.socket_read_into_ptr(&u8(buffer.data), buffer.len) or { return err }
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module net
|
||||
|
||||
import time
|
||||
import io
|
||||
import strings
|
||||
|
||||
const (
|
||||
@@ -132,8 +133,13 @@ pub fn (c TcpConn) read_ptr(buf_ptr &u8, len int) ?int {
|
||||
return none
|
||||
}
|
||||
|
||||
pub fn (c TcpConn) read(mut buf []u8) ?int {
|
||||
return c.read_ptr(buf.data, buf.len)
|
||||
pub fn (c TcpConn) read(mut buf []u8) !int {
|
||||
return c.read_ptr(buf.data, buf.len) or {
|
||||
return IError(io.NotExpected{
|
||||
cause: 'unexpected error in `read_ptr` function'
|
||||
code: -1
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut c TcpConn) read_deadline() ?time.Time {
|
||||
|
||||
@@ -9,10 +9,10 @@ fn (mut ws Client) socket_read(mut buffer []u8) ?int {
|
||||
return error('socket_read: trying to read a closed socket')
|
||||
}
|
||||
if ws.is_ssl {
|
||||
r := ws.ssl_conn.read(mut buffer)?
|
||||
r := ws.ssl_conn.read(mut buffer) or { return none }
|
||||
return r
|
||||
} else {
|
||||
r := ws.conn.read(mut buffer)?
|
||||
r := ws.conn.read(mut buffer) or { return none }
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user