fix(connection): send with bolck flag if conn is bolck

This commit is contained in:
fengzero
2022-07-15 06:48:08 +00:00
parent 4cc5357834
commit 003c31e4a6
4 changed files with 16 additions and 8 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ int modbus_tag_to_point(neu_datatag_t *tag, modbus_point_t *point)
char area = 0;
int n = sscanf(tag->address, "%hhu!%c%hu", &point->slave_id, &area,
&point->start_address);
if (n != 3) {
if (n != 3 || point->start_address == 0) {
return NEU_ERR_TAG_ADDRESS_FORMAT_INVALID;
}
+1 -1
View File
@@ -43,7 +43,7 @@ void modbus_conn_disconnected(void *data, int fd)
struct neu_plugin *plugin = (struct neu_plugin *) data;
(void) fd;
plugin->common.link_state = NEU_NODE_LINK_STATE_CONNECTING;
plugin->common.link_state = NEU_NODE_LINK_STATE_DISCONNECTED;
}
int modbus_send_msg(void *ctx, uint16_t n_byte, uint8_t *bytes)
+4 -4
View File
@@ -90,14 +90,14 @@ static int driver_init(neu_plugin_t *plugin)
static int driver_uninit(neu_plugin_t *plugin)
{
if (plugin->stack) {
modbus_stack_destroy(plugin->stack);
}
if (plugin->conn != NULL) {
neu_conn_destory(plugin->conn);
}
if (plugin->stack) {
modbus_stack_destroy(plugin->stack);
}
neu_event_close(plugin->events);
plog_info(plugin, "node: modbus uninit ok");
+10 -2
View File
@@ -228,7 +228,11 @@ ssize_t neu_conn_send(neu_conn_t *conn, uint8_t *buf, ssize_t len)
break;
case NEU_CONN_TCP_CLIENT:
case NEU_CONN_UDP:
ret = send(conn->fd, buf, len, MSG_NOSIGNAL | MSG_DONTWAIT);
if (conn->block) {
ret = send(conn->fd, buf, len, MSG_NOSIGNAL);
} else {
ret = send(conn->fd, buf, len, MSG_NOSIGNAL | MSG_DONTWAIT);
}
break;
case NEU_CONN_TTY_CLIENT:
ret = write(conn->fd, buf, len);
@@ -472,10 +476,14 @@ static void conn_tcp_server_stop(neu_conn_t *conn)
for (int i = 0; i < conn->param.params.tcp_server.max_link; i++) {
if (conn->tcp_server.clients[i].fd > 0) {
close(conn->tcp_server.clients[i].fd);
conn->tcp_server.clients[i].fd = 0;
}
}
close(conn->fd);
if (conn->fd > 0) {
close(conn->fd);
conn->fd = 0;
}
conn->tcp_server.is_listen = false;
}