From 60a9ec94f1f738f881e67f0a881c44c104f07c04 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 6 Nov 2010 10:30:44 +0800 Subject: http_parser: add HttpParser#next? method An easy combination of the existing HttpParser#keepalive? and HttpParser#reset methods, this makes it easier to implement persistence. --- ext/unicorn_http/unicorn_http.rl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ext') diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index fb99f9c..147750a 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -617,6 +617,25 @@ static VALUE HttpParser_keepalive(VALUE self) return HP_FL_ALL(hp, KEEPALIVE) ? Qtrue : Qfalse; } +/** + * call-seq: + * parser.next? => true or false + * + * Exactly like HttpParser#keepalive?, except it will reset the internal + * parser state if it returns true. + */ +static VALUE HttpParser_next(VALUE self) +{ + struct http_parser *hp = data_get(self); + + if (HP_FL_ALL(hp, KEEPALIVE)) { + http_parser_init(hp); + rb_funcall(hp->env, id_clear, 0); + return Qtrue; + } + return Qfalse; +} + /** * call-seq: * parser.headers? => true or false @@ -736,6 +755,7 @@ void Init_unicorn_http(void) rb_define_method(cHttpParser, "body_eof?", HttpParser_body_eof, 0); rb_define_method(cHttpParser, "keepalive?", HttpParser_keepalive, 0); rb_define_method(cHttpParser, "headers?", HttpParser_has_headers, 0); + rb_define_method(cHttpParser, "next?", HttpParser_next, 0); rb_define_method(cHttpParser, "buf", HttpParser_buf, 0); rb_define_method(cHttpParser, "env", HttpParser_env, 0); -- cgit v1.2.3-24-ge0c7