ENH:Add logging to the send function and optimize the connection process

jira: [STUDIO-11777]

Change-Id: Idac7b7835f13ec1805442a8c8aefbb35786c36ef
(cherry picked from commit 6c07f1b9a2858a9ab0c52330f78224a03ffb6f0c)
This commit is contained in:
milk
2025-05-13 20:34:27 +08:00
committed by Noisyfox
parent f0825f2c2d
commit 6bd99609d8
2 changed files with 87 additions and 15 deletions

View File

@@ -1533,6 +1533,8 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
m_messages.clear();
if (result)
m_cond.timed_wait(l, boost::posix_time::seconds(10));
while (true) {
while (m_stopped) {
if (m_session.owner == nullptr)
@@ -1569,14 +1571,24 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
Bambu_SetLogger(tunnel, DumpLog, this);
ret = Bambu_Open(tunnel);
}
if (ret == 0)
do {
ret = Bambu_StartStreamEx
? Bambu_StartStreamEx(tunnel, CTRL_TYPE)
: Bambu_StartStream(tunnel, false);
if (ret == Bambu_would_block) {}
{
auto start_time = boost::posix_time::microsec_clock::universal_time();
boost::posix_time::time_duration timeout = boost::posix_time::seconds(3);
do{
ret = Bambu_StartStreamEx ? Bambu_StartStreamEx(tunnel, CTRL_TYPE) : Bambu_StartStream(tunnel, false);
if (ret == Bambu_would_block)
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
auto now = boost::posix_time::microsec_clock::universal_time();
if (now - start_time > timeout) {
BOOST_LOG_TRIVIAL(warning) << "StartStream timeout after 5 seconds.";
break;
}
} while (ret == Bambu_would_block && !m_stopped);
}
l.lock();
if (ret == 0) {
m_session.tunnel = tunnel;