c++ - Mongoose Server callback loop -
after looking c library implemented web server, taught mongoose. have made work through several examples make call callback function treats incoming , outgoing data. using on windows, compiling , debugging visual studio 2008.
i called session , follows:
int chttpscom::session( void ) { struct mg_context *ctx; const char *options[] = { "listening_ports", "443s", #ifdef _debug "ssl_certificate", "c:\\temp\\cert.pem", #else "ssl_certificate", "cert.pem", #endif null }; ctx = mg_start( &callback, null, options ); if( !ctx ) return 1; //getchar(); // wait until user hits "enter" while ( leaveit == false ); sleep(3500);// without won't work mg_stop( ctx ); return 0; }
100% of examples have noticed examples use getchar synchronize end of session ending if callback execution. have leaveit flag set after post message. if don't use sleep above, deadlock internal library. there better way of handling wait the callback ending ?
thanks.
replace
while ( leaveit == false ); sleep(3500);// without won't work
by (at worst you'll save cpu consumption):
while (!leaveit) { sleep(500); }
Comments
Post a Comment