[PACKET_IO] fix bug for different file has same time property
This commit is contained in:
10
src/app.toml
10
src/app.toml
@@ -1,7 +1,7 @@
|
||||
[PACKET_IO]
|
||||
# example1:
|
||||
# RUN_MODE="PCAP_LIVE_MODE"
|
||||
# WORKER_THREAD_NUM=10 # Prompt marsio how many threads to start to receive packets
|
||||
# WORKER_THREAD_NUM=10 # Prompt pcap how many threads to start to receive packets
|
||||
# INTERFACE=["eth0", "eth1"]
|
||||
# SNAP_LEN=65535 # default 65535
|
||||
# PROMISC=1 # 0(disable) 1(enable), if enable nic promisc mode, default 0(disable)
|
||||
@@ -14,11 +14,7 @@
|
||||
|
||||
# example3:
|
||||
RUN_MODE="PCAP_FILE_MODE"
|
||||
WORKER_THREAD_NUM=2 # Prompt marsio how many threads to start to receive packets
|
||||
WORKER_THREAD_NUM=2 # Prompt pcap how many threads to start to receive packets
|
||||
PCAP_FILE_PATH="/home/liuwentan/project/stellar/stellar/src/packet_io/test/pcap_sample" # if single file, specify dir+filename; if pcapfile directory, specify dir
|
||||
DELETE_WHEN_DONE=0 # 0(false) 1(true), default 0, if delete it when the pcapfile is processed
|
||||
# BPF_FILTER="port 80 and udp" # default null
|
||||
|
||||
#RUN_MODE="PCAP_LIVE_MODE"
|
||||
#WORKER_THREAD_NUM=3 # Prompt marsio how many threads to start to receive packets
|
||||
#INTERFACE=["eth0"]
|
||||
BPF_FILTER="port 443 and tcp" # default null
|
||||
@@ -98,7 +98,6 @@ static ssize_t init_pcap_file(struct pcap_plain_file_info *pfile_info)
|
||||
}
|
||||
pcap_freecode(&pfile_info->filter);
|
||||
}
|
||||
|
||||
pfile_info->data_link = pcap_datalink(pfile_info->pcap_handle);
|
||||
|
||||
return 0;
|
||||
@@ -166,6 +165,7 @@ static ssize_t pcap_directory_file_init(struct pio_pcap_file_device_context *pfi
|
||||
|
||||
/* init global pending file queue */
|
||||
TAILQ_INIT(&g_pending_file_queue.file_queue_head);
|
||||
g_pending_file_queue.file_queue_len = 0;
|
||||
pthread_mutex_init(&g_pending_file_queue.queue_mutex, nullptr);
|
||||
|
||||
/* pcap file device context mutex init */
|
||||
@@ -479,26 +479,33 @@ static ssize_t pcap_directory_insert_file(struct pending_file *file_to_add)
|
||||
if (TAILQ_EMPTY(&g_pending_file_queue.file_queue_head)) {
|
||||
TAILQ_INSERT_TAIL(&g_pending_file_queue.file_queue_head, file_to_add, next);
|
||||
} else {
|
||||
/* pending file queue is not empty */
|
||||
struct pending_file *file_to_compare = TAILQ_FIRST(&g_pending_file_queue.file_queue_head);
|
||||
/* pending file queue is not empty, traverse queue to filter if same file has been added */
|
||||
struct pending_file *file_to_compare;
|
||||
TAILQ_FOREACH(file_to_compare, &g_pending_file_queue.file_queue_head, next) {
|
||||
if (strcmp(file_to_compare->file_name, file_to_add->file_name) == 0) {
|
||||
pthread_mutex_unlock(&g_pending_file_queue.queue_mutex);
|
||||
FREE(file_to_add);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* add new file to pending file queue */
|
||||
file_to_compare = TAILQ_FIRST(&g_pending_file_queue.file_queue_head);
|
||||
while (file_to_compare != nullptr) {
|
||||
if (compare_timespec(&file_to_add->modified_time, &file_to_compare->modified_time) < 0) {
|
||||
TAILQ_INSERT_BEFORE(file_to_compare, file_to_add, next);
|
||||
file_to_compare = nullptr;
|
||||
} else if (compare_timespec(&file_to_add->modified_time, &file_to_compare->modified_time) > 0) {
|
||||
} else {
|
||||
struct pending_file *next_file_to_compare = TAILQ_NEXT(file_to_compare, next);
|
||||
if (next_file_to_compare == nullptr) {
|
||||
TAILQ_INSERT_AFTER(&g_pending_file_queue.file_queue_head, file_to_compare, file_to_add, next);
|
||||
}
|
||||
file_to_compare = next_file_to_compare;
|
||||
} else {
|
||||
/* find same file, ignore it */
|
||||
printf("find same file\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_pending_file_queue.file_queue_len++;
|
||||
log_debug("the num of pending file in queue: %u", g_pending_file_queue.file_queue_len);
|
||||
pthread_mutex_unlock(&g_pending_file_queue.queue_mutex);
|
||||
|
||||
return 0;
|
||||
@@ -732,7 +739,6 @@ static ssize_t pcap_directory_collect_pending_files(struct pio_pcap_file_device_
|
||||
|
||||
if (pcap_directory_insert_file(file_to_add) < 0) {
|
||||
log_error(ST_ERR_PCAP_FILE_COLLECT_FAILED, "failed to insert file into directory");
|
||||
FREE(file_to_add);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ struct pending_file {
|
||||
|
||||
struct safe_pending_file_queue {
|
||||
TAILQ_HEAD(pending_file_queue, pending_file) file_queue_head;
|
||||
uint32_t file_queue_len;
|
||||
pthread_mutex_t queue_mutex;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user