Changeset 4601 in subversion
- Timestamp:
- Mar 9, 2011 5:30:15 AM (2 years ago)
- Location:
- trunk/roundcubemail
- Files:
-
- 2 edited
-
CHANGELOG (modified) (1 diff)
-
program/include/rcube_imap_generic.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/CHANGELOG
r4599 r4601 2 2 =========================== 3 3 4 - Add code for prevention from IMAP connection hangs when server closes socket unexpectedly 4 5 - Remove redundant DELETE query (for old session deletion) on login 5 6 - Get around unreliable rand() and mt_rand() in session ID generation (#1486281) -
trunk/roundcubemail/program/include/rcube_imap_generic.php
r4592 r4601 214 214 $line = ''; 215 215 216 if (!$this->fp) {217 return NULL;218 }219 220 216 if (!$size) { 221 217 $size = 1024; … … 223 219 224 220 do { 225 if ( feof($this->fp)) {221 if ($this->eof()) { 226 222 return $line ? $line : NULL; 227 223 } … … 230 226 231 227 if ($buffer === false) { 232 @fclose($this->fp); 233 $this->fp = null; 228 $this->closeSocket(); 234 229 break; 235 230 } … … 238 233 } 239 234 $line .= $buffer; 240 } while ( $buffer[strlen($buffer)-1]!= "\n");235 } while (substr($buffer, -1) != "\n"); 241 236 242 237 return $line; … … 268 263 $data = ''; 269 264 $len = 0; 270 while ($len < $bytes && ! feof($this->fp))265 while ($len < $bytes && !$this->eof()) 271 266 { 272 267 $d = fread($this->fp, $bytes-$len); … … 313 308 $this->errornum = self::ERROR_BAD; 314 309 } else if ($res == 'BYE') { 315 @fclose($this->fp); 316 $this->fp = null; 310 $this->closeSocket(); 317 311 $this->errornum = self::ERROR_BYE; 318 312 } … … 340 334 } 341 335 336 private function eof() 337 { 338 if (!is_resource($this->fp)) { 339 return true; 340 } 341 342 // If a connection opened by fsockopen() wasn't closed 343 // by the server, feof() will hang. 344 $start = microtime(true); 345 346 if (feof($this->fp) || 347 ($this->prefs['timeout'] && (microtime(true) - $start > $this->prefs['timeout'])) 348 ) { 349 $this->closeSocket(); 350 return true; 351 } 352 353 return false; 354 } 355 356 private function closeSocket() 357 { 358 @fclose($this->fp); 359 $this->fp = null; 360 } 361 342 362 function setError($code, $msg='') 343 363 { … … 361 381 if ($error && preg_match('/^\* (BYE|BAD) /i', $string, $m)) { 362 382 if (strtoupper($m[1]) == 'BYE') { 363 @fclose($this->fp); 364 $this->fp = null; 383 $this->closeSocket(); 365 384 } 366 385 return true; … … 702 721 } 703 722 723 if ($this->prefs['timeout'] <= 0) { 724 $this->prefs['timeout'] = ini_get('default_socket_timeout'); 725 } 726 704 727 // Connect 705 if ($this->prefs['timeout'] > 0) 706 $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr, $this->prefs['timeout']); 707 else 708 $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr); 728 $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr, $this->prefs['timeout']); 709 729 710 730 if (!$this->fp) { … … 849 869 } 850 870 851 @fclose($this->fp); 852 $this->fp = false; 871 $this->closeSocket(); 853 872 } 854 873
Note: See TracChangeset
for help on using the changeset viewer.
