Skip to content

Commit 14e8cba

Browse files
committed
Use io-stream for buffered streams.
1 parent 44f922d commit 14e8cba

File tree

11 files changed

+31
-25
lines changed

11 files changed

+31
-25
lines changed

async-http.gemspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ Gem::Specification.new do |spec|
2525
spec.required_ruby_version = ">= 3.1"
2626

2727
spec.add_dependency "async", ">= 1.25"
28-
spec.add_dependency "async-io", ">= 1.28"
28+
spec.add_dependency "async-io", ">= 1.43.1"
2929
spec.add_dependency "async-pool", ">= 0.6.1"
30+
spec.add_dependency "io-stream", "~> 0.1.1"
3031
spec.add_dependency "protocol-http", "~> 0.26.0"
3132
spec.add_dependency "protocol-http1", "~> 0.19.0"
3233
spec.add_dependency "protocol-http2", "~> 0.17.0"

fixtures/async/http/a_protocol.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ module HTTP
202202
end
203203

204204
it "disconnects slow clients" do
205+
# We won't be able to disconnect slow clients if IO#timeout is not available:
206+
skip_unless_method_defined(:timeout, IO)
207+
205208
response = client.get("/")
206209
response.read
207210

@@ -478,9 +481,11 @@ def after
478481
end
479482

480483
it "can't get /" do
484+
skip_unless_method_defined(:timeout, IO)
485+
481486
expect do
482487
client.get("/")
483-
end.to raise_exception(Async::TimeoutError)
488+
end.to raise_exception(::IO::TimeoutError)
484489
end
485490
end
486491

gems.rb

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# gem "async", path: "../async"
1111
# gem "async-io", path: "../async-io"
12+
# gem "io-stream", path: "../io-stream"
1213
# gem "traces", path: "../traces"
1314

1415
# gem "protocol-http", path: "../protocol-http"

lib/async/http/body/pipe.rb

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2019-2023, by Samuel Williams.
4+
# Copyright, 2019-2024, by Samuel Williams.
55
# Copyright, 2020, by Bruno Sutic.
66

7-
require 'async/io/socket'
8-
require 'async/io/stream'
9-
107
require_relative 'writable'
118

129
module Async
@@ -18,9 +15,9 @@ def initialize(input, output = Writable.new, task: Task.current)
1815
@input = input
1916
@output = output
2017

21-
head, tail = IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
18+
head, tail = ::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
2219

23-
@head = IO::Stream.new(head)
20+
@head = ::IO::Stream::Buffered.new(head)
2421
@tail = tail
2522

2623
@reader = nil

lib/async/http/protocol/http1.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2017-2023, by Samuel Williams.
4+
# Copyright, 2017-2024, by Samuel Williams.
55

66
require_relative 'http1/client'
77
require_relative 'http1/server'
88

9+
require 'io/stream/buffered'
10+
911
module Async
1012
module HTTP
1113
module Protocol
@@ -21,13 +23,13 @@ def self.trailer?
2123
end
2224

2325
def self.client(peer)
24-
stream = IO::Stream.new(peer, sync: true)
26+
stream = ::IO::Stream::Buffered.wrap(peer)
2527

2628
return HTTP1::Client.new(stream, VERSION)
2729
end
2830

2931
def self.server(peer)
30-
stream = IO::Stream.new(peer, sync: true)
32+
stream = ::IO::Stream::Buffered.wrap(peer)
3133

3234
return HTTP1::Server.new(stream, VERSION)
3335
end

lib/async/http/protocol/http1/connection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def concurrency
6262

6363
# Can we use this connection to make requests?
6464
def viable?
65-
@ready && @stream&.connected?
65+
@ready && @stream&.readable?
6666
end
6767

6868
def reusable?

lib/async/http/protocol/http10.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2017-2023, by Samuel Williams.
4+
# Copyright, 2017-2024, by Samuel Williams.
55

66
require_relative 'http1'
77

@@ -20,13 +20,13 @@ def self.trailer?
2020
end
2121

2222
def self.client(peer)
23-
stream = IO::Stream.new(peer, sync: true)
23+
stream = ::IO::Stream::Buffered.wrap(peer)
2424

2525
return HTTP1::Client.new(stream, VERSION)
2626
end
2727

2828
def self.server(peer)
29-
stream = IO::Stream.new(peer, sync: true)
29+
stream = ::IO::Stream::Buffered.wrap(peer)
3030

3131
return HTTP1::Server.new(stream, VERSION)
3232
end

lib/async/http/protocol/http11.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2017-2023, by Samuel Williams.
4+
# Copyright, 2017-2024, by Samuel Williams.
55
# Copyright, 2018, by Janko Marohnić.
66

77
require_relative 'http1'
@@ -21,13 +21,13 @@ def self.trailer?
2121
end
2222

2323
def self.client(peer)
24-
stream = IO::Stream.new(peer, sync: true)
24+
stream = ::IO::Stream::Buffered.wrap(peer)
2525

2626
return HTTP1::Client.new(stream, VERSION)
2727
end
2828

2929
def self.server(peer)
30-
stream = IO::Stream.new(peer, sync: true)
30+
stream = ::IO::Stream::Buffered.wrap(peer)
3131

3232
return HTTP1::Server.new(stream, VERSION)
3333
end

lib/async/http/protocol/http2.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2018-2023, by Samuel Williams.
4+
# Copyright, 2018-2024, by Samuel Williams.
55

66
require_relative 'http2/client'
77
require_relative 'http2/server'
88

9+
require 'io/stream/buffered'
10+
911
module Async
1012
module HTTP
1113
module Protocol
@@ -35,8 +37,7 @@ def self.trailer?
3537
}
3638

3739
def self.client(peer, settings = CLIENT_SETTINGS)
38-
stream = IO::Stream.new(peer, sync: true)
39-
40+
stream = ::IO::Stream::Buffered.wrap(peer)
4041
client = Client.new(stream)
4142

4243
client.send_connection_preface(settings)
@@ -46,8 +47,7 @@ def self.client(peer, settings = CLIENT_SETTINGS)
4647
end
4748

4849
def self.server(peer, settings = SERVER_SETTINGS)
49-
stream = IO::Stream.new(peer, sync: true)
50-
50+
stream = ::IO::Stream::Buffered.wrap(peer)
5151
server = Server.new(stream)
5252

5353
server.read_connection_preface(settings)

lib/async/http/protocol/http2/connection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def concurrency
122122

123123
# Can we use this connection to make requests?
124124
def viable?
125-
@stream.connected?
125+
@stream&.readable?
126126
end
127127

128128
def reusable?

test/async/http/body/pipe.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def aftrer
4242
end
4343

4444
it "returns an io socket" do
45-
expect(io).to be_a(Async::IO::Socket)
45+
expect(io).to be_a(::Socket)
4646
expect(io.read).to be == data
4747
end
4848

0 commit comments

Comments
 (0)