I’m using a TCPSocket
but connect in a inner block
e.g.:
tcp = TCPSocket() # 1
if condition
tcp = connect(1234)
end
...
I know that in C# one has to close and dispose streams and stuff. Is the same true for Julia. Do I need to close the TCPSocket
from # 1?
I looked at the implementation an there is a finalizer(uvfinalize, tcp)
defined. So does it close and dispose after it goes out of scope?
That’s the definition in Julia.
"""
TCPSocket(; delay=true)
Open a TCP socket using libuv. If `delay` is true, libuv delays creation of the
socket's file descriptor till the first [`bind`](@ref) call. `TCPSocket` has various
fields to denote the state of the socket as well as its send/receive buffers.
"""
mutable struct TCPSocket <: LibuvStream
handle::Ptr{Cvoid}
status::Int
buffer::IOBuffer
cond::Base.ThreadSynchronizer
readerror::Any
sendbuf::Union{IOBuffer, Nothing}
lock::ReentrantLock # advisory lock
throttle::Int
function TCPSocket(handle::Ptr{Cvoid}, status)
tcp = new(
handle,
status,
PipeBuffer(),
Base.ThreadSynchronizer(),
nothing,
nothing,
ReentrantLock(),
Base.DEFAULT_READ_BUFFER_SZ)
associate_julia_struct(tcp.handle, tcp)
finalizer(uvfinalize, tcp)
return tcp
end
end