Loading main.c +17 −11 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ void getRequest(int clientfd, GrowthBuffer *request); int checkFile(char *fileName); void serveFile(int clientfd, const char *path); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wmissing-noreturn" Loading Loading @@ -122,17 +124,7 @@ int handle_client(int clientfd) { appendBuffer(&response, basicHeader, strlen(basicHeader)); write(clientfd, response.array, strlen(response.array)); if (verb == HTTP_GET) { FILE *fp; size_t numBytesReadFile; fp = fopen(path, "r"); char fileBuff[1024]; if (fp) { printf("\nGot a fp\n"); while ((numBytesReadFile = fread(fileBuff, 1023, 1, fp)) > 0) { write(clientfd, fileBuff, strlen(fileBuff)); } } fclose(fp); serveFile(clientfd, path); } } else { char *basicHeader = "HTTP/1.1 404 Not Found\r\n\r\n"; Loading @@ -150,6 +142,20 @@ int handle_client(int clientfd) { #endif } void serveFile(int clientfd, const char *path) { FILE *fp; size_t numBytesReadFile; fp = fopen(path, "r"); char fileBuff[1024]; if (fp) { printf("\nGot a fp\n"); while ((numBytesReadFile = fread(fileBuff, 1023, 1, fp)) > 0) { write(clientfd, fileBuff, strlen(fileBuff)); } } fclose(fp); } void getRequest(int clientfd, GrowthBuffer *request) { struct pollfd pollfd = { .fd = clientfd, Loading Loading
main.c +17 −11 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ void getRequest(int clientfd, GrowthBuffer *request); int checkFile(char *fileName); void serveFile(int clientfd, const char *path); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wmissing-noreturn" Loading Loading @@ -122,17 +124,7 @@ int handle_client(int clientfd) { appendBuffer(&response, basicHeader, strlen(basicHeader)); write(clientfd, response.array, strlen(response.array)); if (verb == HTTP_GET) { FILE *fp; size_t numBytesReadFile; fp = fopen(path, "r"); char fileBuff[1024]; if (fp) { printf("\nGot a fp\n"); while ((numBytesReadFile = fread(fileBuff, 1023, 1, fp)) > 0) { write(clientfd, fileBuff, strlen(fileBuff)); } } fclose(fp); serveFile(clientfd, path); } } else { char *basicHeader = "HTTP/1.1 404 Not Found\r\n\r\n"; Loading @@ -150,6 +142,20 @@ int handle_client(int clientfd) { #endif } void serveFile(int clientfd, const char *path) { FILE *fp; size_t numBytesReadFile; fp = fopen(path, "r"); char fileBuff[1024]; if (fp) { printf("\nGot a fp\n"); while ((numBytesReadFile = fread(fileBuff, 1023, 1, fp)) > 0) { write(clientfd, fileBuff, strlen(fileBuff)); } } fclose(fp); } void getRequest(int clientfd, GrowthBuffer *request) { struct pollfd pollfd = { .fd = clientfd, Loading