From d4a8c9260224e356b5688b53cd3040e1fd28b963 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 14 Feb 2024 13:33:00 -0500 Subject: [PATCH 1/4] Use Base.alloc_request instead of implementing it directly There is slightly better error handling in this function, which avoids relying as directly on implementation details of IOBuffer --- src/Connections.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Connections.jl b/src/Connections.jl index dd716340..0329ac2d 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -224,9 +224,10 @@ function read_to_buffer(c::Connection, sizehint=4096) # Read from stream into buffer. n = min(sizehint, bytesavailable(c.io)) buf = c.buffer - Base.ensureroom(buf, n) - GC.@preserve buf unsafe_read(c.io, pointer(buf.data, buf.size + 1), n) + p, n = Base.alloc_request(buf, UInt(n)) + GC.@preserve buf unsafe_read(c.io, p, min(n, bytesavailable(c.io))) buf.size += n + nothing end """ From b240a831b4541919e48df388ce55b7f4dcb5ff79 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 16 Feb 2024 20:03:08 -0500 Subject: [PATCH 2/4] Update Connections.jl --- src/Connections.jl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Connections.jl b/src/Connections.jl index 0329ac2d..77445c21 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -210,12 +210,6 @@ end function read_to_buffer(c::Connection, sizehint=4096) buf = c.buffer - # Reset the buffer if it is empty. - if bytesavailable(buf) == 0 - buf.size = 0 - buf.ptr = 1 - end - # Wait for data. if eof(c.io) throw(EOFError()) @@ -225,8 +219,8 @@ function read_to_buffer(c::Connection, sizehint=4096) n = min(sizehint, bytesavailable(c.io)) buf = c.buffer p, n = Base.alloc_request(buf, UInt(n)) - GC.@preserve buf unsafe_read(c.io, p, min(n, bytesavailable(c.io))) - buf.size += n + n = GC.@preserve buf unsafe_read(c.io, p, min(n, bytesavailable(c.io))) + Base.notify_filled(buf, Int(n)) nothing end From 19c64e459dbaac5ce5f587324319eb7dbc57751a Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 16 Feb 2024 20:20:13 -0500 Subject: [PATCH 3/4] Update Connections.jl --- src/Connections.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Connections.jl b/src/Connections.jl index 77445c21..07c54db6 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -219,7 +219,7 @@ function read_to_buffer(c::Connection, sizehint=4096) n = min(sizehint, bytesavailable(c.io)) buf = c.buffer p, n = Base.alloc_request(buf, UInt(n)) - n = GC.@preserve buf unsafe_read(c.io, p, min(n, bytesavailable(c.io))) + GC.@preserve buf (n = unsafe_read(c.io, p, min(n, bytesavailable(c.io)))) Base.notify_filled(buf, Int(n)) nothing end From 90f3d7932ed59bb705f3f78c51ce98c63ce983c6 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 16 Feb 2024 20:26:48 -0500 Subject: [PATCH 4/4] Update Connections.jl --- src/Connections.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Connections.jl b/src/Connections.jl index 07c54db6..72d81f39 100644 --- a/src/Connections.jl +++ b/src/Connections.jl @@ -219,7 +219,8 @@ function read_to_buffer(c::Connection, sizehint=4096) n = min(sizehint, bytesavailable(c.io)) buf = c.buffer p, n = Base.alloc_request(buf, UInt(n)) - GC.@preserve buf (n = unsafe_read(c.io, p, min(n, bytesavailable(c.io)))) + n = min(n, bytesavailable(c.io)) + GC.@preserve buf unsafe_read(c.io, p, UInt(n)) Base.notify_filled(buf, Int(n)) nothing end