From da95fb628df6c02522720444442f58cb6672c59f Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Thu, 20 Jan 2011 11:24:50 +0100 Subject: [PATCH] enhanced IP network management --- Classes/PhoneViewController.m | 2 +- Classes/linphoneAppDelegate.h | 2 +- Classes/linphoneAppDelegate.m | 29 +++++++++++++++-------------- linphonerc | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Classes/PhoneViewController.m b/Classes/PhoneViewController.m index 9bb419530..81f37d823 100644 --- a/Classes/PhoneViewController.m +++ b/Classes/PhoneViewController.m @@ -371,7 +371,7 @@ otherButtonTitles:nil]; [error show]; //[self performSelector:@selector(dismissAlertDialog:) withObject:error afterDelay:2]; - //[self performSelector:@selector(dismissIncallView) withObject:nil afterDelay:2]; + [self performSelector:@selector(dismissIncallView) withObject:nil afterDelay:2]; } break; diff --git a/Classes/linphoneAppDelegate.h b/Classes/linphoneAppDelegate.h index 540d4a2f0..ac23e941b 100644 --- a/Classes/linphoneAppDelegate.h +++ b/Classes/linphoneAppDelegate.h @@ -76,7 +76,7 @@ /** * return true if register is activated */ -bool networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void * info); +void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void * info); -(void) doRegister; -(void) doLinphoneConfiguration:(NSNotification *)notification; diff --git a/Classes/linphoneAppDelegate.m b/Classes/linphoneAppDelegate.m index 31737ff87..d57926936 100644 --- a/Classes/linphoneAppDelegate.m +++ b/Classes/linphoneAppDelegate.m @@ -275,15 +275,17 @@ LinphoneCoreVTable linphonec_vtable = { } -(void) kickOffNetworkConnection { - ms_message("waiking up network connection"); + /*start a new thread to avoid blocking the main ui in case of peer host failure*/ + [NSThread detachNewThreadSelector:@selector(runNetworkConnection) toTarget:self withObject:nil]; +} +-(void) runNetworkConnection { CFWriteStreamRef writeStream; - CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"linphone.org", 15000, nil, &writeStream); + CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.0.200"/*"linphone.org"*/, 15000, nil, &writeStream); CFWriteStreamOpen (writeStream); const char* buff="hello"; CFWriteStreamWrite (writeStream,(const UInt8*)buff,strlen(buff)); CFWriteStreamClose (writeStream); - -} +} - (void)applicationDidBecomeActive:(UIApplication *)application { if (myLinphoneCore == nil) { @@ -406,6 +408,9 @@ extern void libmsilbc_init(); } NSString* transport = [[NSUserDefaults standardUserDefaults] stringForKey:@"transport_preference"]; + //initial state is network off should be done as soon as possible + linphone_core_set_network_reachable(myLinphoneCore,false); + LCSipTransports transportValue; if (transport!=nil) { if (linphone_core_get_sip_transports(myLinphoneCore, &transportValue)) { @@ -427,8 +432,7 @@ extern void libmsilbc_init(); - //initial state is network off - linphone_core_set_network_reachable(myLinphoneCore,false); + // Set audio assets NSBundle* myBundle = [NSBundle mainBundle]; const char* lRing = [[myBundle pathForResource:@"oldphone-mono"ofType:@"wav"] cStringUsingEncoding:[NSString defaultCStringEncoding]]; @@ -657,22 +661,19 @@ extern void libmsilbc_init(); } -bool networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void * info) { +void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void * info) { id linphoneDelegate=info; LinphoneCore* lc = [linphoneDelegate getLinphoneCore]; bool result = false; - + ms_message("Network connection flag [%x]",flags); if (lc != nil) { if ((flags == 0) | (flags & (kSCNetworkReachabilityFlagsConnectionRequired |kSCNetworkReachabilityFlagsConnectionOnTraffic))) { [linphoneDelegate kickOffNetworkConnection]; - } - if (flags) { - linphone_core_set_network_reachable(lc,true); - result = true; - } else { linphone_core_set_network_reachable(lc,false); - result = false; + } else { + linphone_core_set_network_reachable(lc,true); } + } return result; } diff --git a/linphonerc b/linphonerc index 7bfbc4584..89eabc1bc 100644 --- a/linphonerc +++ b/linphonerc @@ -11,8 +11,8 @@ contact=sip:toto@unknown-host inc_timeout=15 use_info=0 use_ipv6=0 -register_only_when_network_is_up=0 default_proxy=-1 +register_only_when_network_is_up=1 auto_net_state_mon=0 keepalive_period=3600000