task API demo page, string stuff

This commit is contained in:
udo
2022-01-19 20:46:27 +00:00
parent cbf57a9a35
commit 08496afa11
15 changed files with 188 additions and 10 deletions
+24
View File
@@ -40,6 +40,30 @@ u8 hex_to_u8(String src)
return(char_to_u8(src[0])*16 + char_to_u8(src[1]));
}
String str_to_lower(String s)
{
String result = "";
for(auto c : s)
{
if(c >= 'A' && c <= 'Z')
c = tolower(c);
result.append(1, c);
}
return(result);
}
String str_to_upper(String s)
{
String result = "";
for(auto c : s)
{
if(c >= 'A' && c <= 'Z')
c = toupper(c);
result.append(1, c);
}
return(result);
}
String trim(String raw)
{
u32 len = raw.length();
+2
View File
@@ -2,6 +2,8 @@
u8 char_to_u8(char input);
u8 hex_to_u8(String src);
u64 int_val(String s, u32 base = 10);
String str_to_lower(String s);
String str_to_upper(String s);
String trim(String raw);
StringList split(String str, String delim = "\n");
+15
View File
@@ -423,6 +423,21 @@ void spawn_subprocess(std::function<void()> exec_after_spawn)
}
}
pid_t task_pid(String key)
{
String status_file_name = context->server->config.BIN_DIRECTORY + "/task-" + key;
String status_file = file_get_contents(status_file_name);
pid_t p = 0;
if(status_file != "")
{
p = int_val(status_file);
if(kill(p, 0) == 0) // process is still running
return(p);
unlink(status_file_name);
}
return(p);
}
pid_t task(String key, std::function<void()> exec_after_spawn, u64 timeout)
{
String status_file_name = context->server->config.BIN_DIRECTORY + "/task-" + key;
+2
View File
@@ -39,4 +39,6 @@ pid_t parent_pid = 0;
pid_t my_pid = 0;
void on_segfault(int sig);
pid_t task(String key, std::function<void()> exec_after_spawn, u64 timeout = 60*10);
pid_t task_pid(String key);
+4
View File
@@ -21,6 +21,10 @@ String uri_decode(String q)
result.append(1, hex_to_u8(q.substr(i+1, 2)));
i += 2;
}
else if(c == '+')
{
result.append(1, ' ');
}
else
{
result.append(1, c);