summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2019-12-15 17:44:05 -0500
committerGravatar GitHub <noreply@github.com>2019-12-15 17:44:05 -0500
commit29a55cd595d41af31ee0b4737f78e53fa7cfc18d (patch)
tree1c1176b62f706101dff9e48baa0d41f243f08aa7
parent2bca6e48c0ea8043c5300f4ebdefa5167e6472bf (diff)
parent26bc0b3ba3990535034a296fc758759d6ae99f07 (diff)
Merge pull request #183 from docelic/master
Add UNIX socket support and '-u' option to specify socket filename
-rw-r--r--src/c/http.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/c/http.c b/src/c/http.c
index c1fccf4a..de2f1376 100644
--- a/src/c/http.c
+++ b/src/c/http.c
@@ -11,6 +11,7 @@
#include <unistd.h>
#include <signal.h>
#include <stdarg.h>
+#include <sys/un.h>
#include <pthread.h>
@@ -335,7 +336,7 @@ static void *worker(void *data) {
}
static void help(char *cmd) {
- printf("Usage: %s [-p <port>] [-a <IPv4 address>] [-A <IPv6 address>] [-t <thread count>] [-m <bytes>] [-k] [-q] [-T SEC]\nThe '-k' option turns on HTTP keepalive.\nThe '-q' option turns off some chatter on stdout.\nThe '-T' option sets socket recv timeout (0 disables timeout, default is 5 sec).\nThe '-m' sets the maximum size (in bytes) for any buffer used to hold HTTP data sent by clients. (The default is 1 MB.)\n", cmd);
+ printf("Usage: %s [-p <port>] [-a <IPv4 address>] [-A <IPv6 address>] [-u <UNIX socket>] [-t <thread count>] [-m <bytes>] [-k] [-q] [-T SEC]\nThe '-k' option turns on HTTP keepalive.\nThe '-q' option turns off some chatter on stdout.\nThe '-T' option sets socket recv timeout (0 disables timeout, default is 5 sec).\nThe '-m' sets the maximum size (in bytes) for any buffer used to hold HTTP data sent by clients. (The default is 1 MB.)\n", cmd);
}
static void sigint(int signum) {
@@ -348,6 +349,7 @@ union uw_sockaddr {
struct sockaddr sa;
struct sockaddr_in ipv4;
struct sockaddr_in6 ipv6;
+ struct sockaddr_un un;
};
int main(int argc, char *argv[]) {
@@ -367,7 +369,7 @@ int main(int argc, char *argv[]) {
my_addr.sa.sa_family = AF_INET;
my_addr.ipv4.sin_addr.s_addr = INADDR_ANY; // auto-fill with my IP
- while ((opt = getopt(argc, argv, "hp:a:A:t:kqT:m:")) != -1) {
+ while ((opt = getopt(argc, argv, "hp:a:A:u:t:kqT:m:")) != -1) {
switch (opt) {
case '?':
fprintf(stderr, "Unknown command-line option\n");
@@ -405,6 +407,15 @@ int main(int argc, char *argv[]) {
}
break;
+ case 'u':
+ my_addr.sa.sa_family = AF_UNIX;
+ if (!strncpy(my_addr.un.sun_path, optarg, sizeof(my_addr.un.sun_path)-1)) {
+ fprintf(stderr, "Invalid UNIX socket filename\n");
+ help(argv[0]);
+ return 1;
+ }
+ break;
+
case 't':
nthreads = atoi(optarg);
if (nthreads <= 0) {
@@ -474,6 +485,11 @@ int main(int argc, char *argv[]) {
my_size = sizeof(my_addr.ipv6);
my_addr.ipv6.sin6_port = htons(uw_port);
break;
+
+ case AF_UNIX:
+ unlink(my_addr.un.sun_path);
+ my_size = sizeof(my_addr.un);
+ break;
}
if (bind(sockfd, &my_addr.sa, my_size) < 0) {