/** Main request handling thread. @param args Two item array of void-cast pointers to the httpd and request struct */ void thread_httpd(void *args) { void **params; httpd *webserver; request *r; params = (void **)args; webserver = *params; r = *(params + 1); free(params); /* XXX We must release this ourselves. */ if (httpdReadRequest(webserver, r) == 0) { /* * We read the request fine */ debug(LOG_DEBUG, "Processing request from %s", r->clientAddr); debug(LOG_DEBUG, "Calling httpdProcessRequest() for %s", r->clientAddr); //前面有通过函数httpdAddCContent设置访问页面的回调函数..如果请求的不是页面没有设置, //那就会调用404错误... //该函数httpdSetErrorFunction会设定404错误的回调函数. httpdProcessRequest(webserver, r); debug(LOG_DEBUG, "Returned from httpdProcessRequest() for %s", r->clientAddr); } else { debug(LOG_DEBUG, "No valid request received from %s", r->clientAddr); } debug(LOG_DEBUG, "Closing connection with %s", r->clientAddr); httpdEndRequest(r); }
void* remoteConfigThread(void* param) { RemoteConfigImpl* self = (RemoteConfigImpl*)param; while(!self->base.requestExit) { struct timeval to = {0, 1000}; if (httpdGetConnection(self->base.http, &to) <= 0) continue; if(httpdReadRequest(self->base.http) < 0) { httpdEndRequest(self->base.http); continue; } remoteConfigLockImpl(self); httpdProcessRequest(self->base.http); remoteConfigUnlockImpl(self); httpdEndRequest(self->base.http); } return nullptr; }
int main( int argc, char *argv[]) { httpd *server; /* ** Create a server and setup our logging */ server = httpdCreate(NULL,1234); if (server == NULL) { perror("Can't create server"); exit(1); } httpdSetAccessLog(server, stdout); httpdSetErrorLog(server, stderr); /* ** Setup some content for the server */ httpdAddCContent(server,"/", "dummy", HTTP_TRUE, NULL, dummy_html); httpdSetFileBase(server, "/home/prabinb/queralyzer/queralyzerUI/"); httpdAddFileContent(server, "/", "index.html", HTTP_TRUE, NULL, "index.html" ); httpdAddWildcardContent(server, "/css", NULL, "css"); httpdAddWildcardContent(server, "/img", NULL, "img"); httpdAddWildcardContent(server, "/js", NULL, "js"); httpdAddWildcardContent(server, "/js/lib", NULL, "js/lib"); httpdAddWildcardContent(server, "/bootstrap", NULL, "bootstrap"); httpdAddWildcardContent(server, "/bootstrap/css", NULL, "bootstrap/css"); httpdAddWildcardContent(server, "/bootstrap/img", NULL, "bootstrap/img"); httpdAddWildcardContent(server, "/bootstrap/js", NULL, "bootstrap/js"); httpdAddCContent(server,"/", "query", HTTP_TRUE, NULL, query_html); httpdAddCContent(server,"/", "tablemetadata", HTTP_TRUE, NULL, table_data_html); httpdAddCContent(server,"/", "indexmetadata", HTTP_TRUE, NULL, index_data_html); /* ** Go into our service loop */ while(1 == 1) { if (httpdGetConnection(server, 0) < 0) continue; if(httpdReadRequest(server) < 0) { httpdEndRequest(server); continue; } else { httpdProcessRequest(server); httpdEndRequest(server); } } }