Fixed a bug with CPU usage
This commit is contained in:
@@ -200,19 +200,22 @@ static int processChar(Connection *conn, char c, Sitefile *site) {
|
|||||||
conn->receivedBody >= conn->bodylen)
|
conn->receivedBody >= conn->bodylen)
|
||||||
getResponse(conn, site);
|
getResponse(conn, site);
|
||||||
if (conn->progress == SEND_RESPONSE) {
|
if (conn->progress == SEND_RESPONSE) {
|
||||||
|
lseek(conn->fd, 0, SEEK_SET);
|
||||||
while (conn->len > 0) {
|
while (conn->len > 0) {
|
||||||
char buffer[1024];
|
char buff[1024];
|
||||||
size_t readLen = read(conn->fd, buffer, sizeof(buffer));
|
ssize_t readLen = read(conn->fd, buff, sizeof(buff));
|
||||||
if (readLen < 0)
|
if (readLen < 0)
|
||||||
return 1;
|
return 1;
|
||||||
while (readLen > 0) {
|
ssize_t leftToSend = readLen;
|
||||||
|
while (leftToSend > 0) {
|
||||||
size_t writeLen = sendStream(conn->stream,
|
size_t writeLen = sendStream(conn->stream,
|
||||||
buffer, readLen);
|
buff, leftToSend);
|
||||||
if (writeLen < 0)
|
if (writeLen < 0)
|
||||||
return 1;
|
return 1;
|
||||||
readLen -= writeLen;
|
leftToSend -= writeLen;
|
||||||
}
|
}
|
||||||
conn->len -= readLen;
|
conn->len -= readLen;
|
||||||
|
printf("%ld\n", conn->len);
|
||||||
}
|
}
|
||||||
resetConnection(conn);
|
resetConnection(conn);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,11 @@ static int readResponse(Connection *conn, char *path) {
|
|||||||
off_t len = lseek(fd, 0, SEEK_END);
|
off_t len = lseek(fd, 0, SEEK_END);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
goto error;
|
goto error;
|
||||||
lseek(fd, 0, SEEK_SET);
|
if (lseek(fd, 0, SEEK_SET) < 0) {
|
||||||
|
sendErrorResponse(conn, ERROR_500);
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
sendHeader(conn, CODE_200, len);
|
sendHeader(conn, CODE_200, len);
|
||||||
conn->len = len;
|
conn->len = len;
|
||||||
return fd;
|
return fd;
|
||||||
|
|||||||
Reference in New Issue
Block a user