summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/main.c b/main.c
index 906be15..96cfa67 100644
--- a/main.c
+++ b/main.c
@@ -46,7 +46,7 @@ static int read_everything(FILE * f_r, FILE * output) {
46 continue; 46 continue;
47 } 47 }
48 48
49 fwrite(read_buffer, read_buffer_length, 1, output); 49 fwrite(read_buffer, 1, size, output);
50 50
51 if (read_buffer_length > POST_DATA_MAX_LENGTH) 51 if (read_buffer_length > POST_DATA_MAX_LENGTH)
52 return EXIT_FAILURE; 52 return EXIT_FAILURE;
@@ -67,7 +67,10 @@ static void * answer_request(size_t new_socket) {
67 FILE * output = open_memstream(&output_buffer, &output_buffer_length); 67 FILE * output = open_memstream(&output_buffer, &output_buffer_length);
68 68
69 read_everything(f_r, output); // TODO: catch return value and error handling 69 read_everything(f_r, output); // TODO: catch return value and error handling
70 shutdown(new_socket, SHUT_RD); // shutdown the reading half of the connection 70 fflush(output);
71 // shutdown(new_socket, SHUT_RD); // shutdown the reading half of the connection
72
73 DEBUG("output buffer has a length of %ld bytes\n", output_buffer_length);
71 74
72 // TODO: make parsing function abstract (e.g. parse(...) function point with dlsym) 75 // TODO: make parsing function abstract (e.g. parse(...) function point with dlsym)
73 parse_http(new_socket, output_buffer, output_buffer_length); 76 parse_http(new_socket, output_buffer, output_buffer_length);
@@ -80,8 +83,8 @@ static void * answer_request(size_t new_socket) {
80 return NULL; 83 return NULL;
81} 84}
82 85
83
84int become_daemon(const char * name) { 86int become_daemon(const char * name) {
87# ifndef DEBUG // debugging is simpler in foreground mode
85 if(fork()) { 88 if(fork()) {
86 exit(EXIT_SUCCESS); 89 exit(EXIT_SUCCESS);
87 } else { 90 } else {
@@ -90,12 +93,12 @@ int become_daemon(const char * name) {
90 exit(EXIT_SUCCESS); 93 exit(EXIT_SUCCESS);
91 } else { 94 } else {
92 syslog(0, "daemon '%s' is running with pid %d", name, getpid()); 95 syslog(0, "daemon '%s' is running with pid %d", name, getpid());
93 return EXIT_SUCCESS;
94 } 96 }
95 } 97 }
98# endif
99 return EXIT_SUCCESS;
96} 100}
97 101
98
99static int serve(int server_fd) 102static int serve(int server_fd)
100{ 103{
101 struct sockaddr_in address; 104 struct sockaddr_in address;
@@ -129,7 +132,6 @@ int main(const int argc, char const * argv[]) {
129 int port = atoi(argc > 1 ? argv[1] : "8080"); 132 int port = atoi(argc > 1 ? argv[1] : "8080");
130 0 == port ? port = 8080 : port; 133 0 == port ? port = 8080 : port;
131 134
132
133 struct sockaddr_in address = { 135 struct sockaddr_in address = {
134 .sin_family = AF_INET, 136 .sin_family = AF_INET,
135 .sin_addr.s_addr = INADDR_ANY, 137 .sin_addr.s_addr = INADDR_ANY,
..