1
+ /*
2
+ * Simple webserver for MATLAB Coder
3
+ * Peter Corke August 2018
4
+ */
5
+
1
6
#include <stdio.h>
2
7
#include <string.h>
3
8
//#include <stdlib.h>
@@ -47,6 +52,7 @@ static void postvar_add(char *key, char *value);
47
52
static char * postvar_find (char * key );
48
53
static void postvar_free ();
49
54
void * malloc (); // stdlib.h clashes with microhttpd.h
55
+ void * calloc (size_t count , size_t size );
50
56
void free (void * );
51
57
52
58
int
@@ -58,7 +64,7 @@ post_data_iterator(void *cls, enum MHD_ValueKind kind,
58
64
// Called on every POST variable uploaded
59
65
60
66
// make null terminated heap copy of the value
61
- char * value = (char * )calloc (size + 1 );
67
+ char * value = (char * )calloc (size + 1 , 1 );
62
68
strncpy (value , data , size );
63
69
64
70
// add to the list of POST variables
@@ -295,17 +301,19 @@ void web_setvalue(char *name, char *value)
295
301
}
296
302
297
303
void
298
- web_start (int32_t port , char * callback )
304
+ web_start (int32_t port , char * callback , void * arg )
299
305
{
300
306
if (daemon )
301
307
stl_error ("web server already launched" );
302
308
303
309
request_matlab_callback = stl_get_functionptr (callback );
304
310
if (request_matlab_callback == NULL )
305
- stl_error ("thread named [%s] not found" , callback );
311
+ stl_error ("MATLAB entrypoint named [%s] not found" , callback );
306
312
307
- daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD , port , NULL , NULL ,
308
- & page_request , NULL , MHD_OPTION_END );
313
+ daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD , port ,
314
+ NULL , NULL ,
315
+ & page_request , arg ,
316
+ MHD_OPTION_END );
309
317
310
318
// this starts a POSIX thread but its handle is very well buried
311
319
// its name will be MHD-single but this is not gettable under MacOS
0 commit comments