kazeburo / Gazelle

Preforked Plack Handler for performance freaks
https://metacpan.org/release/Gazelle
Other
74 stars 19 forks source link

Fix iovcnt(writev argument) calculation #12

Closed syohex closed 9 years ago

syohex commented 9 years ago

The calculation is wrong after second time loop.

For example, write_data_count=21, IOV_MAX=16

First loop, iovcnt=16(count=16,vec_offset=0) Second loop, iovcnt=0(count=16,vec_offset=16)

writev returns EINVAL if iovcnt is 0.

You can reproduce this issue by setting small value to IOV_MAX.

diff --git a/lib/Plack/Handler/Gazelle.xs b/lib/Plack/Handler/Gazelle.xs
index 5ed3c0c..15d835f 100644
--- a/lib/Plack/Handler/Gazelle.xs
+++ b/lib/Plack/Handler/Gazelle.xs
@@ -54,6 +54,9 @@ extern "C" {
 #define EXPECT_FAILED "HTTP/1.1 417 Expectation Failed\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\nExpectation Failed\r\n"
 #define TOU(ch) (('a' <= ch && ch <= 'z') ? ch - ('a' - 'A') : ch)

+#undef IOV_MAX
+#define IOV_MAX 16
+
 static const char *DoW[] = {
   "Sun","Mon","Tue","Wed","Thu","Fri","Sat"
 };
syohex commented 9 years ago

Tests with Perl 5.12 are failed, however they are passed on my machine with Perl 5.12. Hmm.