Minor logic change

This commit is contained in:
Nate Choe
2022-02-16 23:33:14 -06:00
parent f79105f621
commit 49adfea0db
2 changed files with 14 additions and 9 deletions

View File

@@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -218,6 +219,7 @@ static long diff(struct timespec *t1, struct timespec *t2) {
} }
int updateConnection(Connection *conn, Sitefile *site) { int updateConnection(Connection *conn, Sitefile *site) {
size_t totalReceived = 0;
for (;;) { for (;;) {
char buff[300]; char buff[300];
ssize_t received; ssize_t received;
@@ -229,10 +231,17 @@ int updateConnection(Connection *conn, Sitefile *site) {
diff(&conn->lastdata, &currentTime) > site->timeout) diff(&conn->lastdata, &currentTime) > site->timeout)
return 1; return 1;
received = recvStream(conn->stream, buff, sizeof(buff)); received = recvStream(conn->stream, buff, sizeof(buff));
if (received < 0) if (received < 0) {
char log[200];
sprintf(log,
"recvStream() returned %ld, with errno %d, received %lu bytes this iteration "
"of updateConnection",
received, errno, totalReceived);
return errno != EAGAIN; return errno != EAGAIN;
}
if (received == 0) if (received == 0)
return 0; return 1;
totalReceived += received;
memcpy(&conn->lastdata, &currentTime, sizeof(struct timespec)); memcpy(&conn->lastdata, &currentTime, sizeof(struct timespec));
for (i = 0; i < received; i++) { for (i = 0; i < received; i++) {
if (processChar(conn, buff[i], site)) if (processChar(conn, buff[i], site))

View File

@@ -46,16 +46,12 @@ void *runServer(RunnerArgs *args) {
for (;;) { for (;;) {
int i; int i;
if (site->timeout == 0) { poll(fds, connCount, -1);
poll(fds, connCount, -1);
}
else
poll(fds, connCount, site->timeout);
{ {
char log[200]; char log[200];
sprintf(log, sprintf(log,
"poll() finished with %d connections and a timeout of %d ms", "poll() finished with %d connections",
connCount, site->timeout); connCount);
createLog(log); createLog(log);
} }