mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
http: Properly stop server on stop server.
This commit is contained in:
parent
429346bb94
commit
287d1967a5
3 changed files with 19 additions and 4 deletions
|
@ -79,7 +79,7 @@ static void RegisterServer(int port) {
|
|||
static void ExecuteServer() {
|
||||
setCurrentThreadName("HTTPServer");
|
||||
|
||||
net::Init();
|
||||
net::AutoInit netInit;
|
||||
auto http = new http::Server(new threading::SameThreadExecutor());
|
||||
|
||||
std::map<std::string, std::string> paths;
|
||||
|
@ -156,7 +156,11 @@ static void ExecuteServer() {
|
|||
}
|
||||
|
||||
if (!http->Listen(g_Config.iRemoteISOPort)) {
|
||||
http->Listen(0);
|
||||
if (!http->Listen(0)) {
|
||||
ERROR_LOG(COMMON, "Unable to listen on any port");
|
||||
UpdateStatus(ServerStatus::STOPPED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
UpdateStatus(ServerStatus::RUNNING);
|
||||
|
||||
|
@ -173,7 +177,7 @@ static void ExecuteServer() {
|
|||
}
|
||||
}
|
||||
|
||||
net::Shutdown();
|
||||
http->Stop();
|
||||
|
||||
UpdateStatus(ServerStatus::STOPPED);
|
||||
}
|
||||
|
|
|
@ -162,6 +162,10 @@ bool Server::Listen(int port) {
|
|||
}
|
||||
|
||||
bool Server::RunSlice(double timeout) {
|
||||
if (listener_ < 0 || port_ == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (timeout <= 0.0) {
|
||||
timeout = 86400.0;
|
||||
}
|
||||
|
@ -182,7 +186,9 @@ bool Server::RunSlice(double timeout) {
|
|||
}
|
||||
|
||||
bool Server::Run(int port) {
|
||||
Listen(port);
|
||||
if (!Listen(port)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
RunSlice(0.0);
|
||||
|
@ -192,6 +198,10 @@ bool Server::Run(int port) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Server::Stop() {
|
||||
closesocket(listener_);
|
||||
}
|
||||
|
||||
void Server::HandleConnection(int conn_fd) {
|
||||
Request request(conn_fd);
|
||||
if (!request.IsOK()) {
|
||||
|
|
|
@ -74,6 +74,7 @@ public:
|
|||
// for a new connection to handle.
|
||||
bool RunSlice(double timeout);
|
||||
bool Listen(int port);
|
||||
void Stop();
|
||||
|
||||
void RegisterHandler(const char *url_path, UrlHandlerFunc handler);
|
||||
void SetFallbackHandler(UrlHandlerFunc handler);
|
||||
|
|
Loading…
Add table
Reference in a new issue