From 84c256f7aaaa4754143c442a28089af45a271b34 Mon Sep 17 00:00:00 2001 From: sletz Date: Fri, 19 Jun 2009 13:44:24 +0000 Subject: [PATCH] NetJack2 code : better error checkout, method renaming. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3565 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 3 ++- common/JackNetInterface.cpp | 39 +++++++++++++++++-------------------- common/JackNetInterface.h | 2 +- common/JackNetManager.cpp | 6 +++--- common/JackNetManager.h | 2 +- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index f63bf432..a75cb8e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,7 +27,8 @@ Paul Davis 2009-06-19 Stephane Letz - * Correct JackTransportEngine::MakeAllLocating, sync callback has to be called in this case also. + * Correct JackTransportEngine::MakeAllLocating, sync callback has to be called in this case also. + * NetJack2 code : better error checkout, method renaming. 2009-06-17 Stephane Letz diff --git a/common/JackNetInterface.cpp b/common/JackNetInterface.cpp index 78e9dbb9..5131c98c 100644 --- a/common/JackNetInterface.cpp +++ b/common/JackNetInterface.cpp @@ -204,8 +204,7 @@ namespace Jack int rx_bytes = 0; //socket - if ( fSocket.NewSocket() == SOCKET_ERROR ) - { + if ( fSocket.NewSocket() == SOCKET_ERROR ) { jack_error ( "Can't create socket : %s", StrError ( NET_ERROR_CODE ) ); return false; } @@ -215,8 +214,7 @@ namespace Jack jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); //connect - if ( fSocket.Connect() == SOCKET_ERROR ) - { + if ( fSocket.Connect() == SOCKET_ERROR ) { jack_error ( "Can't connect : %s", StrError ( NET_ERROR_CODE ) ); return false; } @@ -245,22 +243,19 @@ namespace Jack SessionParamsNToH(&net_params, &host_params); } while ( ( GetPacketType ( &host_params ) != START_MASTER ) && ( ++attempt < SLAVE_SETUP_RETRY ) ); - if ( attempt == SLAVE_SETUP_RETRY ) - { + if ( attempt == SLAVE_SETUP_RETRY ) { jack_error ( "Slave doesn't respond, exiting." ); return false; } //set the new timeout for the socket - if ( SetRxTimeout() == SOCKET_ERROR ) - { + if ( SetRxTimeout() == SOCKET_ERROR ) { jack_error ( "Can't set rx timeout : %s", StrError ( NET_ERROR_CODE ) ); return false; } //set the new rx buffer size - if ( SetNetBufferSize() == SOCKET_ERROR ) - { + if ( SetNetBufferSize() == SOCKET_ERROR ) { jack_error ( "Can't set net buffer sizes : %s", StrError ( NET_ERROR_CODE ) ); return false; } @@ -619,7 +614,7 @@ namespace Jack //first, get a master, do it until a valid connection is running do { - status = GetNetMaster(); + status = SendAvailableToMaster(); if ( status == NET_SOCKET_ERROR ) return false; } @@ -651,7 +646,7 @@ namespace Jack do { //get a master - status = GetNetMaster(); + status = SendAvailableToMaster(); if (status == NET_SOCKET_ERROR) return false; } @@ -678,26 +673,27 @@ namespace Jack return true; } - net_status_t JackNetSlaveInterface::GetNetMaster() + net_status_t JackNetSlaveInterface::SendAvailableToMaster() { - jack_log ( "JackNetSlaveInterface::GetNetMaster()" ); + jack_log ( "JackNetSlaveInterface::SendAvailableToMaster()" ); //utility session_params_t host_params; int rx_bytes = 0; //socket - if ( fSocket.NewSocket() == SOCKET_ERROR ) - { + if ( fSocket.NewSocket() == SOCKET_ERROR ) { jack_error ( "Fatal error : network unreachable - %s", StrError ( NET_ERROR_CODE ) ); return NET_SOCKET_ERROR; } //bind the socket - if ( fSocket.Bind() == SOCKET_ERROR ) + if ( fSocket.Bind() == SOCKET_ERROR ) { jack_error ( "Can't bind the socket : %s", StrError ( NET_ERROR_CODE ) ); + return NET_SOCKET_ERROR; + } //timeout on receive - if ( fSocket.SetTimeOut ( SLAVE_INIT_TIMEOUT ) == SOCKET_ERROR ) + if ( fSocket.SetTimeOut ( SLAVE_INIT_TIMEOUT ) == SOCKET_ERROR ) jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); //disable local loop @@ -730,12 +726,13 @@ namespace Jack fParams = host_params; //set the new buffer sizes - if ( SetNetBufferSize() == SOCKET_ERROR ) + if ( SetNetBufferSize() == SOCKET_ERROR ) { jack_error ( "Can't set net buffer sizes : %s", StrError ( NET_ERROR_CODE ) ); + return NET_SOCKET_ERROR; + } //connect the socket - if ( fSocket.Connect() == SOCKET_ERROR ) - { + if ( fSocket.Connect() == SOCKET_ERROR ) { jack_error ( "Error in connect : %s", StrError ( NET_ERROR_CODE ) ); return NET_CONNECT_ERROR; } diff --git a/common/JackNetInterface.h b/common/JackNetInterface.h index c655a3b0..ca90875f 100644 --- a/common/JackNetInterface.h +++ b/common/JackNetInterface.h @@ -151,7 +151,7 @@ namespace Jack bool InitConnection(); bool InitRendering(); - net_status_t GetNetMaster(); + net_status_t SendAvailableToMaster(); net_status_t SendStartToMaster(); void SetParams(); diff --git a/common/JackNetManager.cpp b/common/JackNetManager.cpp index 86d23522..b4e45853 100644 --- a/common/JackNetManager.cpp +++ b/common/JackNetManager.cpp @@ -618,7 +618,7 @@ namespace Jack switch ( GetPacketType ( &host_params ) ) { case SLAVE_AVAILABLE: - if ( ( net_master = MasterInit ( host_params ) ) ) + if ( ( net_master = InitMaster ( host_params ) ) ) SessionParamsDisplay ( &net_master->fParams ); else jack_error ( "Can't init new net master..." ); @@ -636,9 +636,9 @@ namespace Jack while ( fRunning ); } - JackNetMaster* JackNetMasterManager::MasterInit ( session_params_t& params ) + JackNetMaster* JackNetMasterManager::InitMaster ( session_params_t& params ) { - jack_log ( "JackNetMasterManager::MasterInit, Slave : %s", params.fName ); + jack_log ( "JackNetMasterManager::InitMaster, Slave : %s", params.fName ); //check MASTER <<==> SLAVE network protocol coherency if (params.fProtocolVersion != MASTER_PROTOCOL) { diff --git a/common/JackNetManager.h b/common/JackNetManager.h index b6ad7857..29c8386d 100644 --- a/common/JackNetManager.h +++ b/common/JackNetManager.h @@ -105,7 +105,7 @@ namespace Jack bool fAutoConnect; void Run(); - JackNetMaster* MasterInit ( session_params_t& params ); + JackNetMaster* InitMaster ( session_params_t& params ); master_list_it_t FindMaster ( uint32_t client_id ); int KillMaster ( session_params_t* params ); void SetSlaveName ( session_params_t& params );