feature/esp_http_server_idf_v3.2:Changes to make esp_http_server compatible with ESP8266.

Changes:
Lru counter in place of timestamp added.
syslimits.h definition guards for ARG_MAX, PATH_LEN.
Renamed src/port/esp32 to src/port/esp8266.
Enabled working without IPv6. Test Scripts requiring TinyFW removed
Utility.console_log replaced by print.
This commit is contained in:
Supreet Deshpande
2019-02-18 15:07:09 +05:30
parent 825a53199d
commit efc81a6649
12 changed files with 136 additions and 426 deletions

View File

@ -125,7 +125,7 @@ struct sock_db {
httpd_send_func_t send_fn; /*!< Send function for this socket */
httpd_recv_func_t recv_fn; /*!< Receive function for this socket */
httpd_pending_func_t pending_fn; /*!< Pending function for this socket */
int64_t timestamp; /*!< Timestamp indicating when the socket was last used */
uint64_t lru_counter; /*!< LRU Counter indicating when the socket was last used */
char pending_data[PARSER_BLOCK_SIZE]; /*!< Buffer for pending data to be received */
size_t pending_len; /*!< Length of pending data to be received */
};

View File

@ -236,19 +236,32 @@ static void httpd_thread(void *arg)
static esp_err_t httpd_server_init(struct httpd_data *hd)
{
#ifdef CONFIG_LWIP_IPV6
int fd = socket(PF_INET6, SOCK_STREAM, 0);
#else
int fd = socket(PF_INET, SOCK_STREAM, 0);
#endif /* CONFIG_LWIP_IPV6 */
if (fd < 0) {
ESP_LOGE(TAG, LOG_FMT("error in socket (%d)"), errno);
return ESP_FAIL;
}
#ifdef CONFIG_LWIP_IPV6
struct in6_addr inaddr_any = IN6ADDR_ANY_INIT;
struct sockaddr_in6 serv_addr = {
.sin6_family = PF_INET6,
.sin6_addr = inaddr_any,
.sin6_port = htons(hd->config.server_port)
};
#else
struct sockaddr_in serv_addr = {
.sin_family = PF_INET,
.sin_addr = {
.s_addr = htonl(INADDR_ANY)
},
.sin_port = htons(hd->config.server_port)
};
#endif /* CONFIG_LWIP_IPV6 */
int ret = bind(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
if (ret < 0) {
ESP_LOGE(TAG, LOG_FMT("error in bind (%d)"), errno);

View File

@ -19,6 +19,7 @@
#include <esp_http_server.h>
#include "esp_httpd_priv.h"
#include <sys/fcntl.h>
static const char *TAG = "httpd_sess";
@ -192,7 +193,13 @@ void httpd_sess_set_descriptors(struct httpd_data *hd,
/** Check if a FD is valid */
static int fd_is_valid(int fd)
{
return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
return fcntl(fd, F_GETFD, 0) != -1 || errno != EBADF;
}
static inline uint64_t httpd_sess_get_lru_counter()
{
static uint64_t lru_counter = 0;
return lru_counter++;
}
void httpd_sess_delete_invalid(struct httpd_data *hd)
@ -297,11 +304,11 @@ esp_err_t httpd_sess_process(struct httpd_data *hd, int newfd)
return ESP_FAIL;
}
ESP_LOGD(TAG, LOG_FMT("success"));
sd->timestamp = httpd_os_get_timestamp();
sd->lru_counter = httpd_sess_get_lru_counter();
return ESP_OK;
}
esp_err_t httpd_sess_update_timestamp(httpd_handle_t handle, int sockfd)
esp_err_t httpd_sess_update_lru_counter(httpd_handle_t handle, int sockfd)
{
if (handle == NULL) {
return ESP_ERR_INVALID_ARG;
@ -312,7 +319,7 @@ esp_err_t httpd_sess_update_timestamp(httpd_handle_t handle, int sockfd)
int i;
for (i = 0; i < hd->config.max_open_sockets; i++) {
if (hd->hd_sd[i].fd == sockfd) {
hd->hd_sd[i].timestamp = httpd_os_get_timestamp();
hd->hd_sd[i].lru_counter = httpd_sess_get_lru_counter();
return ESP_OK;
}
}
@ -321,7 +328,7 @@ esp_err_t httpd_sess_update_timestamp(httpd_handle_t handle, int sockfd)
esp_err_t httpd_sess_close_lru(struct httpd_data *hd)
{
int64_t timestamp = INT64_MAX;
uint64_t lru_counter = UINT64_MAX;
int lru_fd = -1;
int i;
for (i = 0; i < hd->config.max_open_sockets; i++) {
@ -332,8 +339,8 @@ esp_err_t httpd_sess_close_lru(struct httpd_data *hd)
if (hd->hd_sd[i].fd == -1) {
return ESP_OK;
}
if (hd->hd_sd[i].timestamp < timestamp) {
timestamp = hd->hd_sd[i].timestamp;
if (hd->hd_sd[i].lru_counter < lru_counter) {
lru_counter = hd->hd_sd[i].lru_counter;
lru_fd = hd->hd_sd[i].fd;
}
}

View File

@ -52,11 +52,6 @@ static inline void httpd_os_thread_sleep(int msecs)
vTaskDelay(msecs / portTICK_RATE_MS);
}
static inline int64_t httpd_os_get_timestamp()
{
return esp_timer_get_time();
}
static inline othread_t httpd_os_thread_handle()
{
return xTaskGetCurrentTaskHandle();