Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3b076ec

Browse filesBrowse files
committed
pass arg to webserver callback
fix bug in calloc cal
1 parent 79d1b5c commit 3b076ec
Copy full SHA for 3b076ec

File tree

2 files changed

+18
-6
lines changed
Filter options

2 files changed

+18
-6
lines changed

‎stl/httpd.c

Copy file name to clipboardExpand all lines: stl/httpd.c
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Simple webserver for MATLAB Coder
3+
* Peter Corke August 2018
4+
*/
5+
16
#include <stdio.h>
27
#include <string.h>
38
//#include <stdlib.h>
@@ -47,6 +52,7 @@ static void postvar_add(char *key, char *value);
4752
static char *postvar_find(char *key);
4853
static void postvar_free();
4954
void *malloc(); // stdlib.h clashes with microhttpd.h
55+
void *calloc(size_t count, size_t size);
5056
void free(void *);
5157

5258
int
@@ -58,7 +64,7 @@ post_data_iterator(void *cls, enum MHD_ValueKind kind,
5864
// Called on every POST variable uploaded
5965

6066
// make null terminated heap copy of the value
61-
char *value = (char *)calloc(size+1);
67+
char *value = (char *)calloc(size+1, 1);
6268
strncpy(value, data, size);
6369

6470
// add to the list of POST variables
@@ -295,17 +301,19 @@ void web_setvalue(char *name, char *value)
295301
}
296302

297303
void
298-
web_start(int32_t port, char *callback)
304+
web_start(int32_t port, char *callback, void *arg)
299305
{
300306
if (daemon)
301307
stl_error("web server already launched");
302308

303309
request_matlab_callback = stl_get_functionptr(callback);
304310
if (request_matlab_callback == NULL)
305-
stl_error("thread named [%s] not found", callback);
311+
stl_error("MATLAB entrypoint named [%s] not found", callback);
306312

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);
309317

310318
// this starts a POSIX thread but its handle is very well buried
311319
// its name will be MHD-single but this is not gettable under MacOS

‎stl/httpd.h

Copy file name to clipboardExpand all lines: stl/httpd.h
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
/*
2+
* Simple webserver for MATLAB Coder
3+
* Peter Corke August 2018
4+
*/
15
#ifndef __httpd_h_
26
#define __httpd_h_
37

48
// C functions in httpd.c which are wrapped by webserver.m
5-
void web_start(int32_t port, char *callback);
9+
void web_start(int32_t port, char *callback, void *arg);
610
void web_debug(int32_t debug);
711

812
void web_url(char *buf, int len);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.