From 568ae1dcf4d80594e2bd7e6e32cf4ef68a6b37f5 Mon Sep 17 00:00:00 2001 From: Markus Gutschke Date: Sat, 2 Oct 2010 23:40:24 +0000 Subject: [PATCH] The server could sometimes end up listening for events even though it was not really interested in them. This could result in inefficient I/O behavior and most noticably it broke the ability to interrupt long running output with CTRL-C. --- config.h | 2 +- configure | 2 +- configure.ac | 2 +- demo/vt100.js | 2 +- libhttp/http.h | 2 +- libhttp/httpconnection.c | 2 +- libhttp/server.c | 9 ++++----- libhttp/server.h | 2 +- shellinabox/shell_in_a_box.js | 2 +- shellinabox/shellinaboxd.c | 11 ++++++----- shellinabox/vt100.js | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/config.h b/config.h index 755a94b..cbea12a 100644 --- a/config.h +++ b/config.h @@ -174,7 +174,7 @@ #define STDC_HEADERS 1 /* Most recent revision number in the version control system */ -#define VCS_REVISION "237" +#define VCS_REVISION "238" /* Version number of package */ #define VERSION "2.10" diff --git a/configure b/configure index fcdca25..b449c85 100755 --- a/configure +++ b/configure @@ -2328,7 +2328,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -VCS_REVISION=237 +VCS_REVISION=238 cat >>confdefs.h <<_ACEOF diff --git a/configure.ac b/configure.ac index 04a9552..b8d05bb 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ(2.57) dnl This is the one location where the authoritative version number is stored AC_INIT(shellinabox, 2.10, markus@shellinabox.com) -VCS_REVISION=237 +VCS_REVISION=238 AC_SUBST(VCS_REVISION) AC_DEFINE_UNQUOTED(VCS_REVISION, "${VCS_REVISION}", [Most recent revision number in the version control system]) diff --git a/demo/vt100.js b/demo/vt100.js index 5f1ee93..f76687c 100644 --- a/demo/vt100.js +++ b/demo/vt100.js @@ -2402,7 +2402,7 @@ VT100.prototype.toggleCursorBlinking = function() { }; VT100.prototype.about = function() { - alert("VT100 Terminal Emulator " + "2.10 (revision 237)" + + alert("VT100 Terminal Emulator " + "2.10 (revision 238)" + "\nCopyright 2008-2010 by Markus Gutschke\n" + "For more information check http://shellinabox.com"); }; diff --git a/libhttp/http.h b/libhttp/http.h index cec2fe0..07e235d 100644 --- a/libhttp/http.h +++ b/libhttp/http.h @@ -98,7 +98,7 @@ time_t serverGetTimeout(ServerConnection *connection); ServerConnection *serverGetConnection(Server *server, ServerConnection *hint, int fd); short serverConnectionSetEvents(Server *server, ServerConnection *connection, - short events); + int fd, short events); void serverExitLoop(Server *server, int exitAll); void serverLoop(Server *server); int serverSupportsSSL(); diff --git a/libhttp/httpconnection.c b/libhttp/httpconnection.c index fc42558..a19ac3f 100644 --- a/libhttp/httpconnection.c +++ b/libhttp/httpconnection.c @@ -768,7 +768,7 @@ void httpTransfer(struct HttpConnection *http, char *msg, int len) { if (!serverGetTimeout(connection)) { serverSetTimeout(connection, CONNECTION_TIMEOUT); } - serverConnectionSetEvents(http->server, connection, + serverConnectionSetEvents(http->server, connection, http->fd, http->msgLength ? POLLIN|POLLOUT : POLLIN); } } diff --git a/libhttp/server.c b/libhttp/server.c index b7e2d03..58ef949 100644 --- a/libhttp/server.c +++ b/libhttp/server.c @@ -453,7 +453,7 @@ struct ServerConnection *serverGetConnection(struct Server *server, } short serverConnectionSetEvents(struct Server *server, - struct ServerConnection *connection, + struct ServerConnection *connection, int fd, short events) { dcheck(server); dcheck(connection); @@ -463,6 +463,7 @@ short serverConnectionSetEvents(struct Server *server, dcheck(!connection->deleted); int idx = connection - server->connections; short oldEvents = server->pollFds[idx + 1].events; + dcheck(fd == server->pollFds[idx + 1].fd); server->pollFds[idx + 1].events = events; return oldEvents; } @@ -582,14 +583,12 @@ void serverLoop(struct Server *server) { if (server->pollFds[i].revents) { eventCount--; } - short events = server->pollFds[i].events; if (!connection->handleConnection(connection, connection->arg, - &events, server->pollFds[i].revents)){ + &server->pollFds[i].events, + server->pollFds[i].revents)) { connection = server->connections + i - 1; connection->destroyConnection(connection->arg); connection->deleted = 1; - } else { - server->pollFds[i].events = events; } } } diff --git a/libhttp/server.h b/libhttp/server.h index 8d3141f..8900d99 100644 --- a/libhttp/server.h +++ b/libhttp/server.h @@ -109,7 +109,7 @@ struct ServerConnection *serverGetConnection(struct Server *server, struct ServerConnection *hint, int fd); short serverConnectionSetEvents(struct Server *server, - struct ServerConnection *connection, + struct ServerConnection *connection, int fd, short events); void serverExitLoop(struct Server *server, int exitAll); void serverLoop(struct Server *server); diff --git a/shellinabox/shell_in_a_box.js b/shellinabox/shell_in_a_box.js index 6a90cbf..244384e 100644 --- a/shellinabox/shell_in_a_box.js +++ b/shellinabox/shell_in_a_box.js @@ -358,7 +358,7 @@ ShellInABox.prototype.extendContextMenu = function(entries, actions) { }; ShellInABox.prototype.about = function() { - alert("Shell In A Box version " + "2.10 (revision 237)" + + alert("Shell In A Box version " + "2.10 (revision 238)" + "\nCopyright 2008-2010 by Markus Gutschke\n" + "For more information check http://shellinabox.com" + (typeof serverSupportsSSL != 'undefined' && serverSupportsSSL ? diff --git a/shellinabox/shellinaboxd.c b/shellinabox/shellinaboxd.c index 1716129..f508c66 100644 --- a/shellinabox/shellinaboxd.c +++ b/shellinabox/shellinaboxd.c @@ -282,8 +282,7 @@ static void sessionDone(void *arg) { } static int handleSession(struct ServerConnection *connection, void *arg, - short *events ATTR_UNUSED, short revents) { - UNUSED(events); + short *events, short revents) { struct Session *session = (struct Session *)arg; session->connection = connection; int len = MAX_RESPONSE - session->len; @@ -311,7 +310,7 @@ static int handleSession(struct ServerConnection *connection, void *arg, session->pty); session->connection = connection; if (session->len >= MAX_RESPONSE) { - serverConnectionSetEvents(session->server, connection, 0); + *events = 0; } serverSetTimeout(connection, AJAX_TIMEOUT); return 1; @@ -460,13 +459,15 @@ static int dataHandler(HttpConnection *http, struct Service *service, serverSetTimeout(session->connection, AJAX_TIMEOUT); if (session->len < MAX_RESPONSE) { // Re-enable input on the child's pty - serverConnectionSetEvents(session->server, session->connection,POLLIN); + serverConnectionSetEvents(session->server, session->connection, + session->pty, POLLIN); } } return HTTP_DONE; } else if (session->connection) { // Re-enable input on the child's pty - serverConnectionSetEvents(session->server, session->connection, POLLIN); + serverConnectionSetEvents(session->server, session->connection, + session->pty, POLLIN); serverSetTimeout(session->connection, AJAX_TIMEOUT); } diff --git a/shellinabox/vt100.js b/shellinabox/vt100.js index 5f1ee93..f76687c 100644 --- a/shellinabox/vt100.js +++ b/shellinabox/vt100.js @@ -2402,7 +2402,7 @@ VT100.prototype.toggleCursorBlinking = function() { }; VT100.prototype.about = function() { - alert("VT100 Terminal Emulator " + "2.10 (revision 237)" + + alert("VT100 Terminal Emulator " + "2.10 (revision 238)" + "\nCopyright 2008-2010 by Markus Gutschke\n" + "For more information check http://shellinabox.com"); }; -- 2.45.1