Closed dongdan002 closed 1 year ago
sendSock在发送的时候设置try_flush为false,消息发送不出去。
This is expected behavior. It is designed this way. Users need to call the flushAll interface again.
sendSock在发送的时候设置try_flush为false,消息发送不出去。
这是预期行为 就是这么设计的 用户需要再调一次flushAll接口才行
TRANS_BY_GITHUB_AI_ASSISTANT
The initial design was intended for batch sending to improve performance.
这样设计的初衷是批量发送提高性能
TRANS_BY_GITHUB_AI_ASSISTANT
Okay, I understand. Thanks for the explanation.
好的,了解了,多谢解答
TRANS_BY_GITHUB_AI_ASSISTANT
In the test code
test_udpSock.cpp
,sendSock
setstry_flush
tofalse
when sending, and the message cannot be sent out.// Send data to the other party every second // sockSend->send(to_string(i++), (struct sockaddr )&addrDst); // Modify to non-forced flush try_flush = false; sockSend->send(to_string(i++), (struct sockaddr )&addrDst, 0, try_flush);
The reason is: When the send buffer is empty, the poller thread will modify the listening fd, turn off writing,, so we don't need to add it again
startWriteAbleEvent(sock);
}
stopWriteAbleEvent()
. However,startWriteAbleEvent()
is only triggered in non-poller threads, and there are no other operations to modify the fd event. This leads to no write event for the fd in the select. if (!poller_thread) { @mtdxc // If this function is triggered by the poller thread, then this socket should have been added to the listening of writable events//每隔一秒往对方发送数据 // sockSend->send(to_string(i++), (struct sockaddr )&addrDst); //修改为非强制刷新 try_flush = false; sockSend->send(to_string(i++), (struct sockaddr )&addrDst, 0, try_flush);
原因为: 当发送缓冲区为空的时候,poller线程会修改监听fd,关掉写,stopWriteAbleEvent() 但是startWriteAbleEvent()只会在非poller线程中触发,又没有其他操作来修改fd的event。导致在select时候,fd没有write事件 if (!poller_thread) { @mtdxc // 如果该函数是poller线程触发的,那么该socket应该已经加入了可写事件的监听<实际并没有加进去>,所以我们不需要再次加入监听 startWriteAbleEvent(sock); }
TRANS_BY_GITHUB_AI_ASSISTANT