mirror of
https://github.com/morgan9e/UxPlay
synced 2026-04-15 00:34:05 +09:00
httpd:c cleanup use of "ret": fixes #508
This commit is contained in:
29
lib/httpd.c
29
lib/httpd.c
@@ -349,7 +349,7 @@ httpd_thread(void *arg)
|
|||||||
char http[] = "HTTP/1.1";
|
char http[] = "HTTP/1.1";
|
||||||
char event[] = "EVENT/1.0";
|
char event[] = "EVENT/1.0";
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
int i;
|
int i = 0;
|
||||||
|
|
||||||
bool logger_debug = (logger_get_level(httpd->logger) >= LOGGER_DEBUG);
|
bool logger_debug = (logger_get_level(httpd->logger) >= LOGGER_DEBUG);
|
||||||
assert(httpd);
|
assert(httpd);
|
||||||
@@ -358,8 +358,9 @@ httpd_thread(void *arg)
|
|||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int nfds=0;
|
int nfds=0;
|
||||||
int ret;
|
int ret = 0;
|
||||||
int new_request;
|
int new_request = 0;
|
||||||
|
int recv_datalen = 0;
|
||||||
|
|
||||||
MUTEX_LOCK(httpd->run_mutex);
|
MUTEX_LOCK(httpd->run_mutex);
|
||||||
if (!httpd->running) {
|
if (!httpd->running) {
|
||||||
@@ -413,7 +414,7 @@ httpd_thread(void *arg)
|
|||||||
|
|
||||||
if (httpd->open_connections < httpd->max_connections &&
|
if (httpd->open_connections < httpd->max_connections &&
|
||||||
httpd->server_fd4 != -1 && FD_ISSET(httpd->server_fd4, &rfds)) {
|
httpd->server_fd4 != -1 && FD_ISSET(httpd->server_fd4, &rfds)) {
|
||||||
ret = httpd_accept_connection(httpd, httpd->server_fd4, 0);
|
int ret = httpd_accept_connection(httpd, httpd->server_fd4, 0);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
logger_log(httpd->logger, LOGGER_ERR, "httpd error in accept ipv4");
|
logger_log(httpd->logger, LOGGER_ERR, "httpd error in accept ipv4");
|
||||||
break;
|
break;
|
||||||
@@ -423,7 +424,7 @@ httpd_thread(void *arg)
|
|||||||
}
|
}
|
||||||
if (httpd->open_connections < httpd->max_connections &&
|
if (httpd->open_connections < httpd->max_connections &&
|
||||||
httpd->server_fd6 != -1 && FD_ISSET(httpd->server_fd6, &rfds)) {
|
httpd->server_fd6 != -1 && FD_ISSET(httpd->server_fd6, &rfds)) {
|
||||||
ret = httpd_accept_connection(httpd, httpd->server_fd6, 1);
|
int ret = httpd_accept_connection(httpd, httpd->server_fd6, 1);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
logger_log(httpd->logger, LOGGER_ERR, "httpd error in accept ipv6");
|
logger_log(httpd->logger, LOGGER_ERR, "httpd error in accept ipv6");
|
||||||
break;
|
break;
|
||||||
@@ -484,7 +485,7 @@ httpd_thread(void *arg)
|
|||||||
if (!connection->socket_fd) {
|
if (!connection->socket_fd) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ret = recv(connection->socket_fd, buffer + readstart, sizeof(buffer) - readstart, 0);
|
int ret = recv(connection->socket_fd, buffer + readstart, sizeof(buffer) - readstart, 0);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
logger_log(httpd->logger, LOGGER_DEBUG, "client closed connection on socket %d",
|
logger_log(httpd->logger, LOGGER_DEBUG, "client closed connection on socket %d",
|
||||||
connection->socket_fd);
|
connection->socket_fd);
|
||||||
@@ -498,7 +499,7 @@ httpd_thread(void *arg)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
readstart += ret;
|
readstart += ret;
|
||||||
ret = readstart;
|
recv_datalen = readstart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!connection->socket_fd) {
|
if (!connection->socket_fd) {
|
||||||
@@ -510,7 +511,7 @@ httpd_thread(void *arg)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (connection->socket_fd) {
|
if (connection->socket_fd) {
|
||||||
ret = recv(connection->socket_fd, buffer, sizeof(buffer), 0);
|
int ret = recv(connection->socket_fd, buffer, sizeof(buffer), 0);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
httpd_remove_connection(httpd, connection, 0);
|
httpd_remove_connection(httpd, connection, 0);
|
||||||
continue;
|
continue;
|
||||||
@@ -521,6 +522,8 @@ httpd_thread(void *arg)
|
|||||||
httpd_remove_connection(httpd, connection, SOCKET_GET_ERROR());
|
httpd_remove_connection(httpd, connection, SOCKET_GET_ERROR());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
recv_datalen = ret;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* connection was recently removed */
|
/* connection was recently removed */
|
||||||
@@ -530,22 +533,22 @@ httpd_thread(void *arg)
|
|||||||
if (http_request_is_reverse(connection->request)) {
|
if (http_request_is_reverse(connection->request)) {
|
||||||
/* this is a response from the client to a
|
/* this is a response from the client to a
|
||||||
* GET /event reverse HTTP request from the server */
|
* GET /event reverse HTTP request from the server */
|
||||||
if (ret && logger_debug) {
|
if (recv_datalen && logger_debug) {
|
||||||
buffer[ret] = '\0';
|
buffer[recv_datalen] = '\0';
|
||||||
logger_log(httpd->logger, LOGGER_INFO, "<<<< received response from client"
|
logger_log(httpd->logger, LOGGER_INFO, "<<<< received response from client"
|
||||||
" (reversed HTTP = \"PTTH/1.0\") connection"
|
" (reversed HTTP = \"PTTH/1.0\") connection"
|
||||||
" on socket %d:\n%s\n", connection->socket_fd, buffer);
|
" on socket %d:\n%s\n", connection->socket_fd, buffer);
|
||||||
}
|
}
|
||||||
if (ret == 0) {
|
if (recv_datalen == 0) {
|
||||||
httpd_remove_connection(httpd, connection, 0);
|
httpd_remove_connection(httpd, connection, 0);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse HTTP request from data read from connection */
|
/* Parse HTTP request from data read from connection */
|
||||||
http_request_add_data(connection->request, buffer, ret);
|
http_request_add_data(connection->request, buffer, recv_datalen);
|
||||||
if (http_request_has_error(connection->request)) {
|
if (http_request_has_error(connection->request)) {
|
||||||
char *data = utils_data_to_text((const char *) buffer, ret);
|
char *data = utils_data_to_text((const char *) buffer, recv_datalen);
|
||||||
logger_log(httpd->logger, LOGGER_ERR, "httpd error in parsing: %s\n%s\n%s",
|
logger_log(httpd->logger, LOGGER_ERR, "httpd error in parsing: %s\n%s\n%s",
|
||||||
http_request_get_error_name(connection->request),
|
http_request_get_error_name(connection->request),
|
||||||
http_request_get_error_description(connection->request),
|
http_request_get_error_description(connection->request),
|
||||||
|
|||||||
Reference in New Issue
Block a user