mega-max-tool 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. checksums.yaml +7 -0
  2. data/mega-max-tool.gemspec +12 -0
  3. data/unicorn-6.1.0/Application_Timeouts +77 -0
  4. data/unicorn-6.1.0/CONTRIBUTORS +39 -0
  5. data/unicorn-6.1.0/COPYING +674 -0
  6. data/unicorn-6.1.0/DESIGN +95 -0
  7. data/unicorn-6.1.0/Documentation/unicorn.1 +222 -0
  8. data/unicorn-6.1.0/Documentation/unicorn_rails.1 +207 -0
  9. data/unicorn-6.1.0/FAQ +70 -0
  10. data/unicorn-6.1.0/GIT-VERSION-FILE +1 -0
  11. data/unicorn-6.1.0/GIT-VERSION-GEN +39 -0
  12. data/unicorn-6.1.0/GNUmakefile +313 -0
  13. data/unicorn-6.1.0/HACKING +112 -0
  14. data/unicorn-6.1.0/ISSUES +97 -0
  15. data/unicorn-6.1.0/KNOWN_ISSUES +79 -0
  16. data/unicorn-6.1.0/LATEST +24 -0
  17. data/unicorn-6.1.0/LICENSE +67 -0
  18. data/unicorn-6.1.0/Links +58 -0
  19. data/unicorn-6.1.0/NEWS +2890 -0
  20. data/unicorn-6.1.0/PHILOSOPHY +139 -0
  21. data/unicorn-6.1.0/README +151 -0
  22. data/unicorn-6.1.0/Rakefile +16 -0
  23. data/unicorn-6.1.0/SIGNALS +123 -0
  24. data/unicorn-6.1.0/Sandbox +104 -0
  25. data/unicorn-6.1.0/TODO +3 -0
  26. data/unicorn-6.1.0/TUNING +119 -0
  27. data/unicorn-6.1.0/archive/slrnpull.conf +4 -0
  28. data/unicorn-6.1.0/bin/unicorn +128 -0
  29. data/unicorn-6.1.0/bin/unicorn_rails +209 -0
  30. data/unicorn-6.1.0/examples/big_app_gc.rb +2 -0
  31. data/unicorn-6.1.0/examples/echo.ru +27 -0
  32. data/unicorn-6.1.0/examples/init.sh +102 -0
  33. data/unicorn-6.1.0/examples/logger_mp_safe.rb +25 -0
  34. data/unicorn-6.1.0/examples/logrotate.conf +44 -0
  35. data/unicorn-6.1.0/examples/nginx.conf +156 -0
  36. data/unicorn-6.1.0/examples/unicorn.conf.minimal.rb +13 -0
  37. data/unicorn-6.1.0/examples/unicorn.conf.rb +110 -0
  38. data/unicorn-6.1.0/examples/unicorn.socket +11 -0
  39. data/unicorn-6.1.0/examples/unicorn@.service +40 -0
  40. data/unicorn-6.1.0/ext/unicorn_http/CFLAGS +13 -0
  41. data/unicorn-6.1.0/ext/unicorn_http/c_util.h +116 -0
  42. data/unicorn-6.1.0/ext/unicorn_http/common_field_optimization.h +128 -0
  43. data/unicorn-6.1.0/ext/unicorn_http/epollexclusive.h +124 -0
  44. data/unicorn-6.1.0/ext/unicorn_http/ext_help.h +38 -0
  45. data/unicorn-6.1.0/ext/unicorn_http/extconf.rb +37 -0
  46. data/unicorn-6.1.0/ext/unicorn_http/global_variables.h +97 -0
  47. data/unicorn-6.1.0/ext/unicorn_http/httpdate.c +79 -0
  48. data/unicorn-6.1.0/ext/unicorn_http/unicorn_http.c +4319 -0
  49. data/unicorn-6.1.0/ext/unicorn_http/unicorn_http.rl +1025 -0
  50. data/unicorn-6.1.0/ext/unicorn_http/unicorn_http_common.rl +76 -0
  51. data/unicorn-6.1.0/lib/unicorn/app/old_rails/static.rb +59 -0
  52. data/unicorn-6.1.0/lib/unicorn/app/old_rails.rb +35 -0
  53. data/unicorn-6.1.0/lib/unicorn/cgi_wrapper.rb +147 -0
  54. data/unicorn-6.1.0/lib/unicorn/configurator.rb +743 -0
  55. data/unicorn-6.1.0/lib/unicorn/const.rb +21 -0
  56. data/unicorn-6.1.0/lib/unicorn/http_request.rb +201 -0
  57. data/unicorn-6.1.0/lib/unicorn/http_response.rb +61 -0
  58. data/unicorn-6.1.0/lib/unicorn/http_server.rb +893 -0
  59. data/unicorn-6.1.0/lib/unicorn/launcher.rb +62 -0
  60. data/unicorn-6.1.0/lib/unicorn/oob_gc.rb +81 -0
  61. data/unicorn-6.1.0/lib/unicorn/preread_input.rb +33 -0
  62. data/unicorn-6.1.0/lib/unicorn/select_waiter.rb +6 -0
  63. data/unicorn-6.1.0/lib/unicorn/socket_helper.rb +211 -0
  64. data/unicorn-6.1.0/lib/unicorn/stream_input.rb +147 -0
  65. data/unicorn-6.1.0/lib/unicorn/tee_input.rb +131 -0
  66. data/unicorn-6.1.0/lib/unicorn/tmpio.rb +33 -0
  67. data/unicorn-6.1.0/lib/unicorn/util.rb +90 -0
  68. data/unicorn-6.1.0/lib/unicorn/version.rb +1 -0
  69. data/unicorn-6.1.0/lib/unicorn/worker.rb +165 -0
  70. data/unicorn-6.1.0/lib/unicorn.rb +138 -0
  71. data/unicorn-6.1.0/man/man1/unicorn.1 +222 -0
  72. data/unicorn-6.1.0/man/man1/unicorn_rails.1 +207 -0
  73. data/unicorn-6.1.0/setup.rb +1586 -0
  74. data/unicorn-6.1.0/t/GNUmakefile +5 -0
  75. data/unicorn-6.1.0/t/README +42 -0
  76. data/unicorn-6.1.0/t/bin/content-md5-put +36 -0
  77. data/unicorn-6.1.0/t/bin/sha1sum.rb +17 -0
  78. data/unicorn-6.1.0/t/bin/unused_listen +40 -0
  79. data/unicorn-6.1.0/t/broken-app.ru +12 -0
  80. data/unicorn-6.1.0/t/detach.ru +11 -0
  81. data/unicorn-6.1.0/t/env.ru +3 -0
  82. data/unicorn-6.1.0/t/fails-rack-lint.ru +5 -0
  83. data/unicorn-6.1.0/t/heartbeat-timeout.ru +12 -0
  84. data/unicorn-6.1.0/t/listener_names.ru +4 -0
  85. data/unicorn-6.1.0/t/my-tap-lib.sh +201 -0
  86. data/unicorn-6.1.0/t/oob_gc.ru +20 -0
  87. data/unicorn-6.1.0/t/oob_gc_path.ru +20 -0
  88. data/unicorn-6.1.0/t/pid.ru +3 -0
  89. data/unicorn-6.1.0/t/preread_input.ru +17 -0
  90. data/unicorn-6.1.0/t/rack-input-tests.ru +21 -0
  91. data/unicorn-6.1.0/t/t0000-http-basic.sh +50 -0
  92. data/unicorn-6.1.0/t/t0001-reload-bad-config.sh +53 -0
  93. data/unicorn-6.1.0/t/t0002-config-conflict.sh +49 -0
  94. data/unicorn-6.1.0/t/t0002-parser-error.sh +94 -0
  95. data/unicorn-6.1.0/t/t0003-working_directory.sh +51 -0
  96. data/unicorn-6.1.0/t/t0004-heartbeat-timeout.sh +69 -0
  97. data/unicorn-6.1.0/t/t0004-working_directory_broken.sh +24 -0
  98. data/unicorn-6.1.0/t/t0005-working_directory_app.rb.sh +40 -0
  99. data/unicorn-6.1.0/t/t0006-reopen-logs.sh +83 -0
  100. data/unicorn-6.1.0/t/t0006.ru +13 -0
  101. data/unicorn-6.1.0/t/t0007-working_directory_no_embed_cli.sh +44 -0
  102. data/unicorn-6.1.0/t/t0008-back_out_of_upgrade.sh +110 -0
  103. data/unicorn-6.1.0/t/t0009-broken-app.sh +56 -0
  104. data/unicorn-6.1.0/t/t0009-winch_ttin.sh +59 -0
  105. data/unicorn-6.1.0/t/t0010-reap-logging.sh +55 -0
  106. data/unicorn-6.1.0/t/t0011-active-unix-socket.sh +79 -0
  107. data/unicorn-6.1.0/t/t0012-reload-empty-config.sh +86 -0
  108. data/unicorn-6.1.0/t/t0013-rewindable-input-false.sh +24 -0
  109. data/unicorn-6.1.0/t/t0013.ru +12 -0
  110. data/unicorn-6.1.0/t/t0014-rewindable-input-true.sh +24 -0
  111. data/unicorn-6.1.0/t/t0014.ru +12 -0
  112. data/unicorn-6.1.0/t/t0015-configurator-internals.sh +25 -0
  113. data/unicorn-6.1.0/t/t0018-write-on-close.sh +23 -0
  114. data/unicorn-6.1.0/t/t0019-max_header_len.sh +49 -0
  115. data/unicorn-6.1.0/t/t0020-at_exit-handler.sh +49 -0
  116. data/unicorn-6.1.0/t/t0021-process_detach.sh +29 -0
  117. data/unicorn-6.1.0/t/t0022-listener_names-preload_app.sh +32 -0
  118. data/unicorn-6.1.0/t/t0100-rack-input-tests.sh +124 -0
  119. data/unicorn-6.1.0/t/t0116-client_body_buffer_size.sh +80 -0
  120. data/unicorn-6.1.0/t/t0116.ru +16 -0
  121. data/unicorn-6.1.0/t/t0300-no-default-middleware.sh +20 -0
  122. data/unicorn-6.1.0/t/t0301-no-default-middleware-ignored-in-config.sh +25 -0
  123. data/unicorn-6.1.0/t/t0301.ru +13 -0
  124. data/unicorn-6.1.0/t/t9000-preread-input.sh +48 -0
  125. data/unicorn-6.1.0/t/t9001-oob_gc.sh +47 -0
  126. data/unicorn-6.1.0/t/t9002-oob_gc-path.sh +75 -0
  127. data/unicorn-6.1.0/t/test-lib.sh +129 -0
  128. data/unicorn-6.1.0/t/write-on-close.ru +11 -0
  129. data/unicorn-6.1.0/test/aggregate.rb +15 -0
  130. data/unicorn-6.1.0/test/benchmark/README +60 -0
  131. data/unicorn-6.1.0/test/benchmark/dd.ru +18 -0
  132. data/unicorn-6.1.0/test/benchmark/ddstream.ru +50 -0
  133. data/unicorn-6.1.0/test/benchmark/readinput.ru +40 -0
  134. data/unicorn-6.1.0/test/benchmark/stack.ru +8 -0
  135. data/unicorn-6.1.0/test/benchmark/uconnect.perl +66 -0
  136. data/unicorn-6.1.0/test/exec/README +5 -0
  137. data/unicorn-6.1.0/test/exec/test_exec.rb +1101 -0
  138. data/unicorn-6.1.0/test/test_helper.rb +306 -0
  139. data/unicorn-6.1.0/test/unit/test_ccc.rb +91 -0
  140. data/unicorn-6.1.0/test/unit/test_configurator.rb +175 -0
  141. data/unicorn-6.1.0/test/unit/test_droplet.rb +28 -0
  142. data/unicorn-6.1.0/test/unit/test_http_parser.rb +884 -0
  143. data/unicorn-6.1.0/test/unit/test_http_parser_ng.rb +714 -0
  144. data/unicorn-6.1.0/test/unit/test_request.rb +182 -0
  145. data/unicorn-6.1.0/test/unit/test_response.rb +111 -0
  146. data/unicorn-6.1.0/test/unit/test_server.rb +342 -0
  147. data/unicorn-6.1.0/test/unit/test_signals.rb +188 -0
  148. data/unicorn-6.1.0/test/unit/test_socket_helper.rb +201 -0
  149. data/unicorn-6.1.0/test/unit/test_stream_input.rb +203 -0
  150. data/unicorn-6.1.0/test/unit/test_tee_input.rb +304 -0
  151. data/unicorn-6.1.0/test/unit/test_upload.rb +301 -0
  152. data/unicorn-6.1.0/test/unit/test_util.rb +131 -0
  153. data/unicorn-6.1.0/test/unit/test_waiter.rb +34 -0
  154. data/unicorn-6.1.0/unicorn.gemspec +49 -0
  155. data/unicorn-6.1.0/unicorn_1 +1 -0
  156. data/unicorn-6.1.0/unicorn_rails_1 +1 -0
  157. metadata +196 -0
@@ -0,0 +1,13 @@
1
+ # Minimal sample configuration file for Unicorn (not Rack) when used
2
+ # with daemonization (unicorn -D) started in your working directory.
3
+ #
4
+ # See https://yhbt.net/unicorn/Unicorn/Configurator.html for complete
5
+ # documentation.
6
+ # See also https://yhbt.net/unicorn/examples/unicorn.conf.rb for
7
+ # a more verbose configuration using more features.
8
+
9
+ listen 2007 # by default Unicorn listens on port 8080
10
+ worker_processes 2 # this should be >= nr_cpus
11
+ pid "/path/to/app/shared/pids/unicorn.pid"
12
+ stderr_path "/path/to/app/shared/log/unicorn.log"
13
+ stdout_path "/path/to/app/shared/log/unicorn.log"
@@ -0,0 +1,110 @@
1
+ # Sample verbose configuration file for Unicorn (not Rack)
2
+ #
3
+ # This configuration file documents many features of Unicorn
4
+ # that may not be needed for some applications. See
5
+ # https://yhbt.net/unicorn/examples/unicorn.conf.minimal.rb
6
+ # for a much simpler configuration file.
7
+ #
8
+ # See https://yhbt.net/unicorn/Unicorn/Configurator.html for complete
9
+ # documentation.
10
+
11
+ # Use at least one worker per core if you're on a dedicated server,
12
+ # more will usually help for _short_ waits on databases/caches.
13
+ worker_processes 4
14
+
15
+ # Since Unicorn is never exposed to outside clients, it does not need to
16
+ # run on the standard HTTP port (80), there is no reason to start Unicorn
17
+ # as root unless it's from system init scripts.
18
+ # If running the master process as root and the workers as an unprivileged
19
+ # user, do this to switch euid/egid in the workers (also chowns logs):
20
+ # user "unprivileged_user", "unprivileged_group"
21
+
22
+ # Help ensure your application will always spawn in the symlinked
23
+ # "current" directory that Capistrano sets up.
24
+ working_directory "/path/to/app/current" # available in 0.94.0+
25
+
26
+ # listen on both a Unix domain socket and a TCP port,
27
+ # we use a shorter backlog for quicker failover when busy
28
+ listen "/path/to/.unicorn.sock", :backlog => 64
29
+ listen 8080, :tcp_nopush => true
30
+
31
+ # nuke workers after 30 seconds instead of 60 seconds (the default)
32
+ timeout 30
33
+
34
+ # feel free to point this anywhere accessible on the filesystem
35
+ pid "/path/to/app/shared/pids/unicorn.pid"
36
+
37
+ # By default, the Unicorn logger will write to stderr.
38
+ # Additionally, ome applications/frameworks log to stderr or stdout,
39
+ # so prevent them from going to /dev/null when daemonized here:
40
+ stderr_path "/path/to/app/shared/log/unicorn.stderr.log"
41
+ stdout_path "/path/to/app/shared/log/unicorn.stdout.log"
42
+
43
+ # combine Ruby 2.0.0+ with "preload_app true" for memory savings
44
+ preload_app true
45
+
46
+ # Enable this flag to have unicorn test client connections by writing the
47
+ # beginning of the HTTP headers before calling the application. This
48
+ # prevents calling the application for connections that have disconnected
49
+ # while queued. This is only guaranteed to detect clients on the same
50
+ # host unicorn runs on, and unlikely to detect disconnects even on a
51
+ # fast LAN.
52
+ check_client_connection false
53
+
54
+ # local variable to guard against running a hook multiple times
55
+ run_once = true
56
+
57
+ before_fork do |server, worker|
58
+ # the following is highly recomended for Rails + "preload_app true"
59
+ # as there's no need for the master process to hold a connection
60
+ defined?(ActiveRecord::Base) and
61
+ ActiveRecord::Base.connection.disconnect!
62
+
63
+ # Occasionally, it may be necessary to run non-idempotent code in the
64
+ # master before forking. Keep in mind the above disconnect! example
65
+ # is idempotent and does not need a guard.
66
+ if run_once
67
+ # do_something_once_here ...
68
+ run_once = false # prevent from firing again
69
+ end
70
+
71
+ # The following is only recommended for memory/DB-constrained
72
+ # installations. It is not needed if your system can house
73
+ # twice as many worker_processes as you have configured.
74
+ #
75
+ # # This allows a new master process to incrementally
76
+ # # phase out the old master process with SIGTTOU to avoid a
77
+ # # thundering herd (especially in the "preload_app false" case)
78
+ # # when doing a transparent upgrade. The last worker spawned
79
+ # # will then kill off the old master process with a SIGQUIT.
80
+ # old_pid = "#{server.config[:pid]}.oldbin"
81
+ # if old_pid != server.pid
82
+ # begin
83
+ # sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
84
+ # Process.kill(sig, File.read(old_pid).to_i)
85
+ # rescue Errno::ENOENT, Errno::ESRCH
86
+ # end
87
+ # end
88
+ #
89
+ # Throttle the master from forking too quickly by sleeping. Due
90
+ # to the implementation of standard Unix signal handlers, this
91
+ # helps (but does not completely) prevent identical, repeated signals
92
+ # from being lost when the receiving process is busy.
93
+ # sleep 1
94
+ end
95
+
96
+ after_fork do |server, worker|
97
+ # per-process listener ports for debugging/admin/migrations
98
+ # addr = "127.0.0.1:#{9293 + worker.nr}"
99
+ # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
100
+
101
+ # the following is *required* for Rails + "preload_app true",
102
+ defined?(ActiveRecord::Base) and
103
+ ActiveRecord::Base.establish_connection
104
+
105
+ # if preload_app is true, then you may also want to check and
106
+ # restart any other shared sockets/descriptors such as Memcached,
107
+ # and Redis. TokyoCabinet file handles are safe to reuse
108
+ # between any number of forked children (assuming your kernel
109
+ # correctly implements pread()/pwrite() system calls)
110
+ end
@@ -0,0 +1,11 @@
1
+ # ==> /etc/systemd/system/unicorn.socket <==
2
+ [Unit]
3
+ Description = unicorn sockets
4
+
5
+ [Socket]
6
+ ListenStream = 127.0.0.1:8080
7
+ ListenStream = /tmp/path/to/.unicorn.sock
8
+ Service = unicorn@1.service
9
+
10
+ [Install]
11
+ WantedBy = sockets.target
@@ -0,0 +1,40 @@
1
+ # ==> /etc/systemd/system/unicorn@.service <==
2
+ # Since SIGUSR2 upgrades do not work under systemd, this service file
3
+ # allows starting two simultaneous services during upgrade time
4
+ # (e.g. unicorn@1 unicorn@2) with the intention that they take
5
+ # turns running in-between upgrades. This should allow upgrading
6
+ # without downtime.
7
+
8
+ [Unit]
9
+ Description = unicorn Rack application server %i
10
+ Wants = unicorn.socket
11
+ After = unicorn.socket
12
+
13
+ [Service]
14
+ # bundler users must use the "--keep-file-descriptors" switch, here:
15
+ # ExecStart = bundle exec --keep-file-descriptors unicorn -c ...
16
+ ExecStart = /usr/bin/unicorn -c /path/to/unicorn.conf.rb /path/to/config.ru
17
+
18
+ # NonBlocking MUST be true if using socket activation with unicorn.
19
+ # Otherwise, there's a small window in-between when the non-blocking
20
+ # flag is set by us and our accept4 call where systemd can momentarily
21
+ # make the socket blocking, causing us to block on accept4:
22
+ NonBlocking = true
23
+ Sockets = unicorn.socket
24
+
25
+ KillSignal = SIGQUIT
26
+ User = nobody
27
+ Group = nogroup
28
+ ExecReload = /bin/kill -HUP $MAINPID
29
+
30
+ # This is based on the Unicorn::Configurator#timeout directive,
31
+ # adding a few seconds for scheduling differences:
32
+ TimeoutStopSec = 62
33
+
34
+ # Only kill the master process, it may be harmful to signal
35
+ # workers via default "control-group" setting since some
36
+ # Ruby extensions and applications misbehave on interrupts
37
+ KillMode = process
38
+
39
+ [Install]
40
+ WantedBy = multi-user.target
@@ -0,0 +1,13 @@
1
+ # CFLAGS used for development (gcc-dependent)
2
+ # source this file if you want/need them
3
+ CFLAGS=
4
+ CFLAGS="$CFLAGS -Wall"
5
+ CFLAGS="$CFLAGS -Wwrite-strings"
6
+ CFLAGS="$CFLAGS -Wdeclaration-after-statement"
7
+ CFLAGS="$CFLAGS -Wcast-qual"
8
+ CFLAGS="$CFLAGS -Wstrict-prototypes"
9
+ CFLAGS="$CFLAGS -Wshadow"
10
+ CFLAGS="$CFLAGS -Wextra"
11
+ CFLAGS="$CFLAGS -Wno-deprecated-declarations"
12
+ CFLAGS="$CFLAGS -Waggregate-return"
13
+ CFLAGS="$CFLAGS -Wchar-subscripts"
@@ -0,0 +1,116 @@
1
+ /*
2
+ * Generic C functions and macros go here, there are no dependencies
3
+ * on Unicorn internal structures or the Ruby C API in here.
4
+ */
5
+
6
+ #ifndef UH_util_h
7
+ #define UH_util_h
8
+
9
+ #include <unistd.h>
10
+ #include <assert.h>
11
+ #include <limits.h>
12
+
13
+ #define MIN(a,b) (a < b ? a : b)
14
+ #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
15
+
16
+ #if SIZEOF_OFF_T == SIZEOF_INT
17
+ # define UH_OFF_T_MAX INT_MAX
18
+ #elif SIZEOF_OFF_T == SIZEOF_LONG_LONG
19
+ # define UH_OFF_T_MAX LLONG_MAX
20
+ #else
21
+ # error off_t size unknown for this platform!
22
+ #endif /* SIZEOF_OFF_T check */
23
+
24
+ /*
25
+ * ragel enforces fpc as a const, and merely casting can make picky
26
+ * compilers unhappy, so we have this little helper do our dirty work
27
+ */
28
+ static inline void *deconst(const void *in)
29
+ {
30
+ union { const void *in; void *out; } tmp;
31
+
32
+ tmp.in = in;
33
+
34
+ return tmp.out;
35
+ }
36
+
37
+ /*
38
+ * capitalizes all lower-case ASCII characters and converts dashes
39
+ * to underscores for HTTP headers. Locale-agnostic.
40
+ */
41
+ static void snake_upcase_char(char *c)
42
+ {
43
+ if (*c >= 'a' && *c <= 'z')
44
+ *c &= ~0x20;
45
+ else if (*c == '-')
46
+ *c = '_';
47
+ }
48
+
49
+ /* Downcases a single ASCII character. Locale-agnostic. */
50
+ static void downcase_char(char *c)
51
+ {
52
+ if (*c >= 'A' && *c <= 'Z')
53
+ *c |= 0x20;
54
+ }
55
+
56
+ static int hexchar2int(int xdigit)
57
+ {
58
+ if (xdigit >= 'A' && xdigit <= 'F')
59
+ return xdigit - 'A' + 10;
60
+ if (xdigit >= 'a' && xdigit <= 'f')
61
+ return xdigit - 'a' + 10;
62
+
63
+ /* Ragel already does runtime range checking for us in Unicorn: */
64
+ assert(xdigit >= '0' && xdigit <= '9' && "invalid digit character");
65
+
66
+ return xdigit - '0';
67
+ }
68
+
69
+ /*
70
+ * multiplies +i+ by +base+ and increments the result by the parsed
71
+ * integer value of +xdigit+. +xdigit+ is a character byte
72
+ * representing a number the range of 0..(base-1)
73
+ * returns the new value of +i+ on success
74
+ * returns -1 on errors (including overflow)
75
+ */
76
+ static off_t step_incr(off_t i, int xdigit, const int base)
77
+ {
78
+ static const off_t max = UH_OFF_T_MAX;
79
+ const off_t next_max = (max - (max % base)) / base;
80
+ off_t offset = hexchar2int(xdigit);
81
+
82
+ if (offset > (base - 1))
83
+ return -1;
84
+ if (i > next_max)
85
+ return -1;
86
+ i *= base;
87
+
88
+ if ((offset > (base - 1)) || ((max - i) < offset))
89
+ return -1;
90
+
91
+ return i + offset;
92
+ }
93
+
94
+ /*
95
+ * parses a non-negative length according to base-10 and
96
+ * returns it as an off_t value. Returns -1 on errors
97
+ * (including overflow).
98
+ */
99
+ static off_t parse_length(const char *value, size_t length)
100
+ {
101
+ off_t rv;
102
+
103
+ for (rv = 0; length-- && rv >= 0; ++value) {
104
+ if (*value >= '0' && *value <= '9')
105
+ rv = step_incr(rv, *value, 10);
106
+ else
107
+ return -1;
108
+ }
109
+
110
+ return rv;
111
+ }
112
+
113
+ #define CONST_MEM_EQ(const_p, buf, len) \
114
+ ((sizeof(const_p) - 1) == len && !memcmp(const_p, buf, sizeof(const_p) - 1))
115
+
116
+ #endif /* UH_util_h */
@@ -0,0 +1,128 @@
1
+ #ifndef common_field_optimization
2
+ #define common_field_optimization
3
+ #include "ruby.h"
4
+ #include "c_util.h"
5
+
6
+ struct common_field {
7
+ const signed long len;
8
+ const char *name;
9
+ VALUE value;
10
+ };
11
+
12
+ /*
13
+ * A list of common HTTP headers we expect to receive.
14
+ * This allows us to avoid repeatedly creating identical string
15
+ * objects to be used with rb_hash_aset().
16
+ */
17
+ static struct common_field common_http_fields[] = {
18
+ # define f(N) { (sizeof(N) - 1), N, Qnil }
19
+ f("ACCEPT"),
20
+ f("ACCEPT_CHARSET"),
21
+ f("ACCEPT_ENCODING"),
22
+ f("ACCEPT_LANGUAGE"),
23
+ f("ALLOW"),
24
+ f("AUTHORIZATION"),
25
+ f("CACHE_CONTROL"),
26
+ f("CONNECTION"),
27
+ f("CONTENT_ENCODING"),
28
+ f("CONTENT_LENGTH"),
29
+ f("CONTENT_TYPE"),
30
+ f("COOKIE"),
31
+ f("DATE"),
32
+ f("EXPECT"),
33
+ f("FROM"),
34
+ f("HOST"),
35
+ f("IF_MATCH"),
36
+ f("IF_MODIFIED_SINCE"),
37
+ f("IF_NONE_MATCH"),
38
+ f("IF_RANGE"),
39
+ f("IF_UNMODIFIED_SINCE"),
40
+ f("KEEP_ALIVE"), /* Firefox sends this */
41
+ f("MAX_FORWARDS"),
42
+ f("PRAGMA"),
43
+ f("PROXY_AUTHORIZATION"),
44
+ f("RANGE"),
45
+ f("REFERER"),
46
+ f("TE"),
47
+ f("TRAILER"),
48
+ f("TRANSFER_ENCODING"),
49
+ f("UPGRADE"),
50
+ f("USER_AGENT"),
51
+ f("VIA"),
52
+ f("X_FORWARDED_FOR"), /* common for proxies */
53
+ f("X_FORWARDED_PROTO"), /* common for proxies */
54
+ f("X_REAL_IP"), /* common for proxies */
55
+ f("WARNING")
56
+ # undef f
57
+ };
58
+
59
+ #define HTTP_PREFIX "HTTP_"
60
+ #define HTTP_PREFIX_LEN (sizeof(HTTP_PREFIX) - 1)
61
+ static ID id_uminus;
62
+
63
+ /* this dedupes under Ruby 2.5+ (December 2017) */
64
+ static VALUE str_dd_freeze(VALUE str)
65
+ {
66
+ if (STR_UMINUS_DEDUPE)
67
+ return rb_funcall(str, id_uminus, 0);
68
+
69
+ /* freeze,since it speeds up older MRI slightly */
70
+ OBJ_FREEZE(str);
71
+ return str;
72
+ }
73
+
74
+ static VALUE str_new_dd_freeze(const char *ptr, long len)
75
+ {
76
+ return str_dd_freeze(rb_str_new(ptr, len));
77
+ }
78
+
79
+ /* this function is not performance-critical, called only at load time */
80
+ static void init_common_fields(void)
81
+ {
82
+ int i;
83
+ struct common_field *cf = common_http_fields;
84
+ char tmp[64];
85
+
86
+ memcpy(tmp, HTTP_PREFIX, HTTP_PREFIX_LEN);
87
+
88
+ for(i = ARRAY_SIZE(common_http_fields); --i >= 0; cf++) {
89
+ /* Rack doesn't like certain headers prefixed with "HTTP_" */
90
+ if (!strcmp("CONTENT_LENGTH", cf->name) ||
91
+ !strcmp("CONTENT_TYPE", cf->name)) {
92
+ cf->value = str_new_dd_freeze(cf->name, cf->len);
93
+ } else {
94
+ memcpy(tmp + HTTP_PREFIX_LEN, cf->name, cf->len + 1);
95
+ cf->value = str_new_dd_freeze(tmp, HTTP_PREFIX_LEN + cf->len);
96
+ }
97
+ rb_gc_register_mark_object(cf->value);
98
+ }
99
+ }
100
+
101
+ /* this function is called for every header set */
102
+ static VALUE find_common_field(const char *field, size_t flen)
103
+ {
104
+ int i;
105
+ struct common_field *cf = common_http_fields;
106
+
107
+ for(i = ARRAY_SIZE(common_http_fields); --i >= 0; cf++) {
108
+ if (cf->len == (long)flen && !memcmp(cf->name, field, flen))
109
+ return cf->value;
110
+ }
111
+ return Qnil;
112
+ }
113
+
114
+ /*
115
+ * We got a strange header that we don't have a memoized value for.
116
+ * Fallback to creating a new string to use as a hash key.
117
+ */
118
+ static VALUE uncommon_field(const char *field, size_t flen)
119
+ {
120
+ VALUE f = rb_str_new(NULL, HTTP_PREFIX_LEN + flen);
121
+ memcpy(RSTRING_PTR(f), HTTP_PREFIX, HTTP_PREFIX_LEN);
122
+ memcpy(RSTRING_PTR(f) + HTTP_PREFIX_LEN, field, flen);
123
+ assert(*(RSTRING_PTR(f) + RSTRING_LEN(f)) == '\0' &&
124
+ "string didn't end with \\0"); /* paranoia */
125
+ return HASH_ASET_DEDUPE ? f : str_dd_freeze(f);
126
+ }
127
+
128
+ #endif /* common_field_optimization_h */
@@ -0,0 +1,124 @@
1
+ /*
2
+ * This is only intended for use inside a unicorn worker, nowhere else.
3
+ * EPOLLEXCLUSIVE somewhat mitigates the thundering herd problem for
4
+ * mostly idle processes since we can't use blocking accept4.
5
+ * This is NOT intended for use with multi-threaded servers, nor
6
+ * single-threaded multi-client ("C10K") servers or anything advanced
7
+ * like that. This use of epoll is only appropriate for a primitive,
8
+ * single-client, single-threaded servers like unicorn that need to
9
+ * support SIGKILL timeouts and parent death detection.
10
+ */
11
+ #if defined(HAVE_EPOLL_CREATE1)
12
+ # include <sys/epoll.h>
13
+ # include <errno.h>
14
+ # include <ruby/io.h>
15
+ # include <ruby/thread.h>
16
+ #endif /* __linux__ */
17
+
18
+ #if defined(EPOLLEXCLUSIVE) && defined(HAVE_EPOLL_CREATE1)
19
+ # define USE_EPOLL (1)
20
+ #else
21
+ # define USE_EPOLL (0)
22
+ #endif
23
+
24
+ #if USE_EPOLL
25
+ /*
26
+ * :nodoc:
27
+ * returns IO object if EPOLLEXCLUSIVE works and arms readers
28
+ */
29
+ static VALUE prep_readers(VALUE cls, VALUE readers)
30
+ {
31
+ long i;
32
+ int epfd = epoll_create1(EPOLL_CLOEXEC);
33
+ VALUE epio;
34
+
35
+ if (epfd < 0) rb_sys_fail("epoll_create1");
36
+
37
+ epio = rb_funcall(cls, rb_intern("for_fd"), 1, INT2NUM(epfd));
38
+
39
+ Check_Type(readers, T_ARRAY);
40
+ for (i = 0; i < RARRAY_LEN(readers); i++) {
41
+ int rc;
42
+ struct epoll_event e;
43
+ rb_io_t *fptr;
44
+ VALUE io = rb_ary_entry(readers, i);
45
+
46
+ e.data.u64 = i; /* the reason readers shouldn't change */
47
+
48
+ /*
49
+ * I wanted to use EPOLLET here, but maintaining our own
50
+ * equivalent of ep->rdllist in Ruby-space doesn't fit
51
+ * our design at all (and the kernel already has it's own
52
+ * code path for doing it). So let the kernel spend
53
+ * cycles on maintaining level-triggering.
54
+ */
55
+ e.events = EPOLLEXCLUSIVE | EPOLLIN;
56
+ io = rb_io_get_io(io);
57
+ GetOpenFile(io, fptr);
58
+ rc = epoll_ctl(epfd, EPOLL_CTL_ADD, fptr->fd, &e);
59
+ if (rc < 0) rb_sys_fail("epoll_ctl");
60
+ }
61
+ return epio;
62
+ }
63
+ #endif /* USE_EPOLL */
64
+
65
+ #if USE_EPOLL
66
+ struct ep_wait {
67
+ struct epoll_event *events;
68
+ rb_io_t *fptr;
69
+ int maxevents;
70
+ int timeout_msec;
71
+ };
72
+
73
+ static void *do_wait(void *ptr) /* runs w/o GVL */
74
+ {
75
+ struct ep_wait *epw = ptr;
76
+
77
+ return (void *)(long)epoll_wait(epw->fptr->fd, epw->events,
78
+ epw->maxevents, epw->timeout_msec);
79
+ }
80
+
81
+ /* :nodoc: */
82
+ /* readers must not change between prepare_readers and get_readers */
83
+ static VALUE
84
+ get_readers(VALUE epio, VALUE ready, VALUE readers, VALUE timeout_msec)
85
+ {
86
+ struct ep_wait epw;
87
+ long i, n;
88
+ VALUE buf;
89
+
90
+ Check_Type(ready, T_ARRAY);
91
+ Check_Type(readers, T_ARRAY);
92
+ epw.maxevents = RARRAY_LENINT(readers);
93
+ buf = rb_str_buf_new(sizeof(struct epoll_event) * epw.maxevents);
94
+ epw.events = (struct epoll_event *)RSTRING_PTR(buf);
95
+ epio = rb_io_get_io(epio);
96
+ GetOpenFile(epio, epw.fptr);
97
+
98
+ epw.timeout_msec = NUM2INT(timeout_msec);
99
+ n = (long)rb_thread_call_without_gvl(do_wait, &epw, RUBY_UBF_IO, NULL);
100
+ if (n < 0) {
101
+ if (errno != EINTR) rb_sys_fail("epoll_wait");
102
+ n = 0;
103
+ }
104
+ /* Linux delivers events in order received */
105
+ for (i = 0; i < n; i++) {
106
+ struct epoll_event *ev = &epw.events[i];
107
+ VALUE obj = rb_ary_entry(readers, ev->data.u64);
108
+
109
+ if (RTEST(obj))
110
+ rb_ary_push(ready, obj);
111
+ }
112
+ rb_str_resize(buf, 0);
113
+ return Qfalse;
114
+ }
115
+ #endif /* USE_EPOLL */
116
+
117
+ static void init_epollexclusive(VALUE mUnicorn)
118
+ {
119
+ #if USE_EPOLL
120
+ VALUE cWaiter = rb_define_class_under(mUnicorn, "Waiter", rb_cIO);
121
+ rb_define_singleton_method(cWaiter, "prep_readers", prep_readers, 1);
122
+ rb_define_method(cWaiter, "get_readers", get_readers, 3);
123
+ #endif
124
+ }
@@ -0,0 +1,38 @@
1
+ #ifndef ext_help_h
2
+ #define ext_help_h
3
+
4
+ /* not all Ruby implementations support frozen objects (Rubinius does not) */
5
+ #if defined(OBJ_FROZEN)
6
+ # define assert_frozen(f) assert(OBJ_FROZEN(f) && "unfrozen object")
7
+ #else
8
+ # define assert_frozen(f) do {} while (0)
9
+ #endif /* !defined(OBJ_FROZEN) */
10
+
11
+ static inline int str_cstr_eq(VALUE val, const char *ptr, long len)
12
+ {
13
+ return (RSTRING_LEN(val) == len && !memcmp(ptr, RSTRING_PTR(val), len));
14
+ }
15
+
16
+ #define STR_CSTR_EQ(val, const_str) \
17
+ str_cstr_eq(val, const_str, sizeof(const_str) - 1)
18
+
19
+ /* strcasecmp isn't locale independent */
20
+ static int str_cstr_case_eq(VALUE val, const char *ptr, long len)
21
+ {
22
+ if (RSTRING_LEN(val) == len) {
23
+ const char *v = RSTRING_PTR(val);
24
+
25
+ for (; len--; ++ptr, ++v) {
26
+ if ((*ptr == *v) || (*v >= 'A' && *v <= 'Z' && (*v | 0x20) == *ptr))
27
+ continue;
28
+ return 0;
29
+ }
30
+ return 1;
31
+ }
32
+ return 0;
33
+ }
34
+
35
+ #define STR_CSTR_CASE_EQ(val, const_str) \
36
+ str_cstr_case_eq(val, const_str, sizeof(const_str) - 1)
37
+
38
+ #endif /* ext_help_h */
@@ -0,0 +1,37 @@
1
+ # -*- encoding: binary -*-
2
+ require 'mkmf'
3
+
4
+ have_func("rb_hash_clear", "ruby.h") or abort 'Ruby 2.0+ required'
5
+
6
+ message('checking if String#-@ (str_uminus) dedupes... ')
7
+ begin
8
+ a = -(%w(t e s t).join)
9
+ b = -(%w(t e s t).join)
10
+ if a.equal?(b)
11
+ $CPPFLAGS += ' -DSTR_UMINUS_DEDUPE=1 '
12
+ message("yes\n")
13
+ else
14
+ $CPPFLAGS += ' -DSTR_UMINUS_DEDUPE=0 '
15
+ message("no, needs Ruby 2.5+\n")
16
+ end
17
+ rescue NoMethodError
18
+ $CPPFLAGS += ' -DSTR_UMINUS_DEDUPE=0 '
19
+ message("no, String#-@ not available\n")
20
+ end
21
+
22
+ message('checking if Hash#[]= (rb_hash_aset) dedupes... ')
23
+ h = {}
24
+ x = {}
25
+ r = rand.to_s
26
+ h[%W(#{r}).join('')] = :foo
27
+ x[%W(#{r}).join('')] = :foo
28
+ if x.keys[0].equal?(h.keys[0])
29
+ $CPPFLAGS += ' -DHASH_ASET_DEDUPE=1 '
30
+ message("yes\n")
31
+ else
32
+ $CPPFLAGS += ' -DHASH_ASET_DEDUPE=0 '
33
+ message("no, needs Ruby 2.6+\n")
34
+ end
35
+
36
+ have_func('epoll_create1', %w(sys/epoll.h))
37
+ create_makefile("unicorn_http")