test-server-status: increase tx size to avoid WRITEABLE loops
[platform/upstream/libwebsockets.git] / test-server / test-server-mirror.c
index a92922f..f0d6111 100644 (file)
@@ -1,28 +1,27 @@
 /*
  * libwebsockets-test-server - libwebsockets test implementation
  *
- * Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
+ * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
  *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation:
- *  version 2.1 of the License.
+ * This file is made available under the Creative Commons CC0 1.0
+ * Universal Public Domain Dedication.
  *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
+ * The person who associated a work with this deed has dedicated
+ * the work to the public domain by waiving all of his or her rights
+ * to the work worldwide under copyright law, including all related
+ * and neighboring rights, to the extent allowed by law. You can copy,
+ * modify, distribute and perform the work, even for commercial purposes,
+ * all without asking permission.
  *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- *  MA  02110-1301  USA
+ * The test apps are intended to be adapted for use in your code, which
+ * may be proprietary.  So unlike the library itself, they are licensed
+ * Public Domain.
  */
 #include "test-server.h"
 
 /* lws-mirror_protocol */
 
-#define MAX_MESSAGE_QUEUE 32
+#define MAX_MESSAGE_QUEUE 512
 
 struct a_message {
        void *payload;
@@ -38,7 +37,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
 {
        struct per_session_data__lws_mirror *pss =
                        (struct per_session_data__lws_mirror *)user;
-       int n;
+       int n, m;
 
        switch (reason) {
 
@@ -59,19 +58,16 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
                if (close_testing)
                        break;
                while (pss->ringbuffer_tail != ringbuffer_head) {
-
+                       m = ringbuffer[pss->ringbuffer_tail].len;
                        n = lws_write(wsi, (unsigned char *)
                                   ringbuffer[pss->ringbuffer_tail].payload +
-                                  LWS_SEND_BUFFER_PRE_PADDING,
-                                  ringbuffer[pss->ringbuffer_tail].len,
-                                                               LWS_WRITE_TEXT);
+                                  LWS_PRE, m, LWS_WRITE_TEXT);
                        if (n < 0) {
                                lwsl_err("ERROR %d writing to mirror socket\n", n);
                                return -1;
                        }
-                       if (n < (int)ringbuffer[pss->ringbuffer_tail].len)
-                               lwsl_err("mirror partial write %d vs %d\n",
-                                      n, ringbuffer[pss->ringbuffer_tail].len);
+                       if (n < m)
+                               lwsl_err("mirror partial write %d vs %d\n", n, m);
 
                        if (pss->ringbuffer_tail == (MAX_MESSAGE_QUEUE - 1))
                                pss->ringbuffer_tail = 0;
@@ -83,8 +79,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
                                lws_rx_flow_allow_all_protocol(lws_get_context(wsi),
                                               lws_get_protocol(wsi));
 
-                       if (lws_partial_buffered(wsi) ||
-                           lws_send_pipe_choked(wsi)) {
+                       if (lws_send_pipe_choked(wsi)) {
                                lws_callback_on_writable(wsi);
                                break;
                        }
@@ -101,11 +96,10 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
                if (ringbuffer[ringbuffer_head].payload)
                        free(ringbuffer[ringbuffer_head].payload);
 
-               ringbuffer[ringbuffer_head].payload =
-                               malloc(LWS_SEND_BUFFER_PRE_PADDING + len);
+               ringbuffer[ringbuffer_head].payload = malloc(LWS_PRE + len);
                ringbuffer[ringbuffer_head].len = len;
                memcpy((char *)ringbuffer[ringbuffer_head].payload +
-                                         LWS_SEND_BUFFER_PRE_PADDING, in, len);
+                      LWS_PRE, in, len);
                if (ringbuffer_head == (MAX_MESSAGE_QUEUE - 1))
                        ringbuffer_head = 0;
                else