Commit 6121648e authored by moret's avatar moret
Browse files

Correct timeout settings in netjack2

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2753 0c269be4-1314-0410-8aa9-9f06e86f4224
parent f1cbf630
......@@ -185,7 +185,7 @@ namespace Jack
jack_log ( "JackNetDriver::GetNetMaster()" );
//utility
session_params_t params;
float ms_timeout = 2000.f;
int us_timeout = 2000000;
int rx_bytes = 0;
//socket
......@@ -200,7 +200,7 @@ namespace Jack
jack_error ( "Can't bind the socket : %s", StrError ( NET_ERROR_CODE ) );
//timeout on receive
if ( fSocket.SetTimeOut ( ms_timeout ) == SOCKET_ERROR )
if ( fSocket.SetTimeOut ( us_timeout ) == SOCKET_ERROR )
jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) );
//send 'AVAILABLE' until 'SLAVE_SETUP' received
......@@ -546,10 +546,6 @@ namespace Jack
}
while ( !rx_bytes && ( rx_head->fDataType != 's' ) );
#ifdef JACK_MONITOR
fMeasureId = 0;
fMeasure[fMeasureId++] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
#endif
//take the time at the beginning of the cycle
JackDriver::CycleTakeBeginTime();
......@@ -596,6 +592,7 @@ namespace Jack
fRxHeader.fCycle = rx_head->fCycle;
#ifdef JACK_MONITOR
fMeasureId = 0;
fMeasure[fMeasureId++] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
#endif
return 0;
......@@ -621,7 +618,7 @@ namespace Jack
fNetAudioPlaybackBuffer->SetBuffer ( audio_port_index, GetOutputBuffer ( audio_port_index ) );
#ifdef JACK_MONITOR
fMeasure[fMeasureId++] = ( ( float ) ( GetMicroSeconds() - fMonTimeRef ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
fMeasure[fMeasureId++] = ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f;
#endif
//sync
......
......@@ -163,7 +163,7 @@ namespace Jack
{
jack_log ( "JackNetMaster::Init, ID %u.", fParams.fID );
session_params_t params;
float msec_timeout = 1000.f;
int usec_timeout = 1000000;
uint attempt = 0;
int rx_bytes = 0;
......@@ -175,7 +175,7 @@ namespace Jack
}
//timeout on receive (for init)
if ( fSocket.SetTimeOut ( msec_timeout ) < 0 )
if ( fSocket.SetTimeOut ( usec_timeout ) < 0 )
jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) );
//connect
......@@ -615,7 +615,7 @@ namespace Jack
{
jack_log ( "JackNetMasterManager::Run" );
//utility variables
float msec_timeout = 2000.f;
int usec_timeout = 2000000;
int attempt = 0;
//data
......@@ -654,7 +654,7 @@ namespace Jack
jack_error ( "Can't set local loop : %s", StrError ( NET_ERROR_CODE ) );
//set a timeout on the multicast receive (the thread can now be cancelled)
if ( fSocket.SetTimeOut ( msec_timeout ) == SOCKET_ERROR )
if ( fSocket.SetTimeOut ( usec_timeout ) == SOCKET_ERROR )
jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) );
jack_info ( "Waiting for a slave..." );
......
......@@ -357,12 +357,12 @@ namespace Jack
return npckt;
}
EXPORT int SetRxTimeout ( JackNetSocket* socket, session_params_t* params )
{
//time in ms, 1.25x cycle duration
float time = 1250 * ( static_cast<float> ( params->fPeriodSize ) / static_cast<float> ( params->fSampleRate ) );
return ( socket->SetTimeOut ( time ) == SOCKET_ERROR ) ? SOCKET_ERROR : 0;
}
EXPORT int SetRxTimeout ( JackNetSocket* socket, session_params_t* params )
{
float time = 1250000.f * ( static_cast<float> ( params->fFramesPerPacket ) / static_cast<float> ( params->fSampleRate ) );
int usec = ( int ) time;
return socket->SetTimeOut ( usec );
}
// Packet *******************************************************************************************************
......
......@@ -28,7 +28,7 @@ namespace Jack
{
jack_error ( "Can't get 'hostname' : %s", strerror ( NET_ERROR_CODE ) );
strcpy ( name, "default" );
return -1;
return SOCKET_ERROR;
}
return 0;
}
......@@ -198,30 +198,28 @@ namespace Jack
return getsockopt ( fSockfd, level, optname, optval, optlen );
}
//timeout*************************************************************************************************************
int JackNetUnixSocket::SetTimeOut ( float& msec )
//timeout************************************************************************************************************
int JackNetUnixSocket::SetTimeOut ( int& us )
{
//negative timeout, or exceeding 10s, return
if ( ( msec < 0 ) || ( msec > 10000 ) )
return -1;
//negative timeout, or exceding 10s, return
if ( ( us < 0 ) || ( us > 10000000 ) )
return SOCKET_ERROR;
struct timeval timeout;
//less than 1sec
if ( msec < 1000 )
if ( us < 1000000 )
{
timeout.tv_sec = 0;
timeout.tv_usec = ( int ) ( msec * 1000.f );
return SetOption ( SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof ( timeout ) );
timeout.tv_usec = us;
}
//more than 1sec
if ( msec >= 1000 )
else
{
float sec = msec / 1000.0f;
float sec = static_cast<float>( us ) / 1000000.f;
timeout.tv_sec = ( int ) sec;
float usec = ( sec - timeout.tv_sec ) * 1000000;
float usec = ( sec - static_cast<float> ( timeout.tv_sec ) ) * 1000000;
timeout.tv_usec = ( int ) usec;
return SetOption ( SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof ( timeout ) );
}
return -1;
return SetOption ( SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof ( timeout ) );
}
//local loop**********************************************************************************************************
......
......@@ -80,7 +80,7 @@ namespace Jack
int GetOption ( int level, int optname, void* optval, socklen_t* optlen );
//timeout
int SetTimeOut ( float& msec );
int SetTimeOut ( int& us );
//local loop
int SetLocalLoop();
......
......@@ -263,12 +263,12 @@ namespace Jack
}
//tiemout************************************************************************************************************
int JackNetWinSocket::SetTimeOut ( float& msec )
int JackNetWinSocket::SetTimeOut ( int& usec )
{
//negative timeout, or exceeding 10s, return
if ( ( msec < 0 ) || ( msec > 10000 ) )
if ( ( msec < 0 ) || ( usec > 10000000 ) )
return -1;
int time = ( int ) msec;
int time = usec / 1000;
return SetOption ( SOL_SOCKET, SO_RCVTIMEO, &time, sizeof ( time ) );
}
......
......@@ -81,7 +81,7 @@ namespace Jack
int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen );
//timeout
int SetTimeOut ( float& msec );
int SetTimeOut ( int& usec );
//local loop
int SetLocalLoop();
......
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