Catch exception in on_close

This commit is contained in:
Omar Roth 2019-11-23 18:16:28 -05:00
parent aa94a6ea1b
commit 0c0d8748a7

View file

@ -77,36 +77,38 @@ class QUIC::Client
end end
ON_READ = ->(s : LibLsquic::StreamT, stream_if_ctx : Void*) do ON_READ = ->(s : LibLsquic::StreamT, stream_if_ctx : Void*) do
stream_ctx = Box(StreamCtx).unbox(stream_if_ctx) begin
stream_ctx = Box(StreamCtx).unbox(stream_if_ctx)
buffer = Bytes.new(0x600) buffer = Bytes.new(0x600)
bytes_read = LibLsquic.stream_read(s, buffer, buffer.size) bytes_read = LibLsquic.stream_read(s, buffer, buffer.size)
if bytes_read > 0 if bytes_read > 0
begin
stream_ctx.writer.try &.write buffer[0, bytes_read] stream_ctx.writer.try &.write buffer[0, bytes_read]
rescue ex elsif bytes_read == 0
LibLsquic.stream_shutdown(s, 0) LibLsquic.stream_shutdown(s, 0)
LibLsquic.stream_wantread(s, 0) LibLsquic.stream_wantread(s, 0)
return Box.box(stream_ctx) elsif LibLsquic.stream_is_rejected(s) == 1
LibLsquic.stream_close(s)
else
"Could not read response"
end end
elsif bytes_read == 0 Box.box(stream_ctx)
rescue ex
LibLsquic.stream_shutdown(s, 0) LibLsquic.stream_shutdown(s, 0)
LibLsquic.stream_wantread(s, 0) LibLsquic.stream_wantread(s, 0)
elsif LibLsquic.stream_is_rejected(s) == 1 Box.box(stream_ctx)
LibLsquic.stream_close(s)
else
"Could not read response"
end end
Box.box(stream_ctx)
end end
ON_CLOSE = ->(s : LibLsquic::StreamT, stream_if_ctx : Void*) do ON_CLOSE = ->(s : LibLsquic::StreamT, stream_if_ctx : Void*) do
stream_ctx = Box(StreamCtx).unbox(stream_if_ctx) begin
stream_ctx.writer.try &.close stream_ctx = Box(StreamCtx).unbox(stream_if_ctx)
stream_ctx.writer.try &.close
Box.box(stream_ctx) Box.box(stream_ctx)
rescue ex
Box.box(stream_ctx)
end
end end
EA_PACKETS_OUT = ->(peer_ctx : Void*, specs : LibLsquic::OutSpec*, count : LibC::UInt) do EA_PACKETS_OUT = ->(peer_ctx : Void*, specs : LibLsquic::OutSpec*, count : LibC::UInt) do