![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: sip.cpp
- Revision:
- 104:62646ef786a3
- Parent:
- 100:09a23fcd3bdf
- Child:
- 105:a930035b6556
--- a/sip.cpp Thu Feb 19 18:04:33 2015 +0000 +++ b/sip.cpp Wed Feb 25 18:44:11 2015 +0000 @@ -11,9 +11,8 @@ } void Sip::__reconnect__( void ){ - sock.close(); - sock.init(); - sock.bind( this->my_port ); + __end_sock__(); + __init_sock__(); } Sip::Sip( char * server_ip, int server_port, char * my_ip, int my_port, int my_ext, int peer_ext, int id ){ @@ -169,15 +168,17 @@ int Sip::registry(){ build_registry_package( buffer ); - int sent = sock.sendTo( sip_server, buffer, strlen( buffer ) ); // > 400 + int send = sock.sendTo( sip_server, buffer, strlen( buffer ) ); // > 400 + if( send != strlen( buffer ) ) + { + if( debug_reconnect ) send_msg("Reconnect SIP -- Registry"); + __reconnect__(); + miss_sip_registry_send_pkg++; + } - if( debug_sip ) send_msg("Registry ( %d, %d ) - Sent %i of %i bytes", this->my_ext, this->my_port , sent, strlen( buffer ) ); + if( debug_sip ) send_msg("Registry ( %d, %d ) - Sent %i of %i bytes", this->my_ext, this->my_port , send, strlen( buffer ) ); - if( sent != strlen( buffer ) ){ - sip_socket_send_failure++; - } - - return( sent ); + return( send ); } VZ_call * Sip::invite(){ @@ -199,6 +200,15 @@ this->invite_pkg_sent = sock.sendTo( sip_server, buffer, strlen( buffer ) ); }while( this->invite_pkg_sent == 0 ); + //FIXME verificar se posso nao usar invite_pkg_sent + int send = this->invite_pkg_sent; + if( send != strlen( buffer ) ) + { + if( debug_reconnect ) send_msg("Reconnect SIP -- BYE"); + __reconnect__(); + miss_sip_invite_send_pkg++; + } + if( debug_invite ) debug_msg("Return value for invite pkg %d", invite_pkg_sent ); invite_timer.stop(); @@ -942,30 +952,30 @@ void Sip::send_bye( void ){ - int ret = sock.sendTo( sip_server, build_bye_package( this->buffer ), strlen( this->buffer ) ); + int send = sock.sendTo( sip_server, build_bye_package( this->buffer ), strlen( this->buffer ) ); if( debug_sip ) send_msg( "sizeof( bye pkg ) :: %d", strlen( buffer ) ); - if( ret == -1 ){ - muted = true; - }else{ - muted = false; + if( send != strlen( this->buffer ) ) + { + if( debug_reconnect ) send_msg("Reconnect SIP -- BYE"); + __reconnect__(); + miss_sip_bye_send_pkg++; } } void Sip::send_unregistry_pkg(){ build_unregistry_package( this->buffer ); - int ret = 0; - - ret = sock.sendTo( sip_server, build_bye_package( this->buffer ), strlen( this->buffer ) ); + int send = sock.sendTo( sip_server, build_bye_package( this->buffer ), strlen( this->buffer ) ); + if( send != strlen( this->buffer ) ) + { + if( debug_reconnect ) send_msg("Reconnect SIP -- BYE"); + __reconnect__(); + miss_sip_unregistry_send_pkg++; + } + if( debug_sip ) send_msg("sizeof( unregistry_pkg ) :: %d", strlen( buffer ) ); - - if( ret == -1 ){ - muted = true; - }else{ - muted = false; - } } char * Sip::build_unregistry_package( char * buffer ){ @@ -1066,7 +1076,12 @@ if( memcmp( ( ( u8_t * )( &(from._remoteHost) ) ) + 2, ( ( u8_t * )( &(sip_server._remoteHost) ) ) + 2, 6 ) != 0 ) return 0; - if( length == -1 ){ length_muted++; } + if( length == -1 ) + { + if( debug_reconnect ) send_msg("Reconnect SIP -- UDP Incomming"); + __reconnect__(); + miss_sip_inc_pkg++; + } if( length > 0 ){ if( sizeof( buffer ) > length ) buffer[ length ] = 0; @@ -1093,10 +1108,14 @@ char ans[ 1024 ]; build_ack_package( ans, ( unsigned char *)buffer ); - do{ - //ok_sent = sock.sendTo( sip_server, ans, sizeof( ans ) ); - ok_sent = sock.sendTo( sip_server, ans, strlen( ans ) ); - }while( ok_sent == 0 ); + int send = sock.sendTo( sip_server, ans, strlen( ans ) ); + + if( send != strlen( ans ) ) + { + if( debug_reconnect ) send_msg("Reconnect SIP -- Ok -- Call mode on"); + __reconnect__(); + miss_sip_ok_send_pkg++; + } if( debug_invite ) debug_msg("Call alocada -- Sip::status::%d :: ", status ); set_status( status, sip_on_call ); @@ -1147,10 +1166,15 @@ char ans[ 2000 ]; build_reply_package( ans, (unsigned char*)buffer ); - int bye_sent = sock.sendTo( sip_server, ans, strlen( ans ) ); - if( debug_invite ) debug_msg("sizeof( bye reply pkg ) :: %d", strlen( ans ) ); - if( debug_invite ) debug_msg("Server request BYE to %d ext", my_ext ); - if( debug_invite ) debug_msg("Bye request received from *"); + int send = sock.sendTo( sip_server, ans, strlen( ans ) ); + if( send == strlen( ans ) ) + { + if( debug_reconnect ) send_msg("Reconnect SIP -- RCV BYE from *"); + __reconnect__(); + miss_sip_rcv_bye_send_pkg++; + } + + if( debug_invite ) debug_msg("sizeof( bye reply pkg ) :: %d\nServer request BYE to %d ext\nBye request received from *", strlen( ans ), my_ext ); listen_SIP_server_return = my_ext; }