修复Yoda条件(常量右置)与函数定义括号同行

- net_select.c/net_socket.c 共 62 处 Yoda 条件改为常量在右(规范 6.3.1)

- 11 个文件 58 处函数定义左大括号由换行改为与右括号同行(规范 4.4.2)
This commit is contained in:
2026-09-01 16:57:34 +08:00
parent bb76cfd779
commit 02c10fa5ef
13 changed files with 111 additions and 169 deletions
+21 -21
View File
@@ -60,12 +60,12 @@ int net_select(int nfds, net_fd_set_t *readfds, net_fd_set_t *writefds,
int i;
/* 检查输入参数合法性 */
if ((0 >= nfds) || (NET_MAX_SOCKETS < nfds)) {
if ((nfds <= 0) || (nfds > NET_MAX_SOCKETS)) {
return -1;
}
/* 计算超时时间(毫秒) */
if (NULL != timeout) {
if (timeout != NULL) {
timeout_ms = (uint32_t)(timeout->tv_sec * 1000) +
(uint32_t)(timeout->tv_usec / 1000);
}
@@ -80,12 +80,12 @@ int net_select(int nfds, net_fd_set_t *readfds, net_fd_set_t *writefds,
for (i = 0; i < nfds && i < NET_MAX_SOCKETS; i++) {
const net_sock_t *p_sock = net_get_sock(i);
if (NULL == p_sock) {
if (p_sock == NULL) {
continue;
}
/* 检查可读事件 */
if ((NULL != readfds) && NET_FD_ISSET(i, readfds)) {
if ((readfds != NULL) && NET_FD_ISSET(i, readfds)) {
if (check_socket_readable(i)) {
NET_FD_SET(i, &result_read);
ready_count++;
@@ -93,7 +93,7 @@ int net_select(int nfds, net_fd_set_t *readfds, net_fd_set_t *writefds,
}
/* 检查可写事件 */
if ((NULL != writefds) && NET_FD_ISSET(i, writefds)) {
if ((writefds != NULL) && NET_FD_ISSET(i, writefds)) {
if (check_socket_writable(i)) {
NET_FD_SET(i, &result_write);
ready_count++;
@@ -101,7 +101,7 @@ int net_select(int nfds, net_fd_set_t *readfds, net_fd_set_t *writefds,
}
/* 检查异常事件 */
if ((NULL != exceptfds) && NET_FD_ISSET(i, exceptfds)) {
if ((exceptfds != NULL) && NET_FD_ISSET(i, exceptfds)) {
if (check_socket_error(i)) {
NET_FD_SET(i, &result_except);
ready_count++;
@@ -110,13 +110,13 @@ int net_select(int nfds, net_fd_set_t *readfds, net_fd_set_t *writefds,
}
/* 有事件就绪,返回 */
if (0 < ready_count) {
if (ready_count > 0) {
break;
}
/* 超时检测 */
if (NULL != timeout) {
if ((0 < timeout_ms) &&
if (timeout != NULL) {
if ((timeout_ms > 0) &&
((HAL_GetTick() - start_tick) >= timeout_ms)) {
break; /* 超时返回 0 */
}
@@ -127,13 +127,13 @@ int net_select(int nfds, net_fd_set_t *readfds, net_fd_set_t *writefds,
}
/* 复制结果集合 */
if (NULL != readfds) {
if (readfds != NULL) {
readfds->fd_bits = result_read.fd_bits;
}
if (NULL != writefds) {
if (writefds != NULL) {
writefds->fd_bits = result_write.fd_bits;
}
if (NULL != exceptfds) {
if (exceptfds != NULL) {
exceptfds->fd_bits = result_except.fd_bits;
}
@@ -158,7 +158,7 @@ int net_poll_events(net_pollfd_t *fds, int nfds, int timeout) {
int ready = 0;
int i;
if ((NULL == fds) || (0 >= nfds)) {
if ((fds == NULL) || (nfds <= 0)) {
return -1;
}
@@ -172,7 +172,7 @@ int net_poll_events(net_pollfd_t *fds, int nfds, int timeout) {
fds[i].revents = 0;
/* 检查 fd 有效性 */
if ((0 > fds[i].fd) || (NET_MAX_SOCKETS <= fds[i].fd)) {
if ((fds[i].fd < 0) || (fds[i].fd >= NET_MAX_SOCKETS)) {
fds[i].revents |= NET_POLLNVAL;
ready++;
continue;
@@ -180,7 +180,7 @@ int net_poll_events(net_pollfd_t *fds, int nfds, int timeout) {
const net_sock_t *p_sock = net_get_sock(fds[i].fd);
if (NULL == p_sock) {
if (p_sock == NULL) {
fds[i].revents |= NET_POLLNVAL;
ready++;
continue;
@@ -215,12 +215,12 @@ int net_poll_events(net_pollfd_t *fds, int nfds, int timeout) {
}
}
if (0 < ready) {
if (ready > 0) {
break;
}
/* 超时检测 */
if (0 <= timeout) {
if (timeout >= 0) {
if ((HAL_GetTick() - start_tick) >= (uint32_t)timeout) {
break;
}
@@ -250,7 +250,7 @@ static int check_socket_readable(int sockfd) {
const net_sock_t *p_sock;
p_sock = net_get_sock(sockfd);
if (NULL == p_sock) {
if (p_sock == NULL) {
return 0;
}
@@ -280,7 +280,7 @@ static int check_socket_writable(int sockfd) {
const net_sock_t *p_sock;
p_sock = net_get_sock(sockfd);
if (NULL == p_sock) {
if (p_sock == NULL) {
return 0;
}
@@ -307,12 +307,12 @@ static int check_socket_error(int sockfd) {
const net_sock_t *p_sock;
/* 无效 fd 视为错误 */
if ((0 > sockfd) || (NET_MAX_SOCKETS <= sockfd)) {
if ((sockfd < 0) || (sockfd >= NET_MAX_SOCKETS)) {
return 1;
}
p_sock = net_get_sock(sockfd);
if (NULL == p_sock) {
if (p_sock == NULL) {
return 1; /* 未使用的 Socket 视为错误 */
}