[libmicrohttpd] Processing single request with data from heap

2017-06-18 Thread Alex Reynolds
I have some request handler code that sends the contents of a regular file
to the client. However, the issue is that my program must first write a
regular file to the file system, and this is time consuming for very large
files. My program (and the client) must wait for the entire file to be
generated, before my program can go back and read the file to send any data
to the client.

As an addition to the excellent tutorials already available, I'd like to
ask if there could be a tutorial written that demonstrates how to process a
single request for data in chunks, where the source of the data is not a
regular file, but a heap-allocated buffer of some size, which is repeatedly
filled to some content length (up to or smaller than its size) and sent to
the client in asynchronous fashion, until all data are processed.

Regards,
Alex


Re: [libmicrohttpd] Processing single request with data from heap

2017-06-18 Thread Christian Grothoff
MHD_create_response_from_callback() is the API you are looking for.
src/examples/chunked_example.c (and various others) is one example for
how this API is used. Admittedly, it's not in the tutorial (yet), and I
agree it would be good to add it.

On 06/18/2017 10:38 AM, Alex Reynolds wrote:
> I have some request handler code that sends the contents of a regular
> file to the client. However, the issue is that my program must first
> write a regular file to the file system, and this is time consuming for
> very large files. My program (and the client) must wait for the entire
> file to be generated, before my program can go back and read the file to
> send any data to the client.
> 
> As an addition to the excellent tutorials already available, I'd like to
> ask if there could be a tutorial written that demonstrates how to
> process a single request for data in chunks, where the source of the
> data is not a regular file, but a heap-allocated buffer of some size,
> which is repeatedly filled to some content length (up to or smaller than
> its size) and sent to the client in asynchronous fashion, until all data
> are processed.
> 
> Regards,
> Alex



signature.asc
Description: OpenPGP digital signature


[libmicrohttpd] Add 'manywarnings' module from Wget2

2017-06-18 Thread Tim Rühsen
Hi,

maybe you like this...

"Add m4/wget_manywarnings

This enables (if switched on) basically all warnings for gcc and clang.
Exceptions are explicitly controlled in configure.ac.

To enable by default: create a file '.manywarnings'
Enable explicitly : ./configure --enable-manywarnings
Disable explicitly: ./configure --disable-manywarnings

New warnings of new compiler versions are automatically added.
This module works much faster than the 'manywarnings' module from gnulib.

Created for developers and Continuous Integration."

I just added the WARN_FLAGS to src/microhttpd/Makefile.am, but if you like it
add it also to the other Makefile.am.

It might need some further tuning in configure.ac to enable/disable warnings (I
just copied the code from Wget2 were we ignore certain warning).

Regards, Tim
From 71a8648145861cebde04cebf4de8ce10e21b7904 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim Rühsen?= 
Date: Sun, 18 Jun 2017 12:33:08 +0200
Subject: [PATCH] Add m4/wget_manywarnings

This enables (if switched on) basically all warnings for gcc and clang.
Exceptions are explicitly controlled in configure.ac.

To enable by default: create a file '.manywarnings'
Enable explicitly : ./configure --enable-manywarnings
Disable explicitly: ./configure --disable-manywarnings

New warnings of new compiler versions are automatically added.
This module works much faster than the 'manywarnings' module from gnulib.

Created for developers and Continuous Integration.
---
 configure.ac   | 53 
 m4/wget_manywarnings.m4| 88 ++
 src/microhttpd/Makefile.am |  2 +-
 3 files changed, 142 insertions(+), 1 deletion(-)
 create mode 100644 m4/wget_manywarnings.m4

diff --git a/configure.ac b/configure.ac
index 443dcf24..b4b28748 100644
--- a/configure.ac
+++ b/configure.ac
@@ -338,6 +338,59 @@ netbsd*)
 ;;
 esac

+
+# enable all possible compiler warnings in WARN_FLAGS
+#
+# to enable by default: create a file '.manywarnings'
+# enable explicitly : ./configure --enable-manywarnings
+# disable explicitly: ./configure --disable-manywarnings
+wget_MANYWARNINGS(WARN_CFLAGS, C)
+
+if test -n "$WARN_CFLAGS"; then
+  if test "$CCNAME" = "gcc"; then
+# Set up list of unwanted warnings
+nw+nw="$nw -Wsystem-headers"   # System headers may trigger lot's of useless warnings
+nw="$nw -Wvla"  # This project is C99
+nw="$nw -Wstack-protector"
+nw="$nw -Wmissing-field-initializer"
+nw="$nw -Wtraditional"
+nw="$nw -Wtraditional-conversion"
+nw="$nw -Wc++-compat"
+nw="$nw -Wcast-qual"
+nw="$nw -Wconversion"
+nw="$nw -Wsign-conversion"
+nw="$nw -Wunsuffixed-float-constants"
+nw="$nw -Wdeclaration-after-statement" # C89 only, messing up gcc < 5
+if test "$cross_compiling" = yes; then
+  nw="$nw -Wformat"
+fi
+
+# remove unwanted warn flags
+wget_WORD_REMOVE([WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
+
+# add more flags as you like
+WARN_CFLAGS="$WARN_CFLAGS -fdiagnostics-color=always"
+if test "$cross_compiling" = yes; then
+  WARN_CFLAGS="$WARN_CFLAGS -Wno-format"
+fi
+# WARN_CFLAGS="$WARN_CFLAGS -Werror"
+
+  elif test "$CCNAME" = "clang"; then
+# setup flags for this project
+WARN_CFLAGS="$WARN_CFLAGS -Wno-system-headers -Wno-vla -Wno-cast-qual -Wno-padded"
+WARN_CFLAGS="$WARN_CFLAGS -Wno-reserved-id-macro -Wno-sign-conversion  -Wno-disabled-macro-expansion"
+WARN_CFLAGS="$WARN_CFLAGS -Wno-documentation -Wno-documentation-unknown-command"
+WARN_CFLAGS="$WARN_CFLAGS -Wno-covered-switch-default"
+
+# remove all flags from WARN_FLAGS that are already in CFLAGS
+# wget_WORD_REMOVE([WARN_CFLAGS], [$WARN_CFLAGS], [$CFLAGS])
+ fi
+
+  AC_SUBST([WARN_CFLAGS])
+fi
+
+
 AC_ARG_WITH([threads],
[AS_HELP_STRING([--with-threads=LIB],[choose threading library (posix, w32, auto) [auto]])],
[], [with_threads='auto'])
diff --git a/m4/wget_manywarnings.m4 b/m4/wget_manywarnings.m4
new file mode 100644
index ..61033282
--- /dev/null
+++ b/m4/wget_manywarnings.m4
@@ -0,0 +1,88 @@
+# wget_manywarnings.m4 serial 1
+dnl Copyright (C) 2016 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Tim Ruehsen
+
+# wget_WORD_SET(RESULT, SET, WORDS)
+# --
+# Add each word in WORDS to SET if not already there and store in RESULT.
+# Words separated by whitespace.
+AC_DEFUN([wget_WORD_SET], [
+  ret=$2
+  words=" $2 "
+  for word in $3; do
+if test "${words#*" $word "}" = "$words"; then ret="$ret $word"; fi
+  done
+  $1=$ret
+])
+
+# wget_WORD_REMOVE(RESULT, SET, WORDS)
+# --
+# Remove each word in WORDS from SET and store in R