Browse Source

Improve network error management

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2739 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.90
moret 17 years ago
parent
commit
5df211a245
2 changed files with 24 additions and 23 deletions
  1. +16
    -14
      common/JackNetDriver.cpp
  2. +8
    -9
      common/JackNetManager.cpp

+ 16
- 14
common/JackNetDriver.cpp View File

@@ -477,34 +477,34 @@ namespace Jack

int JackNetDriver::Recv ( size_t size, int flags )
{
int rx_bytes;
if ( ( rx_bytes = fSocket.Recv ( fRxBuffer, size, flags ) ) == SOCKET_ERROR )
int rx_bytes = fSocket.Recv ( fRxBuffer, size, flags );
//handle errors
if ( rx_bytes == SOCKET_ERROR )
{
net_error_t error = fSocket.GetError();
//just tell there is no data and return 0 instead of SOCKET_ERROR
if ( error == NET_NO_DATA )
{
jack_error ( "No incoming data, is the master still running ?" );
jack_error ( "No data, is the master still running ?" );
return 0;
}
//if a network error occurs, this exception will restart the driver
else if ( error == NET_CONN_ERROR )
{
throw JackDriverException ( "Connection lost." );
}
else
{
jack_error ( "Error in receive : %s", StrError ( NET_ERROR_CODE ) );
return 0;
}
}
return rx_bytes;
}

int JackNetDriver::Send ( size_t size, int flags )
{
int tx_bytes;
if ( ( tx_bytes = fSocket.Send ( fTxBuffer, size, flags ) ) == SOCKET_ERROR )
int tx_bytes = fSocket.Send ( fTxBuffer, size, flags );
//handle errors
if ( tx_bytes == SOCKET_ERROR )
{
net_error_t error = fSocket.GetError();
//if a network error occurs, this exception will restart the driver
if ( error == NET_CONN_ERROR )
throw JackDriverException ( "Connection lost." );
else
@@ -534,8 +534,9 @@ namespace Jack
do
{
rx_bytes = Recv ( fParams.fMtu, 0 );
if ( ( rx_bytes == 0 ) || ( rx_bytes == SOCKET_ERROR ) )
return rx_bytes;
//if error, don't return -1, we need the driver to restart and not to exit
if ( rx_bytes == SOCKET_ERROR )
return 0;
}
while ( !rx_bytes && ( rx_head->fDataType != 's' ) );

@@ -547,8 +548,9 @@ namespace Jack
{
do
{
if ( ( rx_bytes = Recv ( fParams.fMtu, MSG_PEEK ) ) == SOCKET_ERROR )
return rx_bytes;
rx_bytes = Recv ( fParams.fMtu, MSG_PEEK );
if ( rx_bytes == SOCKET_ERROR )
return 0;
if ( rx_bytes && ( rx_head->fDataStream == 's' ) && ( rx_head->fID == fParams.fID ) )
{
switch ( rx_head->fDataType )


+ 8
- 9
common/JackNetManager.cpp View File

@@ -122,7 +122,7 @@ namespace Jack

//monitor
#ifdef JACK_MONITOR
fPeriodUsecs = ( int ) ( 1000000.f * ( (float)fParams.fPeriodSize / (float)fParams.fSampleRate ) );
fPeriodUsecs = ( int ) ( 1000000.f * ( ( float ) fParams.fPeriodSize / ( float ) fParams.fSampleRate ) );
string plot_name = string ( fParams.fName );
plot_name += string ( "_master" );
plot_name += string ( ( fParams.fSlaveSyncMode ) ? "_sync" : "_async" );
@@ -342,7 +342,6 @@ namespace Jack
jack_error ( "'%s' : %s, please check network connection with '%s'.",
fParams.fName, StrError ( NET_ERROR_CODE ), fParams.fSlaveNetName );
Exit();
return 0;
}
else
jack_error ( "Error in send : %s", StrError ( NET_ERROR_CODE ) );
@@ -358,21 +357,21 @@ namespace Jack
net_error_t error = fSocket.GetError();
if ( error == NET_NO_DATA )
{
//too much receive failure, react...
if ( ++fNetJumpCnt == 50 )
//too much receive failure, exit
if ( ++fNetJumpCnt == 100 )
{
jack_error ( "Connection lost, is %s still running ?", fParams.fName );
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, please check network connection with '%s'.",
jack_error ( "'%s' : %s, network connection with '%s' broken, exiting.",
fParams.fName, StrError ( NET_ERROR_CODE ), fParams.fSlaveNetName );
Exit();
return 0;
}
else
jack_error ( "Error in receive : %s", StrError ( NET_ERROR_CODE ) );
@@ -451,7 +450,7 @@ namespace Jack
memcpy ( fTxBuffer, &fTxHeader, sizeof ( packet_header_t ) );
copy_size = fNetMidiCaptureBuffer->RenderToNetwork ( subproc, fTxHeader.fMidiDataSize );
tx_bytes = Send ( fTxBuffer, sizeof ( packet_header_t ) + copy_size, 0 );
if ( tx_bytes < 1 )
if ( ( tx_bytes == 0 ) || ( tx_bytes == SOCKET_ERROR ) )
return tx_bytes;
}
}
@@ -468,7 +467,7 @@ namespace Jack
memcpy ( fTxBuffer, &fTxHeader, sizeof ( packet_header_t ) );
fNetAudioCaptureBuffer->RenderFromJackPorts ( subproc );
tx_bytes = Send ( fTxBuffer, fAudioTxLen, 0 );
if ( tx_bytes < 1 )
if ( ( tx_bytes == 0 ) || ( tx_bytes == SOCKET_ERROR ) )
return tx_bytes;
}
}


Loading…
Cancel
Save