diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-01-21 08:53:55 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-01-21 08:57:01 +0000 |
commit | d3a182dd0238c964ff5191642d53fce3d2e64be9 (patch) | |
tree | 7849641fd6ecdf22f15a82ee1c7653214999ea44 /ext/clogger_ext/clogger.c | |
parent | 0abc76611fe3438dd5b152257f9ba9028c536ed3 (diff) | |
download | clogger-d3a182dd0238c964ff5191642d53fce3d2e64be9.tar.gz |
This optimization is used by Rainbows! to pass IO objects to the response body.
Diffstat (limited to 'ext/clogger_ext/clogger.c')
-rw-r--r-- | ext/clogger_ext/clogger.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index 253339f..94301fc 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -908,6 +908,24 @@ static VALUE to_path(VALUE self) return path; } +/* + * call-seq: + * clogger.to_io + * + * used to proxy +:to_io+ method calls to the wrapped response body. + */ +static VALUE to_io(VALUE self) +{ + struct clogger *c = clogger_get(self); + struct stat sb; + VALUE io = rb_convert_type(c->body, T_FILE, "IO", "to_io"); + + if (fstat(my_fileno(io), &sb) == 0) + c->body_bytes_sent = sb.st_size; + + return io; +} + void Init_clogger_ext(void) { VALUE tmp; @@ -938,6 +956,7 @@ void Init_clogger_ext(void) rb_define_method(cClogger, "wrap_body?", clogger_wrap_body, 0); rb_define_method(cClogger, "reentrant?", clogger_reentrant, 0); rb_define_method(cClogger, "to_path", to_path, 0); + rb_define_method(cClogger, "to_io", to_io, 0); rb_define_method(cClogger, "respond_to?", respond_to, 1); CONST_GLOBAL_STR(REMOTE_ADDR); CONST_GLOBAL_STR(HTTP_X_FORWARDED_FOR); |