mirror of
https://gitea.invidious.io/iv-org/lsquic.cr
synced 2024-08-15 00:43:31 +00:00
Revert "Merge pull request #7 from tenpura-shrimp/processconns5"
This reverts commit3aab3dd7f1
, reversing changes made tocb01d0fbb8
.
This commit is contained in:
parent
3aab3dd7f1
commit
db4f73c25c
1 changed files with 5 additions and 45 deletions
|
@ -145,7 +145,6 @@ module QUIC
|
||||||
@read_timeout : Float64?
|
@read_timeout : Float64?
|
||||||
@socket : UDPSocket?
|
@socket : UDPSocket?
|
||||||
@stream_ctx : StreamCtx?
|
@stream_ctx : StreamCtx?
|
||||||
@process_fiber : Fiber
|
|
||||||
|
|
||||||
def initialize(@host : String, port = nil, tls : Bool | OpenSSL::SSL::Context::Client = false)
|
def initialize(@host : String, port = nil, tls : Bool | OpenSSL::SSL::Context::Client = false)
|
||||||
check_host_only(@host)
|
check_host_only(@host)
|
||||||
|
@ -163,7 +162,6 @@ module QUIC
|
||||||
@stream_channel = Channel(StreamCtx?).new(20)
|
@stream_channel = Channel(StreamCtx?).new(20)
|
||||||
@stream_ctx = nil
|
@stream_ctx = nil
|
||||||
@engine_open = false
|
@engine_open = false
|
||||||
@process_fiber = Fiber.new { puts "process_fiber started before run_engine" }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_engine
|
def run_engine
|
||||||
|
@ -211,7 +209,7 @@ module QUIC
|
||||||
while stream_ctx = @stream_channel.receive
|
while stream_ctx = @stream_channel.receive
|
||||||
LibLsquic.conn_set_ctx(conn, Box.box(stream_ctx))
|
LibLsquic.conn_set_ctx(conn, Box.box(stream_ctx))
|
||||||
LibLsquic.conn_make_stream(conn)
|
LibLsquic.conn_make_stream(conn)
|
||||||
client_process_conns(engine)
|
LibLsquic.engine_process_conns(engine)
|
||||||
end
|
end
|
||||||
@engine_open = false
|
@engine_open = false
|
||||||
LibLsquic.engine_destroy(engine)
|
LibLsquic.engine_destroy(engine)
|
||||||
|
@ -219,47 +217,13 @@ module QUIC
|
||||||
@socket = nil
|
@socket = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@process_fiber = spawn do
|
|
||||||
loop do
|
|
||||||
sleep
|
|
||||||
LibLsquic.engine_process_conns(engine)
|
|
||||||
diff = 0
|
|
||||||
# check advisory time
|
|
||||||
if LibLsquic.engine_earliest_adv_tick(engine, pointerof(diff)) != 0
|
|
||||||
Crystal::Scheduler.current_fiber.resume_event.add(diff.microseconds)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
buffers = [] of Bytes
|
buffer = Bytes.new(0x600)
|
||||||
bytes_read = [] of Int32
|
|
||||||
loop do
|
loop do
|
||||||
# wait until the socket has something.
|
bytes_read = socket.read buffer
|
||||||
socket.wait_readable
|
|
||||||
# read available messages from the socket into the buffers.
|
|
||||||
buffers_read = 0
|
|
||||||
loop do
|
|
||||||
if (buffers_read >= buffers.size)
|
|
||||||
buffers.push(Bytes.new(0x600))
|
|
||||||
bytes_read.push(0)
|
|
||||||
end
|
|
||||||
bytes_read[buffers_read] = LibC.recv(socket.fd, buffers[buffers_read], buffers[buffers_read].size, 0).to_i32
|
|
||||||
if bytes_read[buffers_read] == -1
|
|
||||||
if Errno.value == Errno::EAGAIN || Errno.value == Errno::EWOULDBLOCK
|
|
||||||
# no more messages are currently available to read from the socket.
|
|
||||||
break
|
|
||||||
else
|
|
||||||
raise IO::Error.from_errno("failed to read from socket")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
buffers_read += 1
|
|
||||||
end
|
|
||||||
break if !@engine_open
|
break if !@engine_open
|
||||||
buffers[0, buffers_read].zip(bytes_read) do |buffer, bytes|
|
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_packet_in(engine, buffer[0, bytes], bytes, socket.local_address, socket.remote_address, Box.box(socket), 0) if bytes != 0
|
LibLsquic.engine_process_conns(engine)
|
||||||
end
|
|
||||||
client_process_conns(engine)
|
|
||||||
end
|
end
|
||||||
@socket.try &.close
|
@socket.try &.close
|
||||||
@socket = nil
|
@socket = nil
|
||||||
|
@ -268,10 +232,6 @@ module QUIC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def client_process_conns(engine)
|
|
||||||
Crystal::Scheduler.yield @process_fiber
|
|
||||||
end
|
|
||||||
|
|
||||||
def socket : UDPSocket
|
def socket : UDPSocket
|
||||||
socket = @socket
|
socket = @socket
|
||||||
return socket.not_nil! if @socket
|
return socket.not_nil! if @socket
|
||||||
|
|
Loading…
Reference in a new issue