pitchfork 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.git-blame-ignore-revs +3 -0
- data/.gitattributes +5 -0
- data/.github/workflows/ci.yml +30 -0
- data/.gitignore +23 -0
- data/COPYING +674 -0
- data/Dockerfile +4 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +30 -0
- data/LICENSE +67 -0
- data/README.md +123 -0
- data/Rakefile +72 -0
- data/docs/Application_Timeouts.md +74 -0
- data/docs/CONFIGURATION.md +388 -0
- data/docs/DESIGN.md +86 -0
- data/docs/FORK_SAFETY.md +80 -0
- data/docs/PHILOSOPHY.md +90 -0
- data/docs/REFORKING.md +113 -0
- data/docs/SIGNALS.md +38 -0
- data/docs/TUNING.md +106 -0
- data/examples/constant_caches.ru +43 -0
- data/examples/echo.ru +25 -0
- data/examples/hello.ru +5 -0
- data/examples/nginx.conf +156 -0
- data/examples/pitchfork.conf.minimal.rb +5 -0
- data/examples/pitchfork.conf.rb +77 -0
- data/examples/unicorn.socket +11 -0
- data/exe/pitchfork +116 -0
- data/ext/pitchfork_http/CFLAGS +13 -0
- data/ext/pitchfork_http/c_util.h +116 -0
- data/ext/pitchfork_http/child_subreaper.h +25 -0
- data/ext/pitchfork_http/common_field_optimization.h +130 -0
- data/ext/pitchfork_http/epollexclusive.h +124 -0
- data/ext/pitchfork_http/ext_help.h +38 -0
- data/ext/pitchfork_http/extconf.rb +14 -0
- data/ext/pitchfork_http/global_variables.h +97 -0
- data/ext/pitchfork_http/httpdate.c +79 -0
- data/ext/pitchfork_http/pitchfork_http.c +4318 -0
- data/ext/pitchfork_http/pitchfork_http.rl +1024 -0
- data/ext/pitchfork_http/pitchfork_http_common.rl +76 -0
- data/lib/pitchfork/app/old_rails/static.rb +59 -0
- data/lib/pitchfork/children.rb +124 -0
- data/lib/pitchfork/configurator.rb +314 -0
- data/lib/pitchfork/const.rb +23 -0
- data/lib/pitchfork/http_parser.rb +206 -0
- data/lib/pitchfork/http_response.rb +63 -0
- data/lib/pitchfork/http_server.rb +822 -0
- data/lib/pitchfork/launcher.rb +9 -0
- data/lib/pitchfork/mem_info.rb +36 -0
- data/lib/pitchfork/message.rb +130 -0
- data/lib/pitchfork/mold_selector.rb +29 -0
- data/lib/pitchfork/preread_input.rb +33 -0
- data/lib/pitchfork/refork_condition.rb +21 -0
- data/lib/pitchfork/select_waiter.rb +9 -0
- data/lib/pitchfork/socket_helper.rb +199 -0
- data/lib/pitchfork/stream_input.rb +152 -0
- data/lib/pitchfork/tee_input.rb +133 -0
- data/lib/pitchfork/tmpio.rb +35 -0
- data/lib/pitchfork/version.rb +8 -0
- data/lib/pitchfork/worker.rb +244 -0
- data/lib/pitchfork.rb +158 -0
- data/pitchfork.gemspec +30 -0
- 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
|
+
}
|