Multiple port support

This commit is contained in:
Nate Choe
2022-06-21 23:34:13 -05:00
parent dc044b22e3
commit 47cf044858
19 changed files with 333 additions and 136 deletions

View File

@@ -27,7 +27,7 @@
#include <swebs/responses.h>
#include <swebs/connections.h>
int newConnection(Stream *stream, Connection *ret) {
int newConnection(Stream *stream, Connection *ret, int portind) {
struct timespec currentTime;
ret->stream = stream;
@@ -68,6 +68,8 @@ int newConnection(Stream *stream, Connection *ret) {
return 1;
}
memcpy(&ret->lastdata, &currentTime, sizeof(struct timespec));
ret->portind = portind;
return 0;
}
@@ -360,10 +362,11 @@ int updateConnection(Connection *conn, Sitefile *site) {
ssize_t received;
unsigned long i;
struct timespec currentTime;
const Port *port = site->ports + conn->portind;
if (clock_gettime(CLOCK_MONOTONIC, &currentTime) < 0)
return 1;
if (site->timeout > 0 &&
diff(&conn->lastdata, &currentTime) > site->timeout)
if (port->timeout > 0 &&
diff(&conn->lastdata, &currentTime) > port->timeout)
return 1;
received = recvStream(conn->stream, buff, sizeof(buff));
if (received < 0)