mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 15:09:23 +08:00
Handle failed writes cleanly.
This commit is contained in:
23
DMRIPSC.cpp
23
DMRIPSC.cpp
@@ -272,8 +272,15 @@ bool CDMRIPSC::write(const CDMRData& data)
|
|||||||
if (m_debug)
|
if (m_debug)
|
||||||
CUtils::dump(1U, "IPSC Transmitted", buffer, HOMEBREW_DATA_PACKET_LENGTH);
|
CUtils::dump(1U, "IPSC Transmitted", buffer, HOMEBREW_DATA_PACKET_LENGTH);
|
||||||
|
|
||||||
for (unsigned int i = 0U; i < count; i++)
|
for (unsigned int i = 0U; i < count; i++) {
|
||||||
write(buffer, HOMEBREW_DATA_PACKET_LENGTH);
|
bool ret = write(buffer, HOMEBREW_DATA_PACKET_LENGTH);
|
||||||
|
if (!ret) {
|
||||||
|
LogError("Socket has failed when writing data to the master, retrying connection");
|
||||||
|
close();
|
||||||
|
open();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -282,10 +289,12 @@ void CDMRIPSC::close()
|
|||||||
{
|
{
|
||||||
LogMessage("Closing DMR IPSC");
|
LogMessage("Closing DMR IPSC");
|
||||||
|
|
||||||
unsigned char buffer[9U];
|
if (m_status == RUNNING) {
|
||||||
::memcpy(buffer + 0U, "RPTCL", 5U);
|
unsigned char buffer[9U];
|
||||||
::memcpy(buffer + 5U, m_id, 4U);
|
::memcpy(buffer + 0U, "RPTCL", 5U);
|
||||||
write(buffer, 9U);
|
::memcpy(buffer + 5U, m_id, 4U);
|
||||||
|
write(buffer, 9U);
|
||||||
|
}
|
||||||
|
|
||||||
m_socket.close();
|
m_socket.close();
|
||||||
}
|
}
|
||||||
@@ -296,7 +305,7 @@ void CDMRIPSC::clock(unsigned int ms)
|
|||||||
unsigned int port;
|
unsigned int port;
|
||||||
int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, port);
|
int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, port);
|
||||||
if (length < 0) {
|
if (length < 0) {
|
||||||
LogError("Socket has failed, retrying connection");
|
LogError("Socket has failed, retrying connection to the master");
|
||||||
close();
|
close();
|
||||||
open();
|
open();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user