]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_lua: Add r:wspeek for checking if data is available to be read.
authorDaniel Gruno <humbedooh@apache.org>
Thu, 20 Feb 2014 14:46:38 +0000 (14:46 +0000)
committerDaniel Gruno <humbedooh@apache.org>
Thu, 20 Feb 2014 14:46:38 +0000 (14:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1570208 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/mod/mod_lua.xml
modules/lua/lua_request.c

diff --git a/CHANGES b/CHANGES
index b47204e99d79428f830d61063be20a0f3cb269d8..d0bd9d540d78164d147612df3d8741df057935d6 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) mod_lua: Add r:wspeek for checking if there is any data waiting on the line
+     [Daniel Gruno]
+
   *) mod_proxy_wstunnel: Avoid busy loop on client errors, drop message
      IDs 02445, 02446, and 02448 to TRACE1 from DEBUG. PR 56145.
      [Joffroy Christen <joffroy.christen solvaxis com>, Eric Covener]
index 4d26b8c5db91349c3dd7a6bf2f2a4952df276300..3b06d1e563ae1696bf80a792c227607ba89b89cf 100644 (file)
@@ -1023,6 +1023,18 @@ if r:wsupgrade() then
 end
 </highlight>
 
+<highlight language="lua">
+r:wspeek() -- Checks if any data is ready to be read
+
+-- Sleep while nothing is being sent to us...
+while r:wspeek() == false do
+   r.usleep(50000)
+end
+-- We have data ready!
+local line = r:wsread()
+
+</highlight>
+
 </section>
 
 <section id="logging"><title>Logging Functions</title>
index e9af3bd937f8cc2e5d0f98923173e28bf71f7ebf..78bed5b017fbf4b9311df561836c46e61417f702 100644 (file)
@@ -2152,6 +2152,27 @@ static apr_status_t lua_websocket_readbytes(conn_rec* c, char* buffer,
     return rv;
 }
 
+static int lua_websocket_peek(lua_State *L) 
+{
+    apr_status_t rv;
+    apr_bucket_brigade *brigade;
+    
+    request_rec *r = ap_lua_check_request_rec(L, 1);
+    
+    brigade = apr_brigade_create(r->connection->pool, 
+            r->connection->bucket_alloc);
+    rv = ap_get_brigade(r->connection->input_filters, brigade, 
+            AP_MODE_READBYTES, APR_NONBLOCK_READ, 1);
+    if (rv == APR_SUCCESS) {
+        lua_pushboolean(L, 1);
+    }
+    else {
+        lua_pushboolean(L, 0);
+    }
+    apr_brigade_cleanup(brigade);
+    return 1;
+}
+
 static int lua_websocket_read(lua_State *L) 
 {
     apr_socket_t *sock;
@@ -2789,6 +2810,8 @@ void ap_lua_load_request_lmodule(lua_State *L, apr_pool_t *p)
                  makefun(&lua_websocket_greet, APL_REQ_FUNTYPE_LUACFUN, p));
     apr_hash_set(dispatch, "wsread", APR_HASH_KEY_STRING,
                  makefun(&lua_websocket_read, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "wspeek", APR_HASH_KEY_STRING,
+                 makefun(&lua_websocket_peek, APL_REQ_FUNTYPE_LUACFUN, p));
     apr_hash_set(dispatch, "wswrite", APR_HASH_KEY_STRING,
                  makefun(&lua_websocket_write, APL_REQ_FUNTYPE_LUACFUN, p));
     apr_hash_set(dispatch, "wsclose", APR_HASH_KEY_STRING,