|
|
|
@ -39,12 +39,15 @@ void transportSerial::m_fThreadAProc( void ){ |
|
|
|
LOG("Buffer ready to Send"); |
|
|
|
#endif
|
|
|
|
while( (index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED) ){ |
|
|
|
RetVal = sendBlock( m_pOutputBuffer + index, m_nOutputBufferSize - index ); |
|
|
|
if( RetVal > 0 ) index += RetVal; |
|
|
|
if (RetVal < 0) { |
|
|
|
setConnectionStatus(CS_DISCONNECTED); |
|
|
|
m_bThreadAStatus = TH_ENDED; |
|
|
|
}; |
|
|
|
if ( m_mIsBusy.try_lock() ) { |
|
|
|
RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index); |
|
|
|
m_mIsBusy.unlock(); |
|
|
|
if( RetVal > 0 ) index += RetVal; |
|
|
|
if (RetVal < 0) { |
|
|
|
setConnectionStatus(CS_DISCONNECTED); |
|
|
|
m_bThreadAStatus = TH_ENDED; |
|
|
|
}; |
|
|
|
} else SLEEP( 3 ); |
|
|
|
}; |
|
|
|
#ifdef DEBUG_COMMUNICATION
|
|
|
|
LOG("Buffer is Sent"); |
|
|
|
@ -68,27 +71,30 @@ void transportSerial::m_fThreadBProc(void){ |
|
|
|
LOG("Input Thread Started"); |
|
|
|
#endif
|
|
|
|
while (m_bThreadBStatus < TH_ENDED) { |
|
|
|
int retVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize ); |
|
|
|
if (retVal < 0) { |
|
|
|
setConnectionStatus(CS_DISCONNECTED); |
|
|
|
m_bThreadBStatus = TH_ENDED; |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
if (m_nInputBufferSize > 0 && m_bThreadBStatus == TH_WORKING) { |
|
|
|
m_mQueueProtectorMutex.lock(); |
|
|
|
for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++) { |
|
|
|
if (m_bThreadBStatus == TH_WORKING) { |
|
|
|
(*index)->parse(m_pInputBuffer, m_nInputBufferSize); |
|
|
|
} |
|
|
|
}; |
|
|
|
m_mQueueProtectorMutex.unlock(); |
|
|
|
nSleepTime = 1; |
|
|
|
} else { |
|
|
|
nSleepTime = 10; |
|
|
|
if( m_bThreadBStatus != TH_WORKING ) continue; |
|
|
|
}; |
|
|
|
}; |
|
|
|
SLEEP( nSleepTime ); |
|
|
|
if ( m_mIsBusy.try_lock() ) { |
|
|
|
int retVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize ); |
|
|
|
m_mIsBusy.unlock(); |
|
|
|
if (retVal < 0) { |
|
|
|
setConnectionStatus(CS_DISCONNECTED); |
|
|
|
m_bThreadBStatus = TH_ENDED; |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
if (m_nInputBufferSize > 0 && m_bThreadBStatus == TH_WORKING) { |
|
|
|
m_mQueueProtectorMutex.lock(); |
|
|
|
for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++) { |
|
|
|
if (m_bThreadBStatus == TH_WORKING) { |
|
|
|
(*index)->parse(m_pInputBuffer, m_nInputBufferSize); |
|
|
|
} |
|
|
|
}; |
|
|
|
m_mQueueProtectorMutex.unlock(); |
|
|
|
nSleepTime = 1; |
|
|
|
} else { |
|
|
|
nSleepTime = 10; |
|
|
|
if( m_bThreadBStatus != TH_WORKING ) continue; |
|
|
|
}; |
|
|
|
}; |
|
|
|
SLEEP( nSleepTime ); |
|
|
|
} else SLEEP( 3 ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|