Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
0923072a
Commit
0923072a
authored
Mar 06, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update backend class to support end of stream response
parent
1d0edfbd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
Backend.php
src/opnsense/mvc/app/library/OPNsense/Core/Backend.php
+23
-6
No files found.
src/opnsense/mvc/app/library/OPNsense/Core/Backend.php
View file @
0923072a
...
...
@@ -56,18 +56,35 @@ class Backend
*/
public
function
sendEvent
(
$event
,
$timeout
=
120
)
{
$stream
=
stream_socket_client
(
'unix://'
.
$this
->
configdSocket
,
$errorNumber
,
$errorMessage
,
$timeout
);
$endOfStream
=
chr
(
0
)
.
chr
(
0
)
.
chr
(
0
);
$resp
=
""
;
$stream
=
stream_socket_client
(
'unix://'
.
$this
->
configdSocket
,
$errorNumber
,
$errorMessage
,
$poll_timeout
);
if
(
$stream
===
false
)
{
throw
new
\Exception
(
"Failed to connect:
$errorMessage
"
);
}
stream_set_timeout
(
$stream
,
$timeout
);
stream_set_timeout
(
$stream
,
$poll_timeout
);
// send command
fwrite
(
$stream
,
$event
);
$resp
=
stream_get_contents
(
$stream
);
$info
=
stream_get_meta_data
(
$stream
);
if
(
$info
[
'timed_out'
]
==
1
)
{
throw
new
\Exception
(
"Timeout ("
.
$timeout
.
") executing :"
.
$event
);
// read response data
$pollcount
=
0
;
$poll_timeout
=
2
;
// poll timeout interval
while
(
true
)
{
$resp
=
$resp
.
stream_get_contents
(
$stream
);
if
(
strpos
(
$resp
,
$endOfStream
)
!==
false
)
{
// end of stream detected, exit
break
;
}
// handle timeouts
$pollcount
+=
1
;
if
((
$poll_timeout
*
$pollcount
)
>
$timeout
)
{
throw
new
\Exception
(
"Timeout ("
.
$timeout
.
") executing :"
.
$event
);
}
}
return
$resp
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment