Skip to content

Commit

Permalink
Prevents premature EOFError on blocking reads
Browse files Browse the repository at this point in the history
Blocks until the required number of bytes has been read. Only throws EOFError on actual EOF. Fixes JuliaLang#13559.
  • Loading branch information
hessammehr committed Oct 15, 2015
1 parent b22b652 commit 122205a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ function read(s::IOStream, ::Type{UInt8})
end

function read{T<:Union{UInt16, Int16, UInt32, Int32, UInt64, Int64}}(s::IOStream, ::Type{T})
ccall(:jl_ios_get_nbyte_int, UInt64, (Ptr{Void}, Csize_t), s.ios, sizeof(T)) % T
data = readbytes(s, sizeof(T), all=true)
if length(data) < sizeof(T)
throw(EOFError())
end
first(reinterpret(T, data))
end

function read!(s::IOStream, a::Vector{UInt8})
Expand Down

0 comments on commit 122205a

Please sign in to comment.