mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-19 19:15:22 +00:00
mvc: configdStream: poll_timeout should be configurable on controller layer
The default of 2 is fine for predictable processes or direct data passthrough, but any event-based mechanism might need to change this.
This commit is contained in:
parent
14ea1b96e8
commit
489b5d6c2e
@ -168,15 +168,17 @@ class ApiControllerBase extends ControllerRoot
|
||||
* @param string $action configd action to perform
|
||||
* @param array $params list of parameters
|
||||
* @param array $headers http headers to send before pushing data
|
||||
* @param int $poll_timeout poll timeout after connect
|
||||
*/
|
||||
protected function configdStream(
|
||||
$action,
|
||||
$params = [],
|
||||
$headers = [
|
||||
'Content-Type: application/json', 'Content-Transfer-Encoding: binary', 'Pragma: no-cache', 'Expires: 0'
|
||||
]
|
||||
],
|
||||
$poll_timeout = 2
|
||||
) {
|
||||
$response = (new Backend())->configdpStream($action, $params);
|
||||
$response = (new Backend())->configdpStream($action, $params, $poll_timeout);
|
||||
foreach ($headers as $header) {
|
||||
header($header);
|
||||
}
|
||||
|
||||
@ -29,8 +29,6 @@
|
||||
namespace OPNsense\Diagnostics\Api;
|
||||
|
||||
use OPNsense\Base\ApiControllerBase;
|
||||
use OPNsense\Core\Config;
|
||||
use OPNsense\Core\Backend;
|
||||
|
||||
/**
|
||||
* Class CpuUsage
|
||||
|
||||
@ -64,13 +64,12 @@ class Backend
|
||||
* @param bool $detach detach process
|
||||
* @param int $timeout timeout in seconds
|
||||
* @param int $connect_timeout connect timeout in seconds
|
||||
* @param int $poll_timeout poll timeout after connect
|
||||
* @return resource|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function configdStream($event, $detach = false, $timeout = 120, $connect_timeout = 10)
|
||||
public function configdStream($event, $detach = false, $timeout = 120, $connect_timeout = 10, $poll_timeout = 2)
|
||||
{
|
||||
$poll_timeout = 2; // poll timeout interval
|
||||
|
||||
// wait until socket exist for a maximum of $connect_timeout
|
||||
$timeout_wait = $connect_timeout;
|
||||
$errorMessage = "";
|
||||
@ -107,13 +106,14 @@ class Backend
|
||||
* send event to backend using command parameter list (which will be quoted for proper handling)
|
||||
* @param string $event event string
|
||||
* @param array $params list of parameters to send with command
|
||||
* @param int $poll_timeout poll timeout after connect
|
||||
* @param bool $detach detach process
|
||||
* @param int $timeout timeout in seconds
|
||||
* @param int $connect_timeout connect timeout in seconds
|
||||
* @return resource|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function configdpStream($event, $params = [], $detach = false, $timeout = 120, $connect_timeout = 10)
|
||||
public function configdpStream($event, $params = [], $poll_timeout = 2, $detach = false, $timeout = 120, $connect_timeout = 10)
|
||||
{
|
||||
if (!is_array($params)) {
|
||||
/* just in case there's only one parameter */
|
||||
@ -124,7 +124,7 @@ class Backend
|
||||
$event .= ' ' . escapeshellarg($param ?? '');
|
||||
}
|
||||
|
||||
return $this->configdStream($event, $detach, $timeout, $connect_timeout);
|
||||
return $this->configdStream($event, $detach, $timeout, $connect_timeout, $poll_timeout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user