This commit is contained in:
Jordan Bancino 2022-11-02 00:18:13 +00:00
parent fddfbf57ca
commit 5af229a86e
2 changed files with 14 additions and 4 deletions

View file

@ -59,8 +59,8 @@ Phase 2: Building a foundation
file live there as well. file live there as well.
[x] Allow logging to the syslog [x] Allow logging to the syslog
[x] Fix memory leaks [x] Fix memory leaks
[ ] Fix bug where the socket stays open after quit. [x] Fix bug where the socket stays open after quit.
[ ] Possibly related to not closing the connections with fclose()? [x] Possibly related to not closing the connections with fclose()?
(see HttpServer.c, grep for fclose) (see HttpServer.c, grep for fclose)
[ ] Figure out how to write unit tests for array/hashmap/etc [ ] Figure out how to write unit tests for array/hashmap/etc
[ ] Add recipe to td script to upload patches to the Matrix room [ ] Add recipe to td script to upload patches to the Matrix room

View file

@ -41,6 +41,8 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
static const char ENABLE = 1;
struct HttpServer struct HttpServer
{ {
int sd; int sd;
@ -357,6 +359,16 @@ HttpServerCreate(unsigned short port, unsigned int nThreads, unsigned int maxCon
goto error; goto error;
} }
if (setsockopt(server->sd, SOL_SOCKET, SO_REUSEADDR, &ENABLE, sizeof(int)) < 0)
{
goto error;
}
if (setsockopt(server->sd, SOL_SOCKET, SO_REUSEPORT, &ENABLE, sizeof(int)) < 0)
{
goto error;
}
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_port = htons(port); sa.sin_port = htons(port);
sa.sin_addr.s_addr = htonl(INADDR_ANY); sa.sin_addr.s_addr = htonl(INADDR_ANY);
@ -598,9 +610,7 @@ bad_request:
finish: finish:
Free(line); Free(line);
#if 0
fclose(fp); fclose(fp);
#endif
} }
return NULL; return NULL;