mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-21 08:49:25 +00:00
esp_http_server/lru_counter_for_timestamp:Added LRU counter for timer
Replaced the os timer in http server by LRU counter. The timestamp is unnecessary for LRU.
This commit is contained in:
@@ -195,6 +195,12 @@ static int fd_is_valid(int fd)
|
||||
return fcntl(fd, F_GETFD) != -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)
|
||||
{
|
||||
for (int i = 0; i < hd->config.max_open_sockets; i++) {
|
||||
@@ -297,11 +303,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 +318,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 +327,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 +338,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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user