WebServer WebServerCreate(char* port) { WebServer webServer = malloc(sizeof(struct _WebServer)); webServer->ioQueue = DispatchQueueCreate(0); if (webServer->ioQueue == NULL) { Release(webServer); printf("Could not create io queue.\n"); return NULL; } webServer->processingQueue = DispatchQueueCreate(0); if (webServer->processingQueue == NULL) { Release(webServer); printf("Could not create processing queue.\n"); return NULL; } webServer->numberOfServers = 0; webServer->poll = PollCreate(); if (webServer->poll == NULL) { Release(webServer); printf("Could not create poll.\n"); return NULL; } if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { perror("signal"); Release(webServer); return NULL; } if (!CreateServers(webServer, port)) { Release(webServer); printf("Could not create servers\n"); return NULL; } if (webServer->numberOfServers == 0) { Release(webServer); printf("Could not listen on any socket.\n"); return NULL; } return webServer; }
void TPolls::ScheduleRequest(fastcgi::Request *request, fastcgi::HandlerContext *context) { auto& path = request->getScriptName(); auto& method = request->getRequestMethod(); request->setContentType("application/json"); std::string pollId; std::string voteId; if (IsListPolls(path, method)) { ListPolls(request, context); } else if (IsPollCreate(path, method)) { PollCreate(request, context); } else if (IsPollInfo(path, method, &pollId)) { PollInfo(request, context, pollId); } else if (IsPollVote(path, method, &pollId, &voteId)) { PollVote(request, context, pollId, voteId); } else { request->setStatus(404); } }