aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-runserver/main.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-09-25 20:54:39 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-09-25 20:54:39 +0200
commit123486ac617ac298fdecb1fbdbc504ac84118718 (patch)
tree837d72872a23607ae2f6994a6fe8a61a0dc2dbe1 /src/blogc-runserver/main.c
parent1a94d1f0f7e1403fd76ff09fbdb0d79c766d1a5c (diff)
downloadblogc-123486ac617ac298fdecb1fbdbc504ac84118718.tar.gz
blogc-123486ac617ac298fdecb1fbdbc504ac84118718.tar.bz2
blogc-123486ac617ac298fdecb1fbdbc504ac84118718.zip
runserver: implemented a thread pool and fixed few bugs
Diffstat (limited to 'src/blogc-runserver/main.c')
-rw-r--r--src/blogc-runserver/main.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/blogc-runserver/main.c b/src/blogc-runserver/main.c
index d12fc99..afc9db6 100644
--- a/src/blogc-runserver/main.c
+++ b/src/blogc-runserver/main.c
@@ -23,7 +23,7 @@ print_help(void)
{
printf(
"usage:\n"
- " blogc-runserver [-h] [-v] [-t HOST] [-p PORT] DOCROOT\n"
+ " blogc-runserver [-h] [-v] [-t HOST] [-p PORT] [-m THREADS] DOCROOT\n"
" - A simple HTTP server to test blogc websites.\n"
"\n"
"positional arguments:\n"
@@ -33,14 +33,15 @@ print_help(void)
" -h show this help message and exit\n"
" -v show version and exit\n"
" -t HOST set server listen address (default: 127.0.0.1)\n"
- " -p PORT set server listen port (default: 8080)\n");
+ " -p PORT set server listen port (default: 8080)\n"
+ " -m THREADS set maximum number of threads to spawn (default: 20)\n");
}
static void
print_usage(void)
{
- printf("usage: blogc-runserver [-h] [-v] [-t HOST] [-p PORT] DOCROOT\n");
+ printf("usage: blogc-runserver [-h] [-v] [-t HOST] [-p PORT] [-m THREADS] DOCROOT\n");
}
@@ -53,6 +54,7 @@ main(int argc, char **argv)
char *host = NULL;
char *docroot = NULL;
unsigned short port = 8080;
+ size_t max_threads = 20;
unsigned int args = 0;
@@ -77,6 +79,12 @@ main(int argc, char **argv)
else
port = strtoul(argv[++i], NULL, 10);
break;
+ case 'm':
+ if (argv[i][2] != '\0')
+ max_threads = strtoul(argv[i] + 2, NULL, 10);
+ else
+ max_threads = strtoul(argv[++i], NULL, 10);
+ break;
default:
print_usage();
fprintf(stderr, "blogc-runserver: error: invalid "
@@ -106,10 +114,18 @@ main(int argc, char **argv)
goto cleanup;
}
+ if (max_threads <= 0 || max_threads > 1000) {
+ print_usage();
+ fprintf(stderr, "blogc-runserver: error: invalid value for -m. "
+ "Must be integer > 0 and <= 1000\n");
+ rv = 2;
+ goto cleanup;
+ }
+
if (host == NULL)
host = bc_strdup("127.0.0.1");
- rv = br_httpd_run(host, port, docroot);
+ rv = br_httpd_run(host, port, docroot, max_threads);
cleanup:
free(host);