From 35db6f019f9ebcf95d2b393111193474fec900d1 Mon Sep 17 00:00:00 2001 From: Chris Foster Date: Fri, 27 Aug 2021 01:44:48 +1000 Subject: [PATCH] Rename shutdown() to closewrite() (#41995) This name was suggested in #24526 and * Has a good analogy to close(), so people are likely to be able to guess what it means. * Is more specific to IO (conversely, it's easy to imagine shutdown() being wanted for any number of things unrelated to closing the write side of an IO stream). --- NEWS.md | 2 +- base/exports.jl | 2 +- base/io.jl | 8 ++++---- base/iobuffer.jl | 4 ++-- base/process.jl | 2 +- base/stream.jl | 4 ++-- doc/src/base/io-network.md | 2 +- stdlib/Sockets/test/runtests.jl | 4 ++-- test/iobuffer.jl | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/NEWS.md b/NEWS.md index 6ac3546e969bb1..ae6880b5a8d0dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -49,7 +49,7 @@ Standard library changes overflow in most cases. The new function `checked_length` is now available, which will try to use checked arithmetic to error if the result may be wrapping. Or use a package such as SaferIntegers.jl when constructing the range. ([#40382]) -* TCP socket objects now expose `shutdown` functionality and support half-open mode usage ([#40783]). +* TCP socket objects now expose `closewrite` functionality and support half-open mode usage ([#40783]). #### InteractiveUtils * A new macro `@time_imports` for reporting any time spent importing packages and their dependencies ([#41612]) diff --git a/base/exports.jl b/base/exports.jl index da0019ab469877..36baa386d5510a 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -803,7 +803,7 @@ export # I/O and events close, - shutdown, + closewrite, countlines, eachline, readeach, diff --git a/base/io.jl b/base/io.jl index 2eface1ca94581..9e7248c55c43ad 100644 --- a/base/io.jl +++ b/base/io.jl @@ -62,7 +62,7 @@ Close an I/O stream. Performs a [`flush`](@ref) first. function close end """ - shutdown(stream) + closewrite(stream) Shutdown the write half of a full-duplex I/O stream. Performs a [`flush`](@ref) first. Notify the other end that no more data will be written to the underlying @@ -76,12 +76,12 @@ julia> write(io, "request"); julia> # calling `read(io)` here would block forever -julia> shutdown(io); +julia> closewrite(io); julia> read(io, String) "request" """ -function shutdown end +function closewrite end """ flush(stream) @@ -410,7 +410,7 @@ end function pipe_reader end function pipe_writer end -for f in (:flush, :shutdown, :iswritable) +for f in (:flush, :closewrite, :iswritable) @eval $(f)(io::AbstractPipe) = $(f)(pipe_writer(io)::IO) end write(io::AbstractPipe, byte::UInt8) = write(pipe_writer(io)::IO, byte) diff --git a/base/iobuffer.jl b/base/iobuffer.jl index f65ed3f894fe00..e08a019d84a2ca 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -334,9 +334,9 @@ end eof(io::GenericIOBuffer) = (io.ptr-1 == io.size) -function shutdown(io::GenericIOBuffer) +function closewrite(io::GenericIOBuffer) io.writable = false - # OR throw(_UVError("shutdown", UV_ENOTSOCK)) + # OR throw(_UVError("closewrite", UV_ENOTSOCK)) nothing end diff --git a/base/process.jl b/base/process.jl index 6be7099f94f358..666c94c49a7fa0 100644 --- a/base/process.jl +++ b/base/process.jl @@ -275,7 +275,7 @@ function setup_stdio(stdio::Union{IOBuffer, BufferStream}, child_readable::Bool) @warn "Process error" exception=(ex, catch_backtrace()) finally close(parent) - child_readable || shutdown(stdio) + child_readable || closewrite(stdio) end end catch ex diff --git a/base/stream.jl b/base/stream.jl index f4bd8b29fc981d..b9bfa7aee1d960 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -433,7 +433,7 @@ function wait_readnb(x::LibuvStream, nb::Int) nothing end -function shutdown(s::LibuvStream) +function closewrite(s::LibuvStream) iolock_begin() check_open(s) req = Libc.malloc(_sizeof_uv_shutdown) @@ -1478,7 +1478,7 @@ end isopen(s::BufferStream) = s.status != StatusClosed -shutdown(s::BufferStream) = close(s) +closewrite(s::BufferStream) = close(s) function close(s::BufferStream) lock(s.cond) do diff --git a/doc/src/base/io-network.md b/doc/src/base/io-network.md index 8b2ea3c4c2412f..ba7d779f9152ae 100644 --- a/doc/src/base/io-network.md +++ b/doc/src/base/io-network.md @@ -13,7 +13,7 @@ Base.take!(::Base.GenericIOBuffer) Base.fdio Base.flush Base.close -Base.shutdown +Base.closewrite Base.write Base.read Base.read! diff --git a/stdlib/Sockets/test/runtests.jl b/stdlib/Sockets/test/runtests.jl index 328ea929f4b4ba..90a281050d150a 100644 --- a/stdlib/Sockets/test/runtests.jl +++ b/stdlib/Sockets/test/runtests.jl @@ -566,7 +566,7 @@ end end let s = Sockets.connect(addr) @test iswritable(s) - shutdown(s) + closewrite(s) @test !iswritable(s) close(s) end @@ -578,7 +578,7 @@ end end @test iswritable(s) write(s, "hello world\n") - shutdown(s) + closewrite(s) @test !iswritable(s) @test isreadable(s) @test read(s, String) == "hello world\n" diff --git a/test/iobuffer.jl b/test/iobuffer.jl index 5514b6dc03f7fa..d8211aa7086b34 100644 --- a/test/iobuffer.jl +++ b/test/iobuffer.jl @@ -46,7 +46,7 @@ bufcontents(io::Base.GenericIOBuffer) = unsafe_string(pointer(io.data), io.size) @test String(take!(io)) == "" @test write(io, ComplexF64(0)) === 16 @test write(io, Rational{Int64}(1//2)) === 16 - @test shutdown(io) === nothing + @test closewrite(io) === nothing @test_throws ArgumentError write(io, UInt8[0]) @test eof(io) @test close(io) === nothing @@ -253,7 +253,7 @@ end @test !eof(bstream) read!(bstream,c) @test c == a[3:10] - @test shutdown(bstream) === nothing + @test closewrite(bstream) === nothing @test eof(bstream) @test bytesavailable(bstream) == 0 @test close(bstream) === nothing