diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 41 |
1 files changed, 2 insertions, 39 deletions
@@ -1,16 +1,16 @@ -#define _GNU_SOURCE #include <stdio.h> #include <stdbool.h> -#include <stdarg.h> #include <string.h> #include <signal.h> #include <sys/socket.h> +#include <sys/wait.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <errno.h> #include "http.h" #include "memory.h" +#include "util.h" #define PORT 8080 @@ -37,43 +37,6 @@ static void signal_handler(int sig){ } -// Returns -1 on error, 0 on success -static int sendall(int sock,const char *buf,ssize_t len){ - if(len==-1){ - len=strlen(buf); - } - - ssize_t sent=0; - while(sent<len){ - ssize_t ret=send(sock,buf+sent,len-sent,0); - if(ret<0){ - if(errno==EINTR){ - continue; - } else { - return -1; - } - } - sent+=ret; - } - - return 0; -} - -__attribute__((format (printf, 2, 3))) -static int sendallf(int sock,const char *format,...){ - va_list ap; - va_start(ap,format); - char *buf; - int len=vasprintf(&buf,format,ap); - va_end(ap); - if(len<0){ - return -1; - } - int ret=sendall(sock,buf,len); - free(buf); - return ret; -} - static void connection_handler(int sock){ Headers *headers=http_get_headers(sock); if(headers==NULL){ |