static int webserver_handler() { int retval = 1; switch(webserver_state) { case WEBSERVER_STATE_INIT: webserver = mg_create_server(NULL, ev_handler); mg_set_option(webserver, "listening_port", webserver_listeningport); mg_set_option(webserver, "document_root", webserver_documentroot); mg_set_option(webserver, "enable_directory_listing", "no"); mg_set_option(webserver, "index_files", ""); mg_set_option(webserver, "auth_domain", webserver_domain); webserver_state = WEBSERVER_STATE_POLLING; break; case WEBSERVER_STATE_POLLING: mg_poll_server(webserver, 1000); break; case WEBSERVER_STATE_EXITING: mg_destroy_server(&webserver); retval = 0; default: assert(false); } return retval; }
int main(void) { struct mg_server *server; //Start network configurations //setup_ap(); //setup_dhcp(); //setup_iptables(); // Create and configure the server server = mg_create_server(NULL, ev_handler); mg_set_option(server, "document_root", "."); mg_set_option(server, "listening_port", "8080"); limparRotas(); init_resources_table(); criar_tabela(); //registra a rota do log do cliente add_route("/login", handle_post_request); // Serve request. Hit Ctrl-C to terminate the program printf("Starting on port %s\n", mg_get_option(server, "listening_port")); for (;;) { mg_poll_server(server, 1000); } // Cleanup, and free server instance mg_destroy_server(&server); return 0; }
/////////////////////// //test <test.dict> int main(int argc, char * argv[]) { struct mg_server * server; // if(argc < 2) { printf("demo: %s <test.dict>\n", argv[0]); exit(0); } // dbox = dict_init(); dict_load(dbox, argv[1]); // server = mg_create_server(NULL, ev_handler); // mg_set_option(server, "listening_port", "8089"); // for(;;) { mg_poll_server(server, 1000); } // mg_destroy_server(&server); // dict_free(dbox); // return 0; }
void webserver_release() { if (g_prf.server != NULL) { mg_destroy_server(&g_prf.server); g_prf.server = NULL; log_print(LOG_TEXT, "httpd debug server closed."); } }
static void* web_SockJsServer_threadRun(void *data) { web_SockJsServer _this = web_SockJsServer(data); struct mg_server *server = mg_create_server(_this, web_SockJsServer_request); mg_set_option(server, "listening_port", "8000"); _this->server = (cx_word)server; web_SockJsServer_run(_this); mg_destroy_server(&server); return NULL; }
static void* web_thread(void* arg) { while (!web.exit) { mg_poll_server(web.server, 20); } mg_destroy_server(&web.server); return NULL; }
void server_stop() { da_free(rcon_data.plugin_handlers); //darray_free(&rcon_data.plugin_handlers); rcon_data.run_thread = false; pthread_join(rcon_data.server_thread,NULL); mg_destroy_server(&rcon_data.server); }
static int l_destroy_server(lua_State *L) { struct httpserver *hs = (struct httpserver *)luaL_checkudata(L, 1, META_HTTPAUTH); if (!hs) return 0; if (hs->server) mg_destroy_server(&hs->server); hs->server = NULL; return 0; }
void RestfulApi::sl_quit() { qDebug()<<"Closing Webserver API with thread: "<< QThread::currentThreadId(); // Cleanup, and free server instance mg_destroy_server(&server); // close the thread terminate(); }
static void WINAPI ServiceMain(void) { hStatus = RegisterServiceCtrlHandler(service_name, ControlHandler); ControlHandler(SERVICE_CONTROL_INTERROGATE); while (ss.dwCurrentState == SERVICE_RUNNING) { Sleep(1000); } mg_destroy_server(&server); }
WebAccess::~WebAccess() { m_running = false; wait(); mg_destroy_server(&m_server); #if defined(Q_WS_X11) || defined(Q_OS_LINUX) delete m_netConfig; #endif }
static void *serve_thread_func(void *param) { struct mg_server *server = (struct mg_server *) param; printf("Listening on port %s\n", mg_get_option(server, "listening_port")); while (s_received_signal == 0) { mg_poll_server(server, 1000); } mg_destroy_server(&server); return NULL; }
static void *stats_thread(void *payload) { struct mg_server *server = payload; for (;;) { mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop } mg_destroy_server(&server); return NULL; }
int main(void) { struct mg_server *server = mg_create_server(NULL); mg_set_option(server, "listening_port", "8080"); mg_add_uri_handler(server, "/", handler); printf("Starting on port %s\n", mg_get_option(server, "listening_port")); for (;;) { mg_poll_server(server, 1000); } mg_destroy_server(&server); return 0; }
void Server::poll() { unsigned int current_timer = 0; while (!stopped) { mg_poll_server(server, 1000); #ifndef NO_WEBSOCKET mg_iterate_over_connections(server, iterate_callback, ¤t_timer); #endif } mg_destroy_server(&server); }
int _tmain(int argc, _TCHAR* argv[]) { struct mg_server *server = mg_create_server(NULL); mg_set_option(server, "document_root", "."); // Serve current directory mg_set_option(server, "listening_port", "80"); // Open port 8080 mg_add_uri_handler(server, "/callPython/", event_handler); for (;;) { mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop } mg_destroy_server(&server); return 0; }
int main(void) { struct mg_server *server = mg_create_server(NULL, NULL); mg_set_option(server, "listening_port", "127.0.0.1:3255"); mg_set_option(server, "document_root", "."); mg_set_option(server, "index_files", "bank.cgi"); printf("Starting on port %s\n", mg_get_option(server, "listening_port")); for (;;) mg_poll_server(server, 1000); mg_destroy_server(&server); return 0; }
int mem_web::start_web() { struct mg_server *server = mg_create_server(NULL, NULL); mg_set_option(server, "document_root", "."); // Serve current directory mg_set_option(server, "listening_port", "8080"); // Open port 8080 for (;;) { mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop } mg_destroy_server(&server); return 0; }
int main() { struct mg_server *server = mg_create_server(NULL, event_handler); mg_set_option(server, "Partyfy", "."); mg_set_option(server, "listening_port", "8080"); const char *username = "******"; //size_t size; char *password = getpass("Enter the password for the account\n"); sp_session *sp; spconfig.application_key_size = g_appkey_size; sp_error err = sp_session_create(&spconfig, &sp); if(SP_ERROR_OK != err) { fprintf(stderr, "Unable to create session: %s\n", sp_error_message(err)); exit(1); } g_sess = sp; pthread_mutex_init(&g_notify_mutex, NULL); pthread_cond_init(&g_notify_cond, NULL); sp_session_login(g_sess, username, password, 0, NULL); // See if the user logged in successfully printConnectionState(); int timeout = 0; sp_connectionstate state = sp_session_connectionstate(g_sess); while (state != SP_CONNECTION_STATE_LOGGED_IN) { sp_session_process_events(g_sess, &timeout); printf("Logging in...\n"); usleep(100000); state = sp_session_connectionstate(g_sess); } //audio_init(&g_audiofifo); printf("Logged in\n"); for(;;) { mg_poll_server(server, 1000); sp_session_process_events(g_sess, &timeout); //while(!g_notify_do) // pthread_cond_wait(&g_notify_cond, &g_notify_mutex); //g_notify_do = 0; //pthread_mutex_unlock(&g_notify_mutex); //if(g_playback_done) { // g_playback_done = 0; //} //pthread_mutex_lock(&g_notify_mutex); } mg_destroy_server(&server); }
void msl::server_thread_func_m(msl::webserver_t::server_thread_t* thread) { while(mg_poll_server(thread->server,10)) { if(thread->stop==true) break; std::this_thread::sleep_for(std::chrono::milliseconds(1)); } mg_destroy_server(&thread->server); thread->stop=true; thread->mutex.unlock(); }
int main(void) { s_server = mg_create_server(NULL, ev_handler); mg_set_option(s_server, "listening_port", "8080"); signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); printf("Started on port %s\n", mg_get_option(s_server, "listening_port")); while (s_signal_received == 0) { mg_poll_server(s_server, 100); } mg_destroy_server(&s_server); return 0; }
int main(int argc, char *argv[]) { init_server_name(); start_mongoose(argc, argv); printf("%s serving [%s] on port %s\n", server_name, mg_get_option(server, "document_root"), mg_get_option(server, "listening_port")); fflush(stdout); // Needed, Windows terminals might not be line-buffered serving_thread_func(server); printf("Exiting on signal %d ...", exit_flag); fflush(stdout); mg_destroy_server(&server); printf("%s\n", " done."); return EXIT_SUCCESS; }
void SocketHandler::run( LPVOID lpStatus ) { const callbackFn fPtr = reinterpret_cast<callbackFn>( lpStatus ); struct mg_server *server = mg_create_server( NULL ); const int buflen = 32; char buf[buflen]; const char *result; int currentPort = DEFAULT_PORT; _snprintf( buf, buflen, "127.0.0.1:%i", currentPort ); while ( result = mg_set_option( server, "listening_port", buf ) ) { USE_DEBUG( "Error \"%s\" opening http listen socket %s\n", result, buf ); Sleep( 100 ); currentPort = rand() % ( MAX_PORT - MIN_PORT ) + MIN_PORT; _snprintf( buf, buflen, "127.0.0.1:%i", currentPort ); } listenPort = currentPort; mg_set_option( server, "document_root", documentRoot.c_str() ); mg_set_option( server, "extra_mime_types", ".mp4=video/mp4" ); USE_DEBUG( "Started on %s with root at %s\n", mg_get_option( server, "listening_port" ), mg_get_option( server, "document_root" ) ); canLoop = true; time_t lastTime = time( NULL ); while ( canLoop ) { mg_poll_server( server, 100 ); const time_t current_time = time( NULL ); if ( fPtr && lastTime < current_time ) { lastTime = current_time; fPtr(); } // Sleep( 20 ); // USE_DEBUG( "." ); } USE_DEBUG( "Webserver shuts down...\n" ); mg_destroy_server( &server ); USE_DEBUG( "Webserver is shut down.\n" ); }
int main(int argc, char *argv[]) { struct mg_server *server = mg_create_server(NULL); mg_set_option(server, "listening_port", "8080"); mg_set_option(server, "document_root", argc > 1 ? argv[1] : "."); mg_add_uri_handler(server, "/ws", handler); mg_start_thread(timer_thread, server); printf("Started on port %s\n", mg_get_option(server, "listening_port")); for (;;) { mg_poll_server(server, 3000); } mg_destroy_server(&server); return 0; }
static const char *test_ssl(void) { static const char *ssl_cert = "examples/ssl_cert.pem"; char buf1[100] = ""; struct mg_server *server = mg_create_server(NULL); ASSERT(mg_set_option(server, "listening_port", LISTENING_ADDR) == NULL); ASSERT(mg_set_option(server, "document_root", ".") == NULL); ASSERT(mg_set_option(server, "ssl_certificate", ssl_cert) == NULL); ASSERT(mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 1, us1, buf1) == 1); { int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1000); } ASSERT(strcmp(buf1, "1") == 0); mg_destroy_server(&server); return NULL; }
// THIS FUNCTION IS NOT CALLED ON THE MAIN THREAD void *SV_MV_Websrv_Loop_ExtThread(void *server) { while (1) { MV_LockMutex(m_srv); if (m_end) { mg_destroy_server((struct mg_server **)&mgsrv); m_end = qfalse; MV_ReleaseMutex(m_srv); return NULL; } MV_ReleaseMutex(m_srv); mg_poll_server((struct mg_server *)mgsrv, 500); } return NULL; }
//Mongoose void mongooseThread::Entry() { struct mg_server *mongooseserver; // Create and configure the server mongooseserver = mg_create_server((void *) "1", ::ev_handler); //WEB监听端口 char listening_port[6]; sprintf(listening_port, "%d", sHttpPort); mg_set_option(mongooseserver, "listening_port", listening_port); mg_set_option(mongooseserver, "document_root", sDocumentRoot); //donot use it printf("mongoose listen on port:%s document path:%s \n", listening_port , sDocumentRoot); //run server for (;;) mg_poll_server((struct mg_server *) mongooseserver, 1000); mg_destroy_server(&mongooseserver); }
int main(int argc, const char* argv[]) { if(2<=argc) { // setup std::string PatchesDirectory(argv[1]); CModularWebController Controller(PatchesDirectory); std::signal(SIGINT, signal_handler); std::signal(SIGTERM, signal_handler); std::signal(SIGILL, signal_handler); std::signal(SIGSEGV, signal_handler); std::signal(SIGFPE, signal_handler); std::signal(SIGABRT, signal_handler); struct mg_server *server; // Create and configure the server server = mg_create_server(&Controller, ev_handler); mg_set_option(server, "listening_port", "8080"); // Serve request. Hit Ctrl-C to terminate the program printf("Starting on port %s\n", mg_get_option(server, "listening_port")); // Run // detect ctrl-C or other signals while(gSignalStatus==0) { mg_poll_server(server, 1000); } std::cout << "Captured signal " << gSignalStatus << std::endl; // Cleanup, and free server instance std::cout << "Destroying server" << std::endl; mg_destroy_server(&server); return 0; } Usage(); return -1; }
void Java_vladimir_fileserver_MainActivity_startNativeServer(JNIEnv* env, jclass clazz, jstring path) { const char *path_utf8 = (*env)->GetStringUTFChars(env, path, NULL); server_loop = 1; struct mg_server *server; server = mg_create_server(NULL, NULL); __android_log_print(ANDROID_LOG_VERBOSE, "HTTP", "server created"); mg_set_option(server, "document_root", path_utf8); // Serve current directory mg_set_option(server, "listening_port", "8090"); // Open port 8080 __android_log_print(ANDROID_LOG_VERBOSE, "HTTP", "root path %s", path_utf8); __android_log_print(ANDROID_LOG_VERBOSE, "HTTP", "port 8090"); __android_log_print(ANDROID_LOG_VERBOSE, "HTTP", "starting loop..."); while (server_loop) { mg_poll_server(server, 500); // Infinite loop, Ctrl-C to stop } __android_log_print(ANDROID_LOG_VERBOSE, "HTTP", "stopping..."); mg_destroy_server(&server); __android_log_print(ANDROID_LOG_VERBOSE, "HTTP", "stopped"); }
int main(void) { struct mg_server *server; // Create and configure the server server = mg_create_server(NULL, ev_handler); mg_set_option(server, "listening_port", "8080"); // Serve request. Hit Ctrl-C to terminate the program printf("Starting on port %s\n", mg_get_option(server, "listening_port")); for (;;) { mg_poll_server(server, 1000); } // Cleanup, and free server instance mg_destroy_server(&server); return 0; }