This repository was archived by the owner on Aug 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-11
lines changed Expand file tree Collapse file tree 2 files changed +34
-11
lines changed Original file line number Diff line number Diff line change @@ -77,16 +77,9 @@ def bind
77
77
task = Async ::Task . current
78
78
79
79
@wrappers . each do |server |
80
- server = server . dup
81
-
82
80
task . async do |task |
83
81
task . annotate "binding to #{ server . inspect } "
84
-
85
- begin
86
- yield server , task
87
- ensure
88
- server . close
89
- end
82
+ yield server , task
90
83
end
91
84
end
92
85
end
@@ -109,9 +102,9 @@ def connect
109
102
end
110
103
end
111
104
112
- def accept ( backlog = nil , &block )
105
+ def accept ( backlog = nil , ** options , &block )
113
106
bind do |server |
114
- server . accept_each ( &block )
107
+ server . accept_each ( ** options , &block )
115
108
end
116
109
end
117
110
Original file line number Diff line number Diff line change 10
10
include_context Async ::RSpec ::Reactor
11
11
12
12
describe '#bound' do
13
- let ( :endpoint ) { Async ::IO ::Endpoint . udp ( "localhost" , 5123 , timeout : 10 ) }
13
+ let ( :endpoint ) { Async ::IO ::Endpoint . tcp ( "localhost" , 5123 , timeout : 10 ) }
14
14
15
15
it "can bind to shared endpoint" do
16
16
bound_endpoint = described_class . bound ( endpoint )
33
33
34
34
bound_endpoint . close
35
35
end
36
+
37
+ it "can close a bound endpoint to terminate accept loop" do
38
+ bound_endpoint = described_class . bound ( endpoint )
39
+ expect ( bound_endpoint . wrappers ) . to_not be_empty
40
+
41
+ server_task = Async do
42
+ bound_endpoint . accept do |io |
43
+ io . close
44
+ end
45
+ end
46
+
47
+ connect = proc do
48
+ endpoint . connect do |io |
49
+ io . write "Hello World"
50
+ io . close
51
+ end
52
+ end
53
+
54
+ connect . call
55
+
56
+ wrapper = bound_endpoint . wrappers . first
57
+ expect ( wrapper ) . to be_a Async ::IO ::Socket
58
+
59
+ bound_endpoint . close
60
+ expect ( wrapper ) . to be_closed
61
+
62
+ expect do
63
+ connect . call
64
+ end . to raise_error ( Errno ::ECONNRESET )
65
+ end
36
66
end
37
67
38
68
describe '#connected' do
You can’t perform that action at this time.
0 commit comments