BUG/MINOR: lua: sockets receive behavior doesn't follows the specs
Specs says that the receive() function with an argument "*l"
must return a line without the final "\n" ( or without "\r\n").
This patch removes these two final bytes.
diff --git a/src/hlua.c b/src/hlua.c
index 260646b..564f5ba 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -1169,6 +1169,7 @@
int len1;
char *blk2;
int len2;
+ int skip_at_end = 0;
/* Check if this lua stack is schedulable. */
if (!hlua || !hlua->task)
@@ -1187,6 +1188,28 @@
goto connection_closed;
if (nblk == 0) /* No data avalaible. */
goto connection_empty;
+
+ /* remove final \r\n. */
+ if (nblk == 1) {
+ if (blk1[len1-1] == '\n') {
+ len1--;
+ skip_at_end++;
+ if (blk1[len1-1] == '\r') {
+ len1--;
+ skip_at_end++;
+ }
+ }
+ }
+ else {
+ if (blk2[len2-1] == '\n') {
+ len2--;
+ skip_at_end++;
+ if (blk2[len2-1] == '\r') {
+ len2--;
+ skip_at_end++;
+ }
+ }
+ }
}
else if (wanted == HLSR_READ_ALL) {
@@ -1224,7 +1247,7 @@
}
/* Consume data. */
- bo_skip(socket->s->si[0].ob, len);
+ bo_skip(socket->s->si[0].ob, len + skip_at_end);
/* Don't wait anything. */
si_update(&socket->s->si[0]);