Commit 9b636ddc authored by moret's avatar moret
Browse files

Fix NetDriver network error detection

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2746 0c269be4-1314-0410-8aa9-9f06e86f4224
parent b8d7ceff
......@@ -252,6 +252,7 @@ namespace Jack
void JackNetDriver::Restart()
{
jack_log ( "JackNetDriver::Restart" );
jack_info ( "Restarting driver..." );
delete[] fTxBuffer;
fTxBuffer = NULL;
......@@ -475,6 +476,8 @@ namespace Jack
return 0;
}
//***********************************network operations*************************************************************
int JackNetDriver::Recv ( size_t size, int flags )
{
int rx_bytes = fSocket.Recv ( fRxBuffer, size, flags );
......@@ -484,13 +487,13 @@ namespace Jack
net_error_t error = fSocket.GetError();
//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 ?" );
return 0;
}
//if a network error occurs, this exception will restart the driver
else if ( error == NET_CONN_ERROR )
throw JackDriverException ( "Connection lost." );
{
jack_error ( "Connection lost." );
throw JackDriverException();
}
else
jack_error ( "Fatal error in receive : %s", StrError ( NET_ERROR_CODE ) );
}
......@@ -506,7 +509,10 @@ namespace Jack
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." );
{
jack_error ( "Connection lost." );
throw JackDriverException();
}
else
jack_error ( "Fatal error in send : %s", StrError ( NET_ERROR_CODE ) );
}
......@@ -534,7 +540,8 @@ namespace Jack
do
{
rx_bytes = Recv ( fParams.fMtu, 0 );
//if error, don't return -1, we need the driver to restart and not to exit
//no sync received during timeout,
//if it's a connection issue, send will detect it, so don't skip the cycle (return 0)
if ( rx_bytes == SOCKET_ERROR )
return 0;
}
......@@ -549,8 +556,9 @@ namespace Jack
do
{
rx_bytes = Recv ( fParams.fMtu, MSG_PEEK );
//error here, problem with send, just skip the cycle (return -1)
if ( rx_bytes == SOCKET_ERROR )
return 0;
return rx_bytes;
if ( rx_bytes && ( rx_head->fDataStream == 's' ) && ( rx_head->fID == fParams.fID ) )
{
switch ( rx_head->fDataType )
......@@ -582,12 +590,9 @@ namespace Jack
}
fRxHeader.fCycle = rx_head->fCycle;
#ifdef JACK_MONITOR
fMeasureId = 0;
fMeasure[fMeasureId++] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
fMeasure[0] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
#endif
return 0;
}
......@@ -611,7 +616,7 @@ namespace Jack
fNetAudioPlaybackBuffer->SetBuffer ( audio_port_index, GetOutputBuffer ( audio_port_index ) );
#ifdef JACK_MONITOR
fMeasure[fMeasureId++] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
fMeasure[1] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
#endif
//sync
......@@ -622,10 +627,10 @@ namespace Jack
SetSyncPacket();
tx_bytes = Send ( fParams.fMtu, 0 );
if ( tx_bytes == SOCKET_ERROR )
return 0;
return tx_bytes;
#ifdef JACK_MONITOR
fMeasure[fMeasureId++] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
fMeasure[2] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
#endif
//midi
......@@ -642,6 +647,8 @@ namespace Jack
memcpy ( fTxBuffer, &fTxHeader, sizeof ( packet_header_t ) );
copy_size = fNetMidiPlaybackBuffer->RenderToNetwork ( subproc, fTxHeader.fMidiDataSize );
tx_bytes = Send ( sizeof ( packet_header_t ) + copy_size, 0 );
if ( tx_bytes == SOCKET_ERROR )
return tx_bytes;
}
}
......@@ -657,11 +664,13 @@ namespace Jack
fNetAudioPlaybackBuffer->RenderFromJackPorts ( subproc );
memcpy ( fTxBuffer, &fTxHeader, sizeof ( packet_header_t ) );
tx_bytes = Send ( fAudioTxLen, 0 );
if ( tx_bytes == SOCKET_ERROR )
return tx_bytes;
}
}
#ifdef JACK_MONITOR
fMeasure[fMeasureId++] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
fMeasure[3] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
fMonitor->Write ( fMeasure );
#endif
......
......@@ -345,8 +345,6 @@ 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;
}
......@@ -360,7 +358,9 @@ namespace Jack
if ( error == NET_NO_DATA )
{
//too much receive failure, react
if ( ++fNetJumpCnt == 100 )
if ( ++fNetJumpCnt < 100 )
return 0;
else
{
jack_error ( "No data from %s...", fParams.fName );
fNetJumpCnt = 0;
......@@ -376,10 +376,6 @@ namespace Jack
}
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;
}
......@@ -434,7 +430,7 @@ namespace Jack
memset ( fTxData, 0, fPayloadSize );
SetSyncPacket();
tx_bytes = Send ( fTxBuffer, fParams.fMtu, 0 );
if ( ( tx_bytes == 0 ) || ( tx_bytes == SOCKET_ERROR ) )
if ( tx_bytes == SOCKET_ERROR )
return tx_bytes;
#ifdef JACK_MONITOR
......@@ -455,7 +451,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 == 0 ) || ( tx_bytes == SOCKET_ERROR ) )
if ( tx_bytes == SOCKET_ERROR )
return tx_bytes;
}
}
......@@ -472,7 +468,7 @@ namespace Jack
memcpy ( fTxBuffer, &fTxHeader, sizeof ( packet_header_t ) );
fNetAudioCaptureBuffer->RenderFromJackPorts ( subproc );
tx_bytes = Send ( fTxBuffer, fAudioTxLen, 0 );
if ( ( tx_bytes == 0 ) || ( tx_bytes == SOCKET_ERROR ) )
if ( tx_bytes == SOCKET_ERROR )
return tx_bytes;
}
}
......
......@@ -320,6 +320,8 @@ namespace Jack
return NET_NO_ERROR;
case WSAETIMEDOUT:
return NET_NO_DATA;
case WSAEWOULDBLOCK:
return NET_NO_DATA;
case WSAECONNREFUSED:
return NET_CONN_ERROR;
case WSAECONNRESET:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment