Added better error handling to signon method

This commit is contained in:
Luke Fitzgerald 2010-06-14 04:26:41 +01:00
parent 3d6bb5a597
commit d1c9908282
1 changed files with 109 additions and 100 deletions

View File

@ -139,6 +139,7 @@ class MSN {
}
$this->debug = isset($Configs['debug']) ? $Configs['debug'] : false;
$this->timeout = $timeout;
// check support
if (!function_exists('curl_init')) throw new Exception("We need curl module!\n");
if (!function_exists('preg_match')) throw new Exception("We need pcre module!\n");
@ -1089,21 +1090,22 @@ class MSN {
*/
public function signon() {
$this->log_message("*** try to connect to MSN network");
while(true) {
while(!$this->connect($this->user, $this->password))
{
$this->signonFailed("!!! Can't connect to server: $this->error");
$this->signonFailure("!!! Can't connect to server: $this->error");
}
if(!$this->UpdateContacts()) {
$this->signonFailed('!!! Could not update contacts');
return $this->signon();
if($this->UpdateContacts() === false) {
$this->signonFailure('!!! Update Contacts failed');
continue;
}
$this->LastPing=time();
$this->log_message("*** connected, wait for command");
$start_tm = time();
$ping_tm = time();
if(($this->aContactList = $this->getMembershipList()) === false) {
$this->signonFailed('!!! Could not get Membership List');
return $this->signon();
continue;
}
if ($this->update_pending) {
if (is_array($this->aContactList)) {
@ -1203,9 +1205,16 @@ class MSN {
$len = strlen($str);
$this->ns_writeln("UUX $this->id $len");
$this->ns_writedata($str);
break;
}
}
private function signonFailed($message) {
/**
* Called if there is an error during signon
*
* @param $message Error message to log
*/
private function signonFailure($message) {
$this->log_message($message);
$this->callHandler('ConnectFailed', NULL);
$this->NSRetryWait($this->retry_wait);