修复发送中途断连空等1s:send等待循环加状态检查,断连立即失败回传CONNRESET
This commit is contained in:
@@ -1184,6 +1184,8 @@ static int net_connect_locked(int sockfd, const struct net_sockaddr *addr, int a
|
||||
* 函数说明:1. 按 NET_SEND_CHUNK_MAX(硬件发送缓冲上限,见 Trap 20)分块写入 CH395F 发送 FIFO
|
||||
* 2. 发送前等待 send_ready 置位,超时返回已发送字节数
|
||||
* 3. 每写完一块等待 SEND_OK 中断(send_ready 清零后重新置位)
|
||||
* 4. 发送中途断连(状态非 ESTABLISHED)→ 立即失败并返回已发字节
|
||||
* (errno=CONNRESET,不再空等超时)
|
||||
*/
|
||||
static int net_send_locked(net_sock_t *p_sock, const void *buf, int len) {
|
||||
int sent = 0;
|
||||
@@ -1209,6 +1211,12 @@ static int net_send_locked(net_sock_t *p_sock, const void *buf, int len) {
|
||||
}
|
||||
|
||||
if (!p_sock->send_ready) {
|
||||
/* 发送中途断连(DISCONNECT/TIMEOUT 已由 net_poll 处理并置状态非 ESTABLISHED):
|
||||
* 立即失败,不再空等满超时(旧行为:白等 1s 后报 TIMEDOUT) */
|
||||
if (p_sock->state != NET_SOCK_STATE_ESTABLISHED) {
|
||||
s_net_errno = NET_ERR_CONNRESET;
|
||||
break;
|
||||
}
|
||||
if (NET_SEND_TIMEOUT_MS > 0 &&
|
||||
(HAL_GetTick() - tick_start) >= NET_SEND_TIMEOUT_MS) {
|
||||
DBG_ERROR("sock%d send stall: send_ready not set (%d/%d)", sockfd, sent, len);
|
||||
@@ -1232,6 +1240,11 @@ static int net_send_locked(net_sock_t *p_sock, const void *buf, int len) {
|
||||
|
||||
tick_start = HAL_GetTick();
|
||||
while (!p_sock->send_ready) {
|
||||
/* 发送中途断连:立即失败(同外层,避免白等超时) */
|
||||
if (p_sock->state != NET_SOCK_STATE_ESTABLISHED) {
|
||||
s_net_errno = NET_ERR_CONNRESET;
|
||||
break;
|
||||
}
|
||||
net_poll();
|
||||
if (NET_SEND_TIMEOUT_MS > 0 &&
|
||||
(HAL_GetTick() - tick_start) >= NET_SEND_TIMEOUT_MS) {
|
||||
|
||||
Reference in New Issue
Block a user