/
puma.rb
75 lines (63 loc) · 1.55 KB
/
puma.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true
# Standard libraries
require 'socket'
require 'tempfile'
require 'time'
require 'etc'
require 'uri'
require 'stringio'
require 'thread'
require 'puma/puma_http11'
require 'puma/detect'
require 'puma/json'
module Puma
autoload :Const, 'puma/const'
autoload :Server, 'puma/server'
autoload :Launcher, 'puma/launcher'
# at present, MiniSSL::Engine is only defined in extension code (puma_http11),
# not in minissl.rb
HAS_SSL = const_defined?(:MiniSSL, false) && MiniSSL.const_defined?(:Engine, false)
if HAS_SSL
require 'puma/minissl'
else
module MiniSSL
# this class is defined so that it exists when Puma is compiled
# without ssl support, as Server and Reactor use it in rescue statements.
class SSLError < StandardError ; end
end
end
def self.ssl?
HAS_SSL
end
def self.abstract_unix_socket?
@abstract_unix ||=
if HAS_UNIX_SOCKET
begin
::UNIXServer.new("\0puma.temp.unix").close
true
rescue ArgumentError # darwin
false
end
else
false
end
end
# @!attribute [rw] stats_object=
def self.stats_object=(val)
@get_stats = val
end
# @!attribute [rw] stats_object
def self.stats
Puma::JSON.generate @get_stats.stats
end
# @!attribute [r] stats_hash
# @version 5.0.0
def self.stats_hash
@get_stats.stats
end
# Thread name is new in Ruby 2.3
def self.set_thread_name(name)
return unless Thread.current.respond_to?(:name=)
Thread.current.name = "puma #{name}"
end
end