Retly incremental ports instead of infinite loop in =h&

This commit is contained in:
pancake 2017-04-03 23:22:59 +02:00
parent 6d870cc05a
commit 67b1d7a655
2 changed files with 10 additions and 2 deletions

View File

@ -2133,7 +2133,8 @@ R_API int r_core_config_init(RCore *core) {
#else
SETPREF("http.root", R2_WWWROOT, "http root directory");
#endif
SETPREF("http.port", "9090", "Server port");
SETPREF("http.port", "9090", "HTTP server port");
SETPREF("http.maxport", "9999", "Last HTTP server port");
SETPREF("http.ui", "m", "Default webui (enyo, m, p, t)");
SETPREF("http.sandbox", "true", "Sandbox the HTTP server");
SETI("http.timeout", 3, "Disconnect clients after N seconds of inactivity");

View File

@ -834,6 +834,13 @@ static int r_core_rtr_http_thread (RThread *th) {
}
int ret = r_core_rtr_http_run (ht->core, ht->launch, ht->path);
R_FREE (ht->path);
if (ret) {
int p = r_config_get_i (ht->core->config, "http.port");
r_config_set_i (ht->core->config, "http.port", p + 1);
if (p >= r_config_get_i (ht->core->config, "http.maxport")) {
return false;
}
}
return ret;
}
@ -1277,7 +1284,7 @@ R_API void r_core_rtr_cmd(RCore *core, const char *input) {
return;
}
if (*input == '&') {
if (*input == '&') { // "=h&"
if (rapthread) {
eprintf ("RAP Thread is already running\n");
eprintf ("This is experimental and probably buggy. Use at your own risk\n");