Commit b9ae7166 authored by sletz's avatar sletz
Browse files

Fix in netjack code.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4360 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 26fdddf8
......@@ -154,7 +154,7 @@ namespace Jack
bool JackNetMasterInterface::Init()
{
jack_log ( "JackNetMasterInterface::Init, ID %u.", fParams.fID );
jack_log ( "JackNetMasterInterface::Init, ID %u", fParams.fID );
session_params_t host_params;
uint attempt = 0;
......@@ -186,12 +186,12 @@ namespace Jack
SessionParamsHToN(&fParams, &net_params);
if ( fSocket.Send ( &net_params, sizeof ( session_params_t ), 0 ) == SOCKET_ERROR )
jack_error ( "Error in send : ", StrError ( NET_ERROR_CODE ) );
jack_error("Error in send : %s", StrError(NET_ERROR_CODE));
memset(&net_params, 0, sizeof (session_params_t));
if (((rx_bytes = fSocket.Recv(&net_params, sizeof(session_params_t), 0)) == SOCKET_ERROR) && (fSocket.GetError() != NET_NO_DATA))
{
jack_error ( "Problem with network." );
jack_error ( "Problem with network" );
return false;
}
......@@ -199,7 +199,7 @@ namespace Jack
}
while ( ( GetPacketType ( &host_params ) != START_MASTER ) && ( ++attempt < SLAVE_SETUP_RETRY ) );
if ( attempt == SLAVE_SETUP_RETRY ) {
jack_error ( "Slave doesn't respond, exiting." );
jack_error ( "Slave doesn't respond, exiting" );
return false;
}
......@@ -315,24 +315,24 @@ namespace Jack
void JackNetMasterInterface::Exit()
{
jack_log ( "JackNetMasterInterface::Exit, ID %u", fParams.fID );
jack_log("JackNetMasterInterface::Exit, ID %u", fParams.fID);
//stop process
fRunning = false;
//send a 'multicast euthanasia request' - new socket is required on macosx
jack_info ( "Exiting '%s'", fParams.fName );
SetPacketType ( &fParams, KILL_MASTER );
JackNetSocket mcast_socket ( fMulticastIP, fSocket.GetPort() );
jack_info("Exiting '%s'", fParams.fName);
SetPacketType(&fParams, KILL_MASTER);
JackNetSocket mcast_socket(fMulticastIP, fSocket.GetPort());
session_params_t net_params;
memset(&net_params, 0, sizeof ( session_params_t ));
memset(&net_params, 0, sizeof(session_params_t));
SessionParamsHToN(&fParams, &net_params);
if ( mcast_socket.NewSocket() == SOCKET_ERROR )
jack_error ( "Can't create socket : %s", StrError ( NET_ERROR_CODE ) );
if ( mcast_socket.SendTo ( &net_params, sizeof ( session_params_t ), 0, fMulticastIP ) == SOCKET_ERROR )
jack_error ( "Can't send suicide request : %s", StrError ( NET_ERROR_CODE ) );
if (mcast_socket.NewSocket() == SOCKET_ERROR)
jack_error("Can't create socket : %s", StrError(NET_ERROR_CODE));
if (mcast_socket.SendTo(&net_params, sizeof(session_params_t), 0, fMulticastIP) == SOCKET_ERROR)
jack_error("Can't send suicide request : %s", StrError(NET_ERROR_CODE));
mcast_socket.Close();
}
......@@ -348,14 +348,14 @@ namespace Jack
return 0;
} else if (error == NET_CONN_ERROR) {
//fatal connection issue, exit
jack_error ( "'%s' : %s, exiting.", fParams.fName, StrError(NET_ERROR_CODE));
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 {
jack_error ( "Error in master receive : %s", StrError(NET_ERROR_CODE));
jack_error("Error in master receive : %s", StrError(NET_ERROR_CODE));
}
}
......@@ -374,7 +374,7 @@ namespace Jack
net_error_t error = fSocket.GetError();
if (error == NET_CONN_ERROR) {
//fatal connection issue, exit
jack_error ("'%s' : %s, exiting.", fParams.fName, StrError (NET_ERROR_CODE));
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.
......@@ -861,7 +861,7 @@ namespace Jack
jack_error ( "No data, is the master still running ?" );
//if a network error occurs, this exception will restart the driver
} else if ( error == NET_CONN_ERROR ) {
jack_error ( "Connection lost." );
jack_error ( "Recv connection lost" );
throw JackNetException();
} else {
jack_error ( "Fatal error in slave receive : %s", StrError ( NET_ERROR_CODE ) );
......@@ -885,7 +885,7 @@ namespace Jack
net_error_t error = fSocket.GetError();
//if a network error occurs, this exception will restart the driver
if ( error == NET_CONN_ERROR ) {
jack_error ( "Connection lost." );
jack_error ( "Send connection lost" );
throw JackNetException();
} else {
jack_error ( "Fatal error in slave send : %s", StrError ( NET_ERROR_CODE ) );
......@@ -954,7 +954,7 @@ namespace Jack
break;
case 's': //sync
jack_info ( "NetSlave : overloaded, skipping receive." );
jack_info("NetSlave : overloaded, skipping receive");
// TODO : finish midi and audio rendering ?
fNetAudioCaptureBuffer->RenderToJackPorts();
return 0;
......
......@@ -92,7 +92,7 @@ namespace Jack
JackNetMaster::~JackNetMaster()
{
jack_log ( "JackNetMaster::~JackNetMaster, ID %u.", fParams.fID );
jack_log ( "JackNetMaster::~JackNetMaster, ID %u", fParams.fID );
if ( fJackClient )
{
......@@ -113,7 +113,7 @@ namespace Jack
bool JackNetMaster::Init(bool auto_connect)
{
//network init
if (!JackNetMasterInterface::Init()){
if (!JackNetMasterInterface::Init()) {
jack_error("JackNetMasterInterface::Init() error..." );
return false;
}
......@@ -128,7 +128,7 @@ namespace Jack
jack_status_t status;
if ( ( fJackClient = jack_client_open ( fClientName, JackNullOption, &status, NULL ) ) == NULL )
{
jack_error ( "Can't open a new jack client." );
jack_error ( "Can't open a new jack client" );
return false;
}
......@@ -140,7 +140,7 @@ namespace Jack
if ( AllocPorts() != 0 )
{
jack_error ( "Can't allocate jack ports." );
jack_error ( "Can't allocate jack ports" );
goto fail;
}
......@@ -150,13 +150,13 @@ namespace Jack
//finally activate jack client
if ( jack_activate ( fJackClient ) != 0 )
{
jack_error ( "Can't activate jack client." );
jack_error ( "Can't activate jack client" );
goto fail;
}
if (auto_connect)
ConnectPorts();
jack_info ( "New NetMaster started." );
jack_info ( "New NetMaster started" );
return true;
fail:
......@@ -314,17 +314,17 @@ namespace Jack
case RELEASE_TIMEBASEMASTER :
timebase = jack_release_timebase ( fJackClient );
if ( timebase < 0 )
jack_error ( "Can't release timebase master." );
jack_error ( "Can't release timebase master" );
else
jack_info ( "'%s' isn't the timebase master anymore.", fParams.fName );
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." );
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;
case CONDITIONAL_TIMEBASEMASTER :
......@@ -332,9 +332,9 @@ namespace Jack
if ( timebase != EBUSY )
{
if ( timebase < 0 )
jack_error ( "Can't set a new timebase master." );
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;
}
......@@ -347,22 +347,22 @@ namespace Jack
{
case JackTransportStopped :
jack_transport_stop ( fJackClient );
jack_info ( "'%s' stops transport.", fParams.fName );
jack_info ( "'%s' stops transport", fParams.fName );
break;
case JackTransportStarting :
if ( jack_transport_reposition ( fJackClient, &fReturnTransportData.fPosition ) == EINVAL )
jack_error ( "Can't set new position." );
jack_error ( "Can't set new position" );
jack_transport_start ( fJackClient );
jack_info ( "'%s' starts transport frame = %d", fParams.fName, fReturnTransportData.fPosition.frame);
break;
case JackTransportNetStarting :
jack_info ( "'%s' is ready to roll..", fParams.fName );
jack_info ( "'%s' is ready to roll...", fParams.fName );
break;
case JackTransportRolling :
jack_info ( "'%s' is rolling.", fParams.fName );
jack_info ( "'%s' is rolling", fParams.fName );
break;
}
}
......@@ -526,11 +526,11 @@ namespace Jack
//activate the client (for sync callback)
if ( jack_activate ( fManagerClient ) != 0 )
jack_error ( "Can't activate the network manager client, transport disabled." );
jack_error ( "Can't activate the network manager client, transport disabled" );
//launch the manager thread
if ( jack_client_create_thread ( fManagerClient, &fManagerThread, 0, 0, NetManagerThread, this ) )
jack_error ( "Can't create the network manager control thread." );
jack_error ( "Can't create the network manager control thread" );
}
JackNetMasterManager::~JackNetMasterManager()
......@@ -579,7 +579,7 @@ namespace Jack
void* JackNetMasterManager::NetManagerThread ( void* arg )
{
JackNetMasterManager* master_manager = static_cast<JackNetMasterManager*> ( arg );
jack_info ( "Starting Jack Network Manager." );
jack_info ( "Starting Jack Network Manager" );
jack_info ( "Listening on '%s:%d'", master_manager->fMulticastIP, master_manager->fSocket.GetPort() );
master_manager->Run();
return NULL;
......@@ -641,7 +641,7 @@ namespace Jack
jack_error ( "Error in receive : %s", StrError ( NET_ERROR_CODE ) );
if ( ++attempt == 10 )
{
jack_error ( "Can't receive on the socket, exiting net manager." );
jack_error ( "Can't receive on the socket, exiting net manager" );
return;
}
}
......@@ -718,7 +718,7 @@ namespace Jack
master_list_it_t JackNetMasterManager::FindMaster ( uint32_t id )
{
jack_log ( "JackNetMasterManager::FindMaster, ID %u.", id );
jack_log ( "JackNetMasterManager::FindMaster, ID %u", id );
master_list_it_t it;
for ( it = fMasterList.begin(); it != fMasterList.end(); it++ )
......@@ -729,7 +729,7 @@ namespace Jack
int JackNetMasterManager::KillMaster ( session_params_t* params )
{
jack_log ( "JackNetMasterManager::KillMaster, ID %u.", params->fID );
jack_log ( "JackNetMasterManager::KillMaster, ID %u", params->fID );
master_list_it_t master = FindMaster ( params->fID );
if ( master != fMasterList.end() )
......
......@@ -99,13 +99,13 @@ namespace Jack
Reset();
}
fSockfd = socket ( AF_INET, SOCK_DGRAM, 0 );
/* Enable address reuse */
int res, on = 1;
if ((res = setsockopt( fSockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) < 0) {
StrError(NET_ERROR_CODE);
}
return fSockfd;
}
......@@ -230,12 +230,12 @@ namespace Jack
{
int flags;
fTimeOut = us;
if ((flags = fcntl(fSockfd, F_GETFL, 0)) < 0) {
jack_error("JackNetUnixSocket::SetTimeOut error in fcntl F_GETFL");
return -1;
}
flags |= O_NONBLOCK;
if (fcntl(fSockfd, F_SETFL, flags) < 0) {
jack_error("JackNetUnixSocket::SetTimeOut error in fcntl F_SETFL");
......@@ -252,17 +252,17 @@ namespace Jack
struct timeval tv;
fd_set fdset;
ssize_t res;
tv.tv_sec = fTimeOut / 1000000;
tv.tv_usec = fTimeOut % 1000000;
FD_ZERO(&fdset);
FD_SET(fSockfd, &fdset);
do {
res = select(fSockfd + 1, &fdset, NULL, NULL, &tv);
} while (res < 0 && errno == EINTR);
if (res < 0) {
return res;
} else if (res == 0) {
......@@ -281,17 +281,17 @@ namespace Jack
struct timeval tv;
fd_set fdset;
ssize_t res;
tv.tv_sec = fTimeOut / 1000000;
tv.tv_usec = fTimeOut % 1000000;
tv.tv_usec = fTimeOut % 1000000;
FD_ZERO(&fdset);
FD_SET(fSockfd, &fdset);
do {
res = select(fSockfd + 1, NULL, &fdset, NULL, &tv);
} while (res < 0 && errno == EINTR);
if (res < 0) {
return res;
} else if (res == 0) {
......@@ -375,7 +375,7 @@ namespace Jack
#if defined(__sun__) || defined(sun)
if (WaitRead() < 0)
return -1;
#endif
#endif
return recvfrom ( fSockfd, buffer, nbytes, flags, reinterpret_cast<socket_address_t*> ( &fRecvAddr ), &addr_len );
}
......@@ -384,7 +384,7 @@ namespace Jack
#if defined(__sun__) || defined(sun)
if (WaitRead() < 0)
return -1;
#endif
#endif
return recv ( fSockfd, buffer, nbytes, flags );
}
......@@ -394,7 +394,7 @@ namespace Jack
#if defined(__sun__) || defined(sun)
if (WaitRead() < 0)
return -1;
#endif
#endif
return recvfrom ( fSockfd, buffer, nbytes, flags, reinterpret_cast<socket_address_t*> ( &fSendAddr ), &addr_len );
}
......@@ -405,7 +405,7 @@ namespace Jack
case EAGAIN:
case ETIMEDOUT:
return NET_NO_DATA;
case ECONNABORTED:
case ECONNREFUSED:
case ECONNRESET:
......@@ -415,9 +415,10 @@ namespace Jack
case ENETDOWN:
case ENETUNREACH:
return NET_CONN_ERROR;
default:
return NET_OP_ERROR;
//return NET_OP_ERROR;
return NET_CONN_ERROR;
}
}
}
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