pitchfork 0.1.0

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.

Potentially problematic release.


This version of pitchfork might be problematic. Click here for more details.

Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.git-blame-ignore-revs +3 -0
  3. data/.gitattributes +5 -0
  4. data/.github/workflows/ci.yml +30 -0
  5. data/.gitignore +23 -0
  6. data/COPYING +674 -0
  7. data/Dockerfile +4 -0
  8. data/Gemfile +9 -0
  9. data/Gemfile.lock +30 -0
  10. data/LICENSE +67 -0
  11. data/README.md +123 -0
  12. data/Rakefile +72 -0
  13. data/docs/Application_Timeouts.md +74 -0
  14. data/docs/CONFIGURATION.md +388 -0
  15. data/docs/DESIGN.md +86 -0
  16. data/docs/FORK_SAFETY.md +80 -0
  17. data/docs/PHILOSOPHY.md +90 -0
  18. data/docs/REFORKING.md +113 -0
  19. data/docs/SIGNALS.md +38 -0
  20. data/docs/TUNING.md +106 -0
  21. data/examples/constant_caches.ru +43 -0
  22. data/examples/echo.ru +25 -0
  23. data/examples/hello.ru +5 -0
  24. data/examples/nginx.conf +156 -0
  25. data/examples/pitchfork.conf.minimal.rb +5 -0
  26. data/examples/pitchfork.conf.rb +77 -0
  27. data/examples/unicorn.socket +11 -0
  28. data/exe/pitchfork +116 -0
  29. data/ext/pitchfork_http/CFLAGS +13 -0
  30. data/ext/pitchfork_http/c_util.h +116 -0
  31. data/ext/pitchfork_http/child_subreaper.h +25 -0
  32. data/ext/pitchfork_http/common_field_optimization.h +130 -0
  33. data/ext/pitchfork_http/epollexclusive.h +124 -0
  34. data/ext/pitchfork_http/ext_help.h +38 -0
  35. data/ext/pitchfork_http/extconf.rb +14 -0
  36. data/ext/pitchfork_http/global_variables.h +97 -0
  37. data/ext/pitchfork_http/httpdate.c +79 -0
  38. data/ext/pitchfork_http/pitchfork_http.c +4318 -0
  39. data/ext/pitchfork_http/pitchfork_http.rl +1024 -0
  40. data/ext/pitchfork_http/pitchfork_http_common.rl +76 -0
  41. data/lib/pitchfork/app/old_rails/static.rb +59 -0
  42. data/lib/pitchfork/children.rb +124 -0
  43. data/lib/pitchfork/configurator.rb +314 -0
  44. data/lib/pitchfork/const.rb +23 -0
  45. data/lib/pitchfork/http_parser.rb +206 -0
  46. data/lib/pitchfork/http_response.rb +63 -0
  47. data/lib/pitchfork/http_server.rb +822 -0
  48. data/lib/pitchfork/launcher.rb +9 -0
  49. data/lib/pitchfork/mem_info.rb +36 -0
  50. data/lib/pitchfork/message.rb +130 -0
  51. data/lib/pitchfork/mold_selector.rb +29 -0
  52. data/lib/pitchfork/preread_input.rb +33 -0
  53. data/lib/pitchfork/refork_condition.rb +21 -0
  54. data/lib/pitchfork/select_waiter.rb +9 -0
  55. data/lib/pitchfork/socket_helper.rb +199 -0
  56. data/lib/pitchfork/stream_input.rb +152 -0
  57. data/lib/pitchfork/tee_input.rb +133 -0
  58. data/lib/pitchfork/tmpio.rb +35 -0
  59. data/lib/pitchfork/version.rb +8 -0
  60. data/lib/pitchfork/worker.rb +244 -0
  61. data/lib/pitchfork.rb +158 -0
  62. data/pitchfork.gemspec +30 -0
  63. metadata +137 -0
@@ -0,0 +1,79 @@
1
+ #include <ruby.h>
2
+ #include <time.h>
3
+ #include <stdio.h>
4
+
5
+ static const size_t buf_capa = sizeof("Thu, 01 Jan 1970 00:00:00 GMT");
6
+ static VALUE buf;
7
+ static char *buf_ptr;
8
+ static const char week[] = "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat";
9
+ static const char months[] = "Jan\0Feb\0Mar\0Apr\0May\0Jun\0"
10
+ "Jul\0Aug\0Sep\0Oct\0Nov\0Dec";
11
+
12
+ /* for people on wonky systems only */
13
+ #ifndef HAVE_GMTIME_R
14
+ # warning using fake gmtime_r
15
+ static struct tm * my_gmtime_r(time_t *now, struct tm *tm)
16
+ {
17
+ struct tm *global = gmtime(now);
18
+ if (global)
19
+ *tm = *global;
20
+ return tm;
21
+ }
22
+ # define gmtime_r my_gmtime_r
23
+ #endif
24
+
25
+
26
+ /*
27
+ * Returns a string which represents the time as rfc1123-date of HTTP-date
28
+ * defined by RFC 2616:
29
+ *
30
+ * day-of-week, DD month-name CCYY hh:mm:ss GMT
31
+ *
32
+ * Note that the result is always GMT.
33
+ *
34
+ * This method is identical to Time#httpdate in the Ruby standard library,
35
+ * except it is implemented in C for performance. We always saw
36
+ * Time#httpdate at or near the top of the profiler output so we
37
+ * decided to rewrite this in C.
38
+ *
39
+ * Caveats: it relies on a Ruby implementation with the global VM lock,
40
+ * a thread-safe version will be provided when a Unix-only, GVL-free Ruby
41
+ * implementation becomes viable.
42
+ */
43
+ static VALUE httpdate(VALUE self)
44
+ {
45
+ static time_t last;
46
+ time_t now = time(NULL); /* not a syscall on modern 64-bit systems */
47
+ struct tm tm;
48
+
49
+ if (last == now)
50
+ return buf;
51
+ last = now;
52
+ gmtime_r(&now, &tm);
53
+
54
+ /* we can make this thread-safe later if our Ruby loses the GVL */
55
+ snprintf(buf_ptr, buf_capa,
56
+ "%s, %02d %s %4d %02d:%02d:%02d GMT",
57
+ week + (tm.tm_wday * 4),
58
+ tm.tm_mday,
59
+ months + (tm.tm_mon * 4),
60
+ tm.tm_year + 1900,
61
+ tm.tm_hour,
62
+ tm.tm_min,
63
+ tm.tm_sec);
64
+
65
+ return buf;
66
+ }
67
+
68
+ void init_pitchfork_httpdate(void)
69
+ {
70
+ VALUE mod = rb_define_module("Pitchfork");
71
+ mod = rb_define_module_under(mod, "HttpResponse");
72
+
73
+ buf = rb_str_new(0, buf_capa - 1);
74
+ rb_gc_register_mark_object(buf);
75
+ buf_ptr = RSTRING_PTR(buf);
76
+ httpdate(Qnil);
77
+
78
+ rb_define_method(mod, "httpdate", httpdate, 0);
79
+ }