Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117894847
D5184.1775369925.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D5184.1775369925.diff
View Options
diff --git a/lib/ext/Syncroton/Command/Ping.php b/lib/ext/Syncroton/Command/Ping.php
--- a/lib/ext/Syncroton/Command/Ping.php
+++ b/lib/ext/Syncroton/Command/Ping.php
@@ -37,6 +37,23 @@
protected $_changesDetected = false;
protected $_foldersWithChanges = [];
+ private function goToSleep($sleepInterval) {
+ // take a break to save battery lifetime
+ call_user_func(Syncroton_Registry::getSleepCallback());
+ sleep($sleepInterval);
+
+ // make sure the connection is still alive, abort otherwise
+ if (connection_aborted()) {
+ if ($this->_logger instanceof Zend_Log) {
+ $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " Exiting on aborted connection");
+ }
+ exit;
+ }
+
+ // reconnect external connections, etc.
+ call_user_func(Syncroton_Registry::getWakeupCallback());
+ }
+
/**
* process the XML file and add, change, delete or fetches data
*
@@ -110,7 +127,6 @@
}
$intervalEnd = $intervalStart + $lifeTime;
- $secondsLeft = $intervalEnd;
$folders = $this->_device->pingfolder ? unserialize($this->_device->pingfolder) : [];
@@ -123,29 +139,7 @@
}
if ($status === self::STATUS_NO_CHANGES_FOUND) {
- $sleepCallback = Syncroton_Registry::getSleepCallback();
- $wakeupCallback = Syncroton_Registry::getWakeupCallback();
-
do {
- // take a break to save battery lifetime
- call_user_func($sleepCallback);
- sleep(min(Syncroton_Registry::getPingTimeout(), $lifeTime));
-
- // make sure the connection is still alive, abort otherwise
- if (connection_aborted()) {
- if ($this->_logger instanceof Zend_Log) {
- $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " Exiting on aborted connection");
- }
- exit;
- }
-
- // reconnect external connections, etc.
- call_user_func($wakeupCallback);
-
- // Calculate secondsLeft before any loop break just to have a correct value
- // for logging purposes in case we breaked from the loop early
- $secondsLeft = $intervalEnd - time();
-
try {
/** @var Syncroton_Model_Device $device */
$device = $this->_deviceBackend->get($this->_device->id);
@@ -259,7 +253,6 @@
break;
}
- // Update secondsLeft (again)
$secondsLeft = $intervalEnd - time();
if ($this->_logger instanceof Zend_Log) {
@@ -271,9 +264,16 @@
// break if there are less than PingTimeout + 10 seconds left for the next loop
// otherwise the response will be returned after the client has finished his Ping
// request already maybe
- } while (Syncroton_Server::validateSession() && $secondsLeft > (Syncroton_Registry::getPingTimeout() + 10));
+ if ($secondsLeft < (Syncroton_Registry::getPingTimeout() + 10)) {
+ break;
+ } else {
+ $this->goToSleep(Syncroton_Registry::getPingTimeout());
+ }
+
+ } while (Syncroton_Server::validateSession());
}
+ $secondsLeft = $intervalEnd - time();
if ($this->_logger instanceof Zend_Log) {
$this->_logger->info(__METHOD__ . '::' . __LINE__ . " DeviceId: " . $this->_device->deviceid . " Lifetime: $lifeTime SecondsLeft: $secondsLeft Status: $status)");
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 5, 6:18 AM (16 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18832618
Default Alt Text
D5184.1775369925.diff (3 KB)
Attached To
Mode
D5184: Sleep after the loop so we can respond immediately
Attached
Detach File
Event Timeline