use context service buf in place of large stack arrays 29/3029/1
authorAndy Green <andy.green@linaro.org>
Fri, 8 Feb 2013 05:01:02 +0000 (13:01 +0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 7 Mar 2013 21:01:32 +0000 (13:01 -0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/libwebsockets.c

index 2ae6b56..131e5e7 100644 (file)
@@ -719,8 +719,6 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
        int n;
        int m;
        struct timeval tv;
-       unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 1 +
-                        MAX_USER_RX_BUFFER + LWS_SEND_BUFFER_POST_PADDING];
 #ifdef LWS_OPENSSL_SUPPORT
        char ssl_err_buf[512];
 #endif
@@ -856,15 +854,19 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
 #ifdef LWS_OPENSSL_SUPPORT
 read_pending:
                if (wsi->ssl) {
-                       eff_buf.token_len = SSL_read(wsi->ssl, buf, sizeof buf);
+                       eff_buf.token_len = SSL_read(wsi->ssl,
+                                       context->service_buffer,
+                                               sizeof context->service_buffer);
                        if (!eff_buf.token_len) {
                                n = SSL_get_error(wsi->ssl, eff_buf.token_len);
-                               lwsl_err("SSL_read returned 0 with reason %s\n", ERR_error_string(n, ssl_err_buf));
+                               lwsl_err("SSL_read returned 0 with reason %s\n",
+                                             ERR_error_string(n, ssl_err_buf));
                        }
                } else
 #endif
-                       eff_buf.token_len =
-                                          recv(pollfd->fd, buf, sizeof buf, 0);
+                       eff_buf.token_len = recv(pollfd->fd,
+                                       context->service_buffer,
+                                            sizeof context->service_buffer, 0);
 
                if (eff_buf.token_len < 0) {
                        lwsl_debug("Socket read returned %d\n",
@@ -893,7 +895,7 @@ read_pending:
                 * used then so it is efficient.
                 */
 
-               eff_buf.token = (char *)buf;
+               eff_buf.token = (char *)context->service_buffer;
 #ifndef LWS_NO_EXTENSIONS
                more = 1;
                while (more) {