Пример #1
0
int start()
{
	jparse_init();
	rest_init();
	http_start();
	device_init();
#ifdef _DEBUG
	billing_init();
#endif
#ifndef _MSC_VER
	const char *initrc = initSearch(search_file.c_str());
	if (initrc && initrc[0]) {
		api_log_printf("%s\r\n", initrc);
		searcher = NULL;
	}
	else {
		searcher = makeSearcher();
	}
#endif

	api_listen_tcp(api_tag, host.c_str(), port.c_str(), &handlers);

	size_t num_cores;

	#ifdef WIN32
		SYSTEM_INFO sysinfo;
		GetSystemInfo(&sysinfo);
		num_cores = sysinfo.dwNumberOfProcessors;
	#elif MACOS
	    int nm[2];
		size_t len = 4;
		uint32_t count;

		nm[0] = CTL_HW; nm[1] = HW_AVAILCPU;
	    sysctl(nm, 2, &count, &len, NULL, 0);

	    if(count < 1) {
		    nm[1] = HW_NCPU;
			sysctl(nm, 2, &count, &len, NULL, 0);
	        if(count < 1) { count = 1; }
		}
	    num_cores = count;
	#else
		num_cores = sysconf(_SC_NPROCESSORS_ONLN);
	#endif

	CPUINFO *cpu_info = cpu_get_info();
	api_log_printf("[HTTP] CPU INFO: Brand name: %s, cores count: %u, Hyper threads: %s\r\n",
		cpu_info->vendor.c_str(), num_cores, (cpu_info->hyper_threads) ? "yes" : "no");

	thread_pool_init(num_cores - 1);

	api_log_printf("[HTTP] Started\r\n");

	return 0;
}
Пример #2
0
int main()
{
	struct http_server *httpd;
	struct timeval timeout = { 2, 0 };	
#ifdef WIN32
	{
		WSADATA wd;
		WSAStartup( MAKEWORD( 2, 0 ), &wd );
	}
#endif
	
#ifdef WIN32
	if( !SetConsoleCtrlHandler( Handler, TRUE ) )
	{
		fprintf( stderr, "error setting event handler.\n" );
		return -1;
	}
#endif

	http_set_info_log( info_log );
	httpd = http_start( "0.0.0.0", 8080, 1024 );
	http_set_rcb( httpd, handle_request, 0 );

#ifdef CGI_SUPPORT
#ifdef CGI_LUA_SUPPORT
	luaC_init( httpd );
	luaC_set_script_cb( file_exist, load_file );
#else
	http_set_cgi_cb( httpd, handle_cgi_query, 0 );
#endif
#endif

	printf( "server startup\n" );
	
	while( is_done == 0 )
	{
		http_poll( httpd, &timeout );
	}

#ifdef CGI_LUA_SUPPORT
	luaC_release();
#endif

	http_free( httpd );
	
#ifdef WIN32
	WSACleanup();
#endif
	printf( "server shutdown\n" );
	return 0;
}