From 6bcf6e6d949ee380d95417bf2cb0e4902768008c Mon Sep 17 00:00:00 2001 From: zedshaw Date: Mon, 30 Jan 2006 06:25:20 +0000 Subject: Last and final attempt at improving the Ruby only speed of the IO processing. Future releases will replace Ruby code with C. git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@15 19e92222-5c0b-0410-8929-a290d50e31e9 --- ext/http11/http11.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/http11/http11.c b/ext/http11/http11.c index 3755d65..cbfb55e 100644 --- a/ext/http11/http11.c +++ b/ext/http11/http11.c @@ -152,6 +152,10 @@ VALUE HttpParser_finish(VALUE self) * returning an Integer to indicate how much of the data has been read. No matter * what the return value, you should call HttpParser#finished? and HttpParser#error? * to figure out if it's done parsing or there was an error. + * + * This function now throws an exception when there is a parsing error. This makes + * the logic for working with the parser much easier. You can still test for an + * error, but now you need to wrap the parser with an exception handling block. */ VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data) { @@ -160,8 +164,12 @@ VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data) http->data = (void *)req_hash; http_parser_execute(http, RSTRING(data)->ptr, RSTRING(data)->len); - - return INT2FIX(http_parser_nread(http)); + + if(http_parser_has_error(http)) { + rb_raise(rb_eStandardError, "HTTP Parsing failure"); + } else { + return INT2FIX(http_parser_nread(http)); + } } -- cgit v1.2.3-24-ge0c7