c - Calling functions from mongoose begin_request_handler callback -
currently i'm working on application embeds mongoose webserver. in cases, have call additional functions inside begin_request_handler create desired http header. during this, realized theses functions called after request handler done. example:
void test() { printf("hello"); } static int begin_request_handler(struct mg_connection *conn) { test(); const struct mg_request_info *request_info = mg_get_request_info(conn); ... return 1; } here hello getting printed right after browser closes tcp connection. there way call functions inside callbacks? or missing something?
if want create desired http header. function mentioned above
(begin_request_handler)may not correct approach. structuremg_request_infofield in structuremg_connection. here name , value of headers set. think these structures populated @ start after connection establishment. @pull(),read(). these ground-level function data set.and yes there way call functions callbacks.you can write own callback , make callback function point in struct of
mg_contextmake point callback. , inhandle_request()can call appropriately. can addstruct mg_callbacksin mongoose.h
example:
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request => begin_request_handler;//place function in place of begin_request_handler
// start web server.ctx = mg_start(&callbacks, null, options);
please specify more details maybe interested in.
Comments
Post a Comment