|
|
@@ -17,59 +17,63 @@
|
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
*/
|
|
|
-
|
|
|
/**
|
|
|
* @file test_callback.c
|
|
|
* @brief Testcase for MHD not calling the callback too often
|
|
|
- * @author Jan Seeger
|
|
|
+ * @author Jan Seeger
|
|
|
* @author Christian Grothoff
|
|
|
*/
|
|
|
-
|
|
|
-
|
|
|
#include "MHD_config.h"
|
|
|
#include "platform.h"
|
|
|
#include <curl/curl.h>
|
|
|
#include <microhttpd.h>
|
|
|
|
|
|
-struct callback_closure {
|
|
|
+struct callback_closure
|
|
|
+{
|
|
|
unsigned int called;
|
|
|
};
|
|
|
|
|
|
|
|
|
-static ssize_t
|
|
|
-called_twice(void *cls, uint64_t pos, char *buf, size_t max)
|
|
|
+static ssize_t
|
|
|
+called_twice(void *cls, uint64_t pos, char *buf, size_t max)
|
|
|
{
|
|
|
struct callback_closure *cls2 = cls;
|
|
|
-
|
|
|
- if (cls2->called == 0)
|
|
|
+
|
|
|
+ if (cls2->called == 0)
|
|
|
{
|
|
|
memset(buf, 0, max);
|
|
|
strcat(buf, "test");
|
|
|
cls2->called = 1;
|
|
|
return strlen(buf);
|
|
|
}
|
|
|
- if (cls2->called == 1)
|
|
|
+ if (cls2->called == 1)
|
|
|
{
|
|
|
cls2->called = 2;
|
|
|
return MHD_CONTENT_READER_END_OF_STREAM;
|
|
|
}
|
|
|
- fprintf(stderr,
|
|
|
+ fprintf(stderr,
|
|
|
"Handler called after returning END_OF_STREAM!\n");
|
|
|
return MHD_CONTENT_READER_END_WITH_ERROR;
|
|
|
}
|
|
|
|
|
|
|
|
|
static int
|
|
|
-callback(void *cls, struct MHD_Connection *connection, const char *url,
|
|
|
- const char *method, const char *version, const char *upload_data,
|
|
|
- size_t *upload_data_size, void **con_cls) {
|
|
|
+callback(void *cls,
|
|
|
+ struct MHD_Connection *connection,
|
|
|
+ const char *url,
|
|
|
+ const char *method,
|
|
|
+ const char *version,
|
|
|
+ const char *upload_data,
|
|
|
+ size_t *upload_data_size,
|
|
|
+ void **con_cls)
|
|
|
+{
|
|
|
struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure));
|
|
|
struct MHD_Response *r;
|
|
|
|
|
|
- r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024,
|
|
|
- &called_twice, cbc,
|
|
|
+ r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024,
|
|
|
+ &called_twice, cbc,
|
|
|
&free);
|
|
|
- MHD_queue_response(connection, 200, r);
|
|
|
+ MHD_queue_response(connection, MHD_HTTP_OK, r);
|
|
|
MHD_destroy_response(r);
|
|
|
return MHD_YES;
|
|
|
}
|
|
|
@@ -82,7 +86,8 @@ discard_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
|
|
|
}
|
|
|
|
|
|
|
|
|
-int main(int argc, char **argv)
|
|
|
+int
|
|
|
+main(int argc, char **argv)
|
|
|
{
|
|
|
struct MHD_Daemon *d;
|
|
|
fd_set rs;
|
|
|
@@ -97,11 +102,11 @@ int main(int argc, char **argv)
|
|
|
struct timeval tv;
|
|
|
int extra;
|
|
|
|
|
|
- d = MHD_start_daemon(0,
|
|
|
+ d = MHD_start_daemon(0,
|
|
|
8000,
|
|
|
NULL,
|
|
|
NULL,
|
|
|
- callback,
|
|
|
+ &callback,
|
|
|
NULL,
|
|
|
MHD_OPTION_END);
|
|
|
c = curl_easy_init ();
|
|
|
@@ -145,7 +150,7 @@ int main(int argc, char **argv)
|
|
|
curl_easy_cleanup (c);
|
|
|
MHD_stop_daemon (d);
|
|
|
return 3;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
if (MHD_YES !=
|
|
|
MHD_get_fdset(d, &rs, &ws, &es, &max))
|