Skip to content

Commit 6769ffa

Browse files
committed
WIP
1 parent 317f078 commit 6769ffa

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

examples/hello/config.ru

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
# frozen_string_literal: true
33

44
run do |env|
5+
Console.info(self, "Sleeping 10 seconds")
6+
sleep(10)
7+
Console.info(self, "Waking up")
8+
59
[200, {}, ["Hello World"]]
610
end

examples/hello/falcon.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,29 @@
88
require "falcon/environment/rack"
99
require "falcon/environment/supervisor"
1010

11+
require_relative "limited"
12+
1113
service "hello.localhost" do
12-
include Falcon::Environment::SelfSignedTLS
1314
include Falcon::Environment::Rack
1415

1516
scheme "http"
1617
protocol {Async::HTTP::Protocol::HTTP}
1718

18-
# endpoint do
19-
# Async::HTTP::Endpoint.for(scheme, "localhost", port: 9292, protocol: protocol)
20-
# end
19+
connection_semaphore {Async::Semaphore.new(1)}
20+
21+
endpoint_options do
22+
super().merge({
23+
wrapper: LimitedAcceptor.new(connection_semaphore)
24+
})
25+
end
26+
27+
count 1
2128

22-
# append preload "preload.rb"
29+
url "http://localhost:8080"
2330

24-
# Process will connect to supervisor to report statistics periodically, otherwise it would be killed.
25-
# report :supervisor
31+
endpoint do
32+
::Async::HTTP::Endpoint.parse(url).with(**endpoint_options)
33+
end
2634
end
2735

2836
service "supervisor" do

examples/hello/limited.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class LimitedAcceptor < IO::Endpoint::Wrapper
2+
def initialize(semaphore)
3+
@semaphore = semaphore
4+
end
5+
6+
def async(&block)
7+
::Fiber.schedule(&block)
8+
end
9+
10+
def before_accept(server)
11+
server.wait_readable
12+
13+
Console.info(self, semaphore: @semaphore) {"Acquiring semaphore..."}
14+
@semaphore.acquire
15+
Console.info(self, semaphore: @semaphore) {"Acquired semaphore."}
16+
end
17+
end

lib/falcon/environment/server.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def count
3333

3434
# Options to use when creating the container.
3535
def container_options
36-
{restart: true, count: self.count, health_check_timeout: 30}.compact
36+
{
37+
restart: true,
38+
count: self.count,
39+
health_check_timeout: 30
40+
}.compact
3741
end
3842

3943
# The host that this server will receive connections for.
@@ -45,13 +49,17 @@ def timeout
4549
nil
4650
end
4751

52+
def endpoint_options
53+
{
54+
reuse_address: true,
55+
timeout: timeout,
56+
}
57+
end
58+
4859
# The upstream endpoint that will handle incoming requests.
4960
# @returns [Async::HTTP::Endpoint]
5061
def endpoint
51-
::Async::HTTP::Endpoint.parse(url).with(
52-
reuse_address: true,
53-
timeout: timeout,
54-
)
62+
::Async::HTTP::Endpoint.parse(url).with(**endpoint_options)
5563
end
5664

5765
def verbose

0 commit comments

Comments
 (0)