Skip to content

Commit

Permalink
Fix issue of it sometimes crashed when cycle read datatag in modbus t…
Browse files Browse the repository at this point in the history
…cp plugin
  • Loading branch information
flyfish30 committed Dec 17, 2021
1 parent 4241829 commit a708814
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugins/modbus/modbus_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ static void start_periodic_read(neu_plugin_t * plugin,
neu_datatag_id_t *id = (neu_datatag_id_t *) iterator_get(&iter);
neu_datatag_t * tag = neu_datatag_tbl_get(plugin->tag_table, *id);

if (tag == NULL) {
// The tag had been deleted by other node
continue;
}
if ((tag->attribute & NEU_ATTRIBUTE_READ) == NEU_ATTRIBUTE_READ) {
switch (tag->type) {
case NEU_DTYPE_UINT16:
Expand Down Expand Up @@ -199,6 +203,11 @@ setup_read_resp_data_value(neu_datatag_table_t * tag_table,
int result = 0;
neu_int_val_t int_val = { 0 };

if (tag == NULL) {
// The tag had been deleted by other node
continue;
}

if ((tag->attribute & NEU_ATTRIBUTE_READ) == NEU_ATTRIBUTE_READ) {
switch (tag->type) {
case NEU_DTYPE_UINT32:
Expand Down Expand Up @@ -343,6 +352,16 @@ static neu_data_val_t *setup_write_resp_data_value(neu_data_val_t *write_val,
neu_datatag_t * tag =
neu_datatag_tbl_get(plugin->tag_table, int_val->key);

if (tag == NULL) {
// The tag had been deleted by other node
error = NEU_ERR_TAG_NOT_EXIST;
neu_dvalue_set_errorcode(val_error, error);

neu_int_val_init(&iv, int_val->key, val_error);
neu_fixed_array_set(array_resp, i, (void *) &iv);
continue;
}

switch (val_type) {
case NEU_DTYPE_INT64: {
int64_t i64 = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/base/neu_plugin_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ int neu_plugin_tag_count_by_attribute(neu_taggrp_config_t *grp_config,
{
neu_datatag_id_t *id = (neu_datatag_id_t *) iterator_get(&iter_id);
neu_datatag_t * tag = neu_datatag_tbl_get(tag_table, *id);
if (tag == NULL) {
// The tag had been deleted by other node
continue;
}
if ((tag->attribute & attribute) == attribute) {
count += 1;
}
Expand Down

0 comments on commit a708814

Please sign in to comment.