Made sockets nonblocking (I'm a fool who didn't do this and spent several hours trying to figure out why I couldn't handle a second request if firefox was on the page I'm so dumb I hate myself I hate coding I hate the internet computers were a mistake)

This commit is contained in:
Nate Choe
2022-01-30 12:43:10 -06:00
parent e4fe179480
commit e05896356f
8 changed files with 115 additions and 10 deletions

View File

@@ -202,7 +202,7 @@ static int processChar(Connection *conn, char c, Sitefile *site) {
return 0;
}
long diff(struct timespec *t1, struct timespec *t2) {
static long diff(struct timespec *t1, struct timespec *t2) {
return (t2->tv_sec - t1->tv_sec) * 1000 +
(t2->tv_nsec - t1->tv_nsec) / 1000000;
}
@@ -220,12 +220,11 @@ int updateConnection(Connection *conn, Sitefile *site) {
if (received < 0)
return errno != EAGAIN;
if (received == 0)
break;
return 0;
memcpy(&conn->lastdata, &currentTime, sizeof(struct timespec));
for (unsigned long i = 0; i < received; i++) {
if (processChar(conn, buff[i], site))
return 1;
}
}
return 0;
}