close socket when the connection is closed (#2)

Close socket when the connection is closed
This commit is contained in:
Van Huynh 2020-10-16 01:41:24 -07:00 committed by GitHub
parent 24dc58db99
commit 4855742c45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -213,17 +213,24 @@ module QUIC
end end
@engine_open = false @engine_open = false
LibLsquic.engine_destroy(engine) LibLsquic.engine_destroy(engine)
@socket.try &.close
@socket = nil
end end
buffer = Bytes.new(0x600) begin
loop do buffer = Bytes.new(0x600)
bytes_read = socket.read buffer loop do
break if !@engine_open bytes_read = socket.read buffer
LibLsquic.engine_packet_in(engine, buffer[0, bytes_read], bytes_read, socket.local_address, socket.remote_address, Box.box(socket), 0) if bytes_read != 0 break if !@engine_open
LibLsquic.engine_process_conns(engine) LibLsquic.engine_packet_in(engine, buffer[0, bytes_read], bytes_read, socket.local_address, socket.remote_address, Box.box(socket), 0) if bytes_read != 0
LibLsquic.engine_process_conns(engine)
end
rescue IO::Error
# may have already been closed
ensure
@socket.try &.close
@socket = nil
end end
@socket.try &.close
@socket = nil
end end
def socket : UDPSocket def socket : UDPSocket