static int createEndpoints(int argc, char **argv) { HttpHost *host; HttpRoute *route; host = httpCreateHost(); httpSetDefaultHost(host); route = httpCreateRoute(host); httpSetHostDefaultRoute(host, route); httpFinalizeRoute(route); httpInitConfig(route); if (httpLoadConfig(route, app->configFile) < 0) { return MPR_ERR_CANT_CREATE; } mprGC(MPR_GC_FORCE | MPR_GC_COMPLETE); return 0; }
/* Destroy the http service. This should be called only after ensuring all running requests have completed. Normally invoked by the http terminator from mprDestroy */ PUBLIC void httpDestroy() { Http *http; if ((http = HTTP) == 0) { return; } httpStopConnections(0); httpStopEndpoints(); httpSetDefaultHost(0); if (http->timer) { mprRemoveEvent(http->timer); http->timer = 0; } if (http->timestamp) { mprRemoveEvent(http->timestamp); http->timestamp = 0; } MPR->httpService = NULL; }
/* Create a new server. A server may manage may multiple servers and virtual hosts. If ip/port endpoint is supplied, this call will create a Server on that endpoint. Otherwise, maConfigureServer should be called later. A default route is created with the document root set to "." */ PUBLIC MaServer *maCreateServer(MaAppweb *appweb, cchar *name) { MaServer *server; HttpHost *host; HttpRoute *route; assert(appweb); if ((server = mprAllocObj(MaServer, manageServer)) == NULL) { return 0; } if (name == 0 || *name == '\0') { name = "default"; } server->name = sclone(name); server->endpoints = mprCreateList(-1, 0); server->limits = httpCreateLimits(1); server->appweb = appweb; server->http = appweb->http; server->defaultHost = host = httpCreateHost(NULL); if (!httpGetDefaultHost()) { httpSetDefaultHost(host); } route = httpCreateRoute(host); httpSetRouteName(route, "default"); //UNUSED httpSetRoutePrefix(route, ""); httpSetHostDefaultRoute(host, route); route->limits = server->limits; maAddServer(appweb, server); if (appweb->defaultServer == 0) { maSetDefaultServer(appweb, server); } return server; }