Hi

Dirlisting is not designed to support event-based working, it is one-shot.

So in a big directory, writev would return EAGAIN (EWOULDBLOCK) after
having written a partial entry.

This would then confuse the client in chunked mode (you promise X bytes but
only send less), which closes the connection, leaving you with a partial 
listing.

With this patch, dirlisting succeeds in a dir with 23k entries.
Without, it fails in a dir with little over 1k entries.


- Lauri
>From 04e544a77ce61ccd9f3aba0c5fd3bd681d845a0f Mon Sep 17 00:00:00 2001
From: Lauri Kasanen <[email protected]>
Date: Sun, 16 Dec 2012 14:55:27 +0200
Subject: [PATCH 6/7] dirlisting: Fix failure in big directories

Dirlisting is not designed to support event-based working, it is one-shot.

So in a big directory, writev would return EAGAIN (EWOULDBLOCK) after
having written a partial entry.

This would then confuse the client in chunked mode (you promise X bytes but
only send less), which closes the connection, leaving you with a partial 
listing.

With this patch, dirlisting succeeds in a dir with 23k entries.
Without, it fails in a dir with little over 1k entries.

Signed-off-by: Lauri Kasanen <[email protected]>
---
 plugins/dirlisting/dirlisting.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/plugins/dirlisting/dirlisting.c b/plugins/dirlisting/dirlisting.c
index b94c34b..e99c251 100644
--- a/plugins/dirlisting/dirlisting.c
+++ b/plugins/dirlisting/dirlisting.c
@@ -30,6 +30,7 @@
  */
 
 #include <dirent.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -820,7 +821,15 @@ int _mkp_stage_30(struct plugin *plugin, struct 
client_session *cs,
         return MK_PLUGIN_RET_NOT_ME;
     }
 
+    // We cannot return to this request later if it fails,
+    // so change to blocking and back.
+
+    fcntl(cs->socket, F_SETFL, fcntl(cs->socket, F_GETFD, 0) & ~O_NONBLOCK);
+
     PLUGIN_TRACE("Dirlisting attending socket %i", cs->socket);
     mk_dirhtml_init(cs, sr);
+
+    mk_api->socket_set_nonblocking(cs->socket);
+
     return MK_PLUGIN_RET_END;
 }
-- 
1.7.2.1

_______________________________________________
Monkey mailing list
[email protected]
http://lists.monkey-project.com/listinfo/monkey

Reply via email to