Skip to content

Commit

Permalink
tcp/ip client is disconnected after 12 hours of inactivity. rcvloop c…
Browse files Browse the repository at this point in the history
…lients does not have this limit.
  • Loading branch information
grodansparadis committed Aug 20, 2018
1 parent a09762a commit 44b1b7f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions m4/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ distclean-generic:
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."

clean: clean-am

clean-am: clean-generic mostlyclean-am
Expand Down
5 changes: 4 additions & 1 deletion src/vscp/common/clientlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,11 @@ class CClientItem
// Used by TCP/IP client thread
//////////////////////////////////////////////////////////////////////////

// UTC time since last client activity
long m_clientActivity;

/*!
RCVLOOP clock
RCVLOOP clock (UTC time for last sent "+OK")
*/
wxLongLong m_timeRcvLoop;

Expand Down
18 changes: 18 additions & 0 deletions src/vscp/common/tcpipsrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@

WX_DEFINE_LIST( TCPIPCLIENTS );

#define TCPIPSRV_INACTIVITY_TIMOUT (3600 * 12)




///////////////////////////////////////////////////
// GLOBALS
///////////////////////////////////////////////////
Expand Down Expand Up @@ -409,6 +414,9 @@ void *TCPClientThread::Entry()
m_pClientItem->m_strDeviceName += _(" ");
m_pClientItem->m_strDeviceName += wxDateTime::Now().FormatISOTime();

// Start of activity
m_pClientItem->m_clientActivity = wxGetUTCTime();

// Add the client to the Client List
gpobj->m_wxClientMutex.Lock();
gpobj->addClient( m_pClientItem );
Expand Down Expand Up @@ -436,6 +444,12 @@ void *TCPClientThread::Entry()
struct pollfd fd;
while ( !TestDestroy() && !(gpobj->m_StopTcpIpSrv ) ) {

// Check for client inactivity
if ( ( wxGetUTCTime() - m_pClientItem->m_clientActivity ) > TCPIPSRV_INACTIVITY_TIMOUT ) {
gpobj->logMsg( _("[TCP/IP srv client thread] Client closed due to inactivity.\n") );
break;
}

// * * * Receiveloop * * *
if ( m_bReceiveLoop ) {

Expand All @@ -449,6 +463,7 @@ void *TCPClientThread::Entry()
// link is open
if ( ( wxGetUTCTime()-m_pClientItem->m_timeRcvLoop ) > 2 ) {
m_pClientItem->m_timeRcvLoop = wxGetUTCTime();
m_pClientItem->m_clientActivity = wxGetUTCTime();
write( "+OK\r\n", 5 );
}

Expand Down Expand Up @@ -499,6 +514,9 @@ void *TCPClientThread::Entry()
else if ( nRead > 0 ) {
m_strResponse += wxString::FromUTF8Unchecked( buf, nRead );
}

// Record client activity
m_pClientItem->m_clientActivity = wxGetUTCTime();

// get data up to "\r\n" if any
int pos;
Expand Down

0 comments on commit 44b1b7f

Please sign in to comment.