Browse Source

Improve NetJack connection handling.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4450 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.9.8
sletz 14 years ago
parent
commit
c5e83d69a8
2 changed files with 56 additions and 27 deletions
  1. +4
    -6
      common/JackNetInterface.cpp
  2. +52
    -21
      common/JackNetManager.cpp

+ 4
- 6
common/JackNetInterface.cpp View File

@@ -352,7 +352,6 @@ namespace Jack
jack_error("'%s' : %s, exiting", fParams.fName, StrError(NET_ERROR_CODE));
//ask to the manager to properly remove the master
Exit();

// UGLY temporary way to be sure the thread does not call code possibly causing a deadlock in JackEngine.
ThreadExit();
} else {
@@ -377,7 +376,6 @@ namespace Jack
//fatal connection issue, exit
jack_error("'%s' : %s, exiting", fParams.fName, StrError(NET_ERROR_CODE));
Exit();

// UGLY temporary way to be sure the thread does not call code possibly causing a deadlock in JackEngine.
ThreadExit();
} else {
@@ -454,8 +452,10 @@ namespace Jack
packet_header_t* rx_head = reinterpret_cast<packet_header_t*>(fRxBuffer);
int rx_bytes = Recv(fParams.fMtu, MSG_PEEK);

if ((rx_bytes == 0) || (rx_bytes == SOCKET_ERROR))
return rx_bytes;
if ((rx_bytes == 0) || (rx_bytes == SOCKET_ERROR)) {
// O bytes considered an error (lost connection)
return SOCKET_ERROR;
}

fCycleOffset = fTxHeader.fCycle - rx_head->fCycle;

@@ -468,7 +468,6 @@ namespace Jack
// - this mode will skip the two first cycles, thus it lets time for data to be processed and queued on the socket rx buffer
//the slow mode is the safest mode because it wait twice the bandwidth relative time (send/return + process)


if (fCycleOffset < CYCLE_OFFSET_SLOW) {
return 0;
} else {
@@ -512,7 +511,6 @@ namespace Jack
jack_info("'%s' can't run in fast network mode, data received too late (%d cycle(s) offset)", fParams.fName, fCycleOffset);
}
break;
break;
}

fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;


+ 52
- 21
common/JackNetManager.cpp View File

@@ -313,28 +313,29 @@ namespace Jack
{
case RELEASE_TIMEBASEMASTER :
timebase = jack_release_timebase ( fJackClient );
if ( timebase < 0 )
jack_error ( "Can't release timebase master" );
else
jack_info ( "'%s' isn't the timebase master anymore", fParams.fName );
if (timebase < 0) {
jack_error("Can't release timebase master");
} else {
jack_info("'%s' isn't the timebase master anymore", fParams.fName);
}
break;

case TIMEBASEMASTER :
timebase = jack_set_timebase_callback ( fJackClient, 0, SetTimebaseCallback, this );
if ( timebase < 0 )
jack_error ( "Can't set a new timebase master" );
else
jack_info ( "'%s' is the new timebase master", fParams.fName );
if (timebase < 0) {
jack_error("Can't set a new timebase master");
} else {
jack_info("'%s' is the new timebase master", fParams.fName);
}
break;

case CONDITIONAL_TIMEBASEMASTER :
timebase = jack_set_timebase_callback ( fJackClient, 1, SetTimebaseCallback, this );
if ( timebase != EBUSY )
{
if ( timebase < 0 )
jack_error ( "Can't set a new timebase master" );
if (timebase != EBUSY) {
if (timebase < 0)
jack_error("Can't set a new timebase master");
else
jack_info ( "'%s' is the new timebase master", fParams.fName );
jack_info("'%s' is the new timebase master", fParams.fName);
}
break;
}
@@ -410,7 +411,7 @@ namespace Jack

int JackNetMaster::Process()
{
if ( !fRunning )
if (!fRunning)
return 0;

int port_index;
@@ -457,7 +458,7 @@ namespace Jack
#endif

//send data
if ( DataSend() == SOCKET_ERROR )
if (DataSend() == SOCKET_ERROR)
return SOCKET_ERROR;

#ifdef JACK_MONITOR
@@ -470,11 +471,26 @@ namespace Jack

//receive sync
res = SyncRecv();
if ( ( res == 0 ) || ( res == SOCKET_ERROR ) )
return res;
switch (res) {

case 0:
jack_error("Connection is not yet synched, skip cycle...");
return res;

case SOCKET_ERROR:
jack_error("Connection is lost, quit master...");
//ask to the manager to properly remove the master
Exit();
//UGLY temporary way to be sure the thread does not call code possibly causing a deadlock in JackEngine.
ThreadExit();
break;

default:
break;
}

#ifdef JACK_MONITOR
fNetTimeMon->Add ( ( ( ( float ) (GetMicroSeconds() - begin_time ) ) / ( float ) fPeriodUsecs ) * 100.f );
fNetTimeMon->Add ((((float) (GetMicroSeconds() - begin_time)) / (float) fPeriodUsecs) * 100.f);
#endif

//decode sync
@@ -482,11 +498,26 @@ namespace Jack

//receive data
res = DataRecv();
if ( ( res == 0 ) || ( res == SOCKET_ERROR ) )
return res;
switch (res) {

case 0:
jack_error("Connection is not yet synched, skip cycle...");
return res;

case SOCKET_ERROR:
jack_error("Connection is lost, quit master...");
//ask to the manager to properly remove the master
Exit();
//UGLY temporary way to be sure the thread does not call code possibly causing a deadlock in JackEngine.
ThreadExit();
break;

default:
break;
}

#ifdef JACK_MONITOR
fNetTimeMon->AddLast ( ( ( ( float ) (GetMicroSeconds() - begin_time ) ) / ( float ) fPeriodUsecs ) * 100.f );
fNetTimeMon->AddLast((((float) (GetMicroSeconds() - begin_time)) / (float) fPeriodUsecs) * 100.f);
#endif
return 0;
}


Loading…
Cancel
Save