From 8a8fae0dbbdead7d3acd87334fd8cd7289dc1022 Mon Sep 17 00:00:00 2001 From: moret Date: Fri, 25 Jul 2008 14:05:30 +0000 Subject: [PATCH] Switch to better network error management in realtime process git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2741 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackNetDriver.cpp | 8 +++++--- common/JackNetManager.cpp | 21 ++++++++++++++------- common/JackNetManager.h | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/common/JackNetDriver.cpp b/common/JackNetDriver.cpp index ecfff43d..62ae13d1 100644 --- a/common/JackNetDriver.cpp +++ b/common/JackNetDriver.cpp @@ -482,7 +482,7 @@ namespace Jack if ( rx_bytes == SOCKET_ERROR ) { net_error_t error = fSocket.GetError(); - //just tell there is no data and return 0 instead of SOCKET_ERROR + //no data isn't really an error in realtime processing, so just return 0 if ( error == NET_NO_DATA ) { jack_error ( "No data, is the master still running ?" ); @@ -492,7 +492,7 @@ namespace Jack else if ( error == NET_CONN_ERROR ) throw JackDriverException ( "Connection lost." ); else - jack_error ( "Error in receive : %s", StrError ( NET_ERROR_CODE ) ); + jack_error ( "Fatal error in receive : %s", StrError ( NET_ERROR_CODE ) ); } return rx_bytes; } @@ -508,7 +508,7 @@ namespace Jack if ( error == NET_CONN_ERROR ) throw JackDriverException ( "Connection lost." ); else - jack_error ( "Error in send : %s", StrError ( NET_ERROR_CODE ) ); + jack_error ( "Fatal error in send : %s", StrError ( NET_ERROR_CODE ) ); } return tx_bytes; } @@ -621,6 +621,8 @@ namespace Jack memset ( fTxData, 0, fPayloadSize ); SetSyncPacket(); tx_bytes = Send ( fParams.fMtu, 0 ); + if ( tx_bytes == SOCKET_ERROR ) + return 0; #ifdef JACK_MONITOR fMeasure[fMeasureId++] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f; diff --git a/common/JackNetManager.cpp b/common/JackNetManager.cpp index 920e5ac8..07cfbe74 100644 --- a/common/JackNetManager.cpp +++ b/common/JackNetManager.cpp @@ -345,6 +345,8 @@ namespace Jack } else jack_error ( "Error in send : %s", StrError ( NET_ERROR_CODE ) ); + //we can't stop the process here, the slave wouldn't see what happens, just return 0 + return 0; } return tx_bytes; } @@ -357,24 +359,27 @@ namespace Jack net_error_t error = fSocket.GetError(); if ( error == NET_NO_DATA ) { - //too much receive failure, exit + //too much receive failure, react if ( ++fNetJumpCnt == 100 ) { jack_error ( "No data from %s...", fParams.fName ); fNetJumpCnt = 0; } - //we don't want the process to stop here, so just return 0 - return 0; } else if ( error == NET_CONN_ERROR ) { //fatal connection issue, exit jack_error ( "'%s' : %s, network connection with '%s' broken, exiting.", - fParams.fName, StrError ( NET_ERROR_CODE ), fParams.fSlaveNetName ); + fParams.fName, StrError ( NET_ERROR_CODE ), fParams.fSlaveNetName ); + //ask to the manager to properly remove the master Exit(); } else jack_error ( "Error in receive : %s", StrError ( NET_ERROR_CODE ) ); + //if we stop the process now, the socket will be closed and deleted to prematurely + //so the slave won't see the connection is down - just return 0, thus the master's process don't stop now + //by this way, the slave will have enough time to get the ICMP "connection refused" msg + return 0; } return rx_bytes; } @@ -690,8 +695,8 @@ namespace Jack jack_info ( "Waiting for a slave..." ); break; case KILL_MASTER: - KillMaster ( ¶ms ); - jack_info ( "Waiting for a slave..." ); + if ( KillMaster ( ¶ms ) ) + jack_info ( "Waiting for a slave..." ); break; default: break; @@ -751,7 +756,7 @@ namespace Jack return it; } - void JackNetMasterManager::KillMaster ( session_params_t* params ) + int JackNetMasterManager::KillMaster ( session_params_t* params ) { jack_log ( "JackNetMasterManager::KillMaster, ID %u.", params->fID ); master_list_it_t master = FindMaster ( params->fID ); @@ -759,7 +764,9 @@ namespace Jack { fMasterList.erase ( master ); delete *master; + return 1; } + return 0; } }//namespace diff --git a/common/JackNetManager.h b/common/JackNetManager.h index 077e8c06..117cb3d7 100644 --- a/common/JackNetManager.h +++ b/common/JackNetManager.h @@ -127,7 +127,7 @@ namespace Jack void Run(); JackNetMaster* MasterInit ( session_params_t& params ); master_list_it_t FindMaster ( uint32_t client_id ); - void KillMaster ( session_params_t* params ); + int KillMaster ( session_params_t* params ); void SetSlaveName ( session_params_t& params ); int SyncCallback ( jack_transport_state_t state, jack_position_t* pos );