diff --git a/examples/buf_reader.v b/examples/buf_reader.v index 5e1770b293..e754f61cdb 100644 --- a/examples/buf_reader.v +++ b/examples/buf_reader.v @@ -9,7 +9,7 @@ fn main() { // Simple http HEAD request for a file conn.write_string('GET /index.html HTTP/1.0\r\n\r\n') ? // Wrap in a buffered reader - mut r := io.new_buffered_reader(reader: io.make_reader(conn)) + mut r := io.new_buffered_reader(reader: conn) for { l := r.read_line() or { break } println('$l') diff --git a/vlib/io/custom_string_reading_test.v b/vlib/io/custom_string_reading_test.v index 7a1212a84c..76e3307395 100644 --- a/vlib/io/custom_string_reading_test.v +++ b/vlib/io/custom_string_reading_test.v @@ -28,7 +28,7 @@ fn read_from_string(text string, capacity int) []byte { mut str := StringReader{ text: text } - mut stream := io.new_buffered_reader(reader: io.make_reader(str), cap: capacity) + mut stream := io.new_buffered_reader(reader: str, cap: capacity) // mut buf := []byte{len: 1} mut res := []byte{} diff --git a/vlib/io/os_file_reader_test.v b/vlib/io/os_file_reader_test.v index 409845f9f4..1ed3a1f7f4 100644 --- a/vlib/io/os_file_reader_test.v +++ b/vlib/io/os_file_reader_test.v @@ -7,7 +7,7 @@ fn read_file(file string, cap int) []string { defer { f.close() } - mut r := io.new_buffered_reader(reader: io.make_reader(f), cap: cap) + mut r := io.new_buffered_reader(reader: f, cap: cap) for { l := r.read_line() or { break } lines << l diff --git a/vlib/io/reader.v b/vlib/io/reader.v index a3e89d8105..b7377b0872 100644 --- a/vlib/io/reader.v +++ b/vlib/io/reader.v @@ -13,6 +13,8 @@ pub interface Reader { // (e.g. for use in struct initialisation) // (this shouldnt need to be a thing but until coercion gets made better // it is required) +[deprecated: 'use just `x` instead of `io.make_reader(x)`. Interfaces are now checked against all types.'] +[deprecated_after: '2021-05-27'] pub fn make_reader(r Reader) Reader { return r } diff --git a/vlib/io/reader_test.v b/vlib/io/reader_test.v index 8622c79bac..c7a2265af9 100644 --- a/vlib/io/reader_test.v +++ b/vlib/io/reader_test.v @@ -62,7 +62,7 @@ fn test_stringreader() { mut s := StringReader{ text: text } - mut r := new_buffered_reader(reader: make_reader(s)) + mut r := new_buffered_reader(reader: s) for i := 0; true; i++ { if _ := r.read_line() { } else { @@ -87,7 +87,7 @@ fn test_stringreader2() { mut s := StringReader{ text: text } - mut r := new_buffered_reader(reader: make_reader(s)) + mut r := new_buffered_reader(reader: s) for i := 0; true; i++ { if _ := r.read_line() { } else { @@ -98,7 +98,7 @@ fn test_stringreader2() { if _ := r.read_line() { assert false } - leftover := read_all(reader: make_reader(r)) or { + leftover := read_all(reader: r) or { assert false panic('bad') } @@ -112,7 +112,7 @@ fn test_leftover() { mut s := StringReader{ text: text } - mut r := new_buffered_reader(reader: make_reader(s)) + mut r := new_buffered_reader(reader: s) _ := r.read_line() or { assert false panic('bad') diff --git a/vlib/net/ftp/ftp.v b/vlib/net/ftp/ftp.v index f27ebb537a..41b2cde70c 100644 --- a/vlib/net/ftp/ftp.v +++ b/vlib/net/ftp/ftp.v @@ -103,7 +103,7 @@ fn (mut zftp FTP) read() ?(int, string) { pub fn (mut zftp FTP) connect(ip string) ?bool { zftp.conn = net.dial_tcp('$ip:21') ? - zftp.reader = io.new_buffered_reader(reader: io.make_reader(zftp.conn)) + zftp.reader = io.new_buffered_reader(reader: zftp.conn) code, _ := zftp.read() ? if code == ftp.connected { return true @@ -184,7 +184,7 @@ fn new_dtp(msg string) ?&DTP { } conn := net.dial_tcp('$ip:$port') or { return error('Cannot connect to the data channel') } dtp.conn = conn - dtp.reader = io.new_buffered_reader(reader: io.make_reader(dtp.conn)) + dtp.reader = io.new_buffered_reader(reader: dtp.conn) return dtp } diff --git a/vlib/net/smtp/smtp.v b/vlib/net/smtp/smtp.v index 1755bb9c33..50c537c62e 100644 --- a/vlib/net/smtp/smtp.v +++ b/vlib/net/smtp/smtp.v @@ -71,7 +71,7 @@ pub fn (mut c Client) reconnect() ? { conn := net.dial_tcp('$c.server:$c.port') or { return error('Connecting to server failed') } c.conn = conn - c.reader = io.new_buffered_reader(reader: io.make_reader(c.conn)) + c.reader = io.new_buffered_reader(reader: c.conn) c.expect_reply(.ready) or { return error('Received invalid response from server') } c.send_ehlo() or { return error('Sending EHLO packet failed') } diff --git a/vlib/net/tcp_read_line.v b/vlib/net/tcp_read_line.v index c76db99fd1..38e24f9585 100644 --- a/vlib/net/tcp_read_line.v +++ b/vlib/net/tcp_read_line.v @@ -9,13 +9,13 @@ const ( // read_line is a *simple*, *non customizable*, blocking line reader. // It will *always* return a line, ending with CRLF, or just '', on EOF. // NB: if you want more control over the buffer, please use a buffered IO -// reader instead: `io.new_buffered_reader({reader: io.make_reader(con)})` +// reader instead: `io.new_buffered_reader(reader: con)` pub fn (mut con TcpConn) read_line() string { - mut buf := [max_read]byte{} // where C.recv will store the network data + mut buf := [net.max_read]byte{} // where C.recv will store the network data mut res := '' // The final result, including the ending \n. for { mut line := '' // The current line. Can be a partial without \n in it. - n := C.recv(con.sock.handle, &buf[0], max_read - 1, msg_peek | msg_nosignal) + n := C.recv(con.sock.handle, &buf[0], net.max_read - 1, net.msg_peek | msg_nosignal) if n == -1 { return res } @@ -48,7 +48,7 @@ pub fn (mut con TcpConn) read_line() string { // recv returned a buffer without \n in it . C.recv(con.sock.handle, &buf[0], n, msg_nosignal) res += line - res += crlf + res += net.crlf break } return res diff --git a/vlib/net/tcp_simple_client_server_test.v b/vlib/net/tcp_simple_client_server_test.v index 321ed04579..4c95cfa242 100644 --- a/vlib/net/tcp_simple_client_server_test.v +++ b/vlib/net/tcp_simple_client_server_test.v @@ -19,9 +19,9 @@ fn setup() (&net.TcpListener, &net.TcpConn, &net.TcpConn) { } fn cleanup(mut server net.TcpListener, mut client net.TcpConn, mut socket net.TcpConn) { - server.close() or { } - client.close() or { } - socket.close() or { } + server.close() or {} + client.close() or {} + socket.close() or {} } fn test_socket() { @@ -74,9 +74,7 @@ fn test_socket_write_and_read() { fn test_socket_read_line() { mut server, mut client, mut socket := setup() - mut reader := io.new_buffered_reader( - reader: io.make_reader(client) - ) + mut reader := io.new_buffered_reader(reader: client) defer { cleanup(mut server, mut client, mut socket) } @@ -108,7 +106,7 @@ fn test_socket_write_fail_without_panic() { // ensure that socket.write (i.e. done on the server side) // continues to work, even when the client side has been disconnected // this test is important for a stable long standing server - client.close() or { } + client.close() or {} $if solaris { return } @@ -123,9 +121,7 @@ fn test_socket_write_fail_without_panic() { fn test_socket_read_line_long_line_without_eol() { mut server, mut client, mut socket := setup() - mut reader := io.new_buffered_reader( - reader: io.make_reader(client) - ) + mut reader := io.new_buffered_reader(reader: client) defer { cleanup(mut server, mut client, mut socket) } diff --git a/vlib/vweb/request_test.v b/vlib/vweb/request_test.v index b935a2e2e9..d39637e20e 100644 --- a/vlib/vweb/request_test.v +++ b/vlib/vweb/request_test.v @@ -20,7 +20,11 @@ fn (mut s StringReader) read(mut buf []byte) ?int { } fn reader(s string) &io.BufferedReader { - return io.new_buffered_reader(reader: io.make_reader(&StringReader{ text: s })) + return io.new_buffered_reader( + reader: &StringReader{ + text: s + } + ) } fn test_parse_request_not_http() { diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 0d6f762205..6d0b034027 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -337,7 +337,7 @@ fn handle_conn(mut conn net.TcpConn, mut app T) { defer { conn.close() or {} } - mut reader := io.new_buffered_reader(reader: io.make_reader(conn)) + mut reader := io.new_buffered_reader(reader: conn) defer { reader.free() }