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)
|
||||
getResponse(conn, site);
|
||||
if (conn->progress == SEND_RESPONSE) {
|
||||
lseek(conn->fd, 0, SEEK_SET);
|
||||
while (conn->len > 0) {
|
||||
char buffer[1024];
|
||||
size_t readLen = read(conn->fd, buffer, sizeof(buffer));
|
||||
char buff[1024];
|
||||
ssize_t readLen = read(conn->fd, buff, sizeof(buff));
|
||||
if (readLen < 0)
|
||||
return 1;
|
||||
while (readLen > 0) {
|
||||
ssize_t leftToSend = readLen;
|
||||
while (leftToSend > 0) {
|
||||
size_t writeLen = sendStream(conn->stream,
|
||||
buffer, readLen);
|
||||
buff, leftToSend);
|
||||
if (writeLen < 0)
|
||||
return 1;
|
||||
readLen -= writeLen;
|
||||
leftToSend -= writeLen;
|
||||
}
|
||||
conn->len -= readLen;
|
||||
printf("%ld\n", conn->len);
|
||||
}
|
||||
resetConnection(conn);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,11 @@ static int readResponse(Connection *conn, char *path) {
|
||||
off_t len = lseek(fd, 0, SEEK_END);
|
||||
if (len < 0)
|
||||
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);
|
||||
conn->len = len;
|
||||
return fd;
|
||||
|
||||
Reference in New Issue
Block a user