Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
84ac79bb
Commit
84ac79bb
authored
Aug 10, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/MultiSocketMonitor: eliminate virtual method CheckSockets()
Handle timeout internally.
parent
be0c8495
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
36 deletions
+16
-36
MultiSocketMonitor.cxx
src/event/MultiSocketMonitor.cxx
+14
-2
MultiSocketMonitor.hxx
src/event/MultiSocketMonitor.hxx
+2
-6
CurlInputPlugin.cxx
src/input/CurlInputPlugin.cxx
+0
-28
No files found.
src/event/MultiSocketMonitor.cxx
View file @
84ac79bb
...
...
@@ -42,7 +42,8 @@ static GSourceFuncs multi_socket_monitor_source_funcs = {
MultiSocketMonitor
::
MultiSocketMonitor
(
EventLoop
&
_loop
)
:
loop
(
_loop
),
source
((
Source
*
)
g_source_new
(
&
multi_socket_monitor_source_funcs
,
sizeof
(
*
source
)))
{
sizeof
(
*
source
))),
absolute_timeout_us
(
G_MAXINT64
)
{
source
->
monitor
=
this
;
g_source_attach
(
&
source
->
base
,
loop
.
GetContext
());
...
...
@@ -56,9 +57,20 @@ MultiSocketMonitor::~MultiSocketMonitor()
}
bool
MultiSocketMonitor
::
Prepare
(
gint
*
timeout_r
)
{
int
timeout_ms
=
*
timeout_r
=
PrepareSockets
();
absolute_timeout_us
=
timeout_ms
<
0
?
G_MAXINT64
:
GetTime
()
+
gint64
(
timeout_ms
)
*
1000
;
return
false
;
}
bool
MultiSocketMonitor
::
Check
()
const
{
if
(
CheckSockets
()
)
if
(
GetTime
()
>=
absolute_timeout_us
)
return
true
;
for
(
const
auto
&
i
:
fds
)
...
...
src/event/MultiSocketMonitor.hxx
View file @
84ac79bb
...
...
@@ -52,6 +52,7 @@ class MultiSocketMonitor {
EventLoop
&
loop
;
Source
*
source
;
gint64
absolute_timeout_us
;
std
::
forward_list
<
GPollFD
>
fds
;
public
:
...
...
@@ -105,7 +106,6 @@ protected:
* @return timeout [ms] or -1 for no timeout
*/
virtual
int
PrepareSockets
()
=
0
;
virtual
bool
CheckSockets
()
const
{
return
false
;
}
virtual
void
DispatchSockets
()
=
0
;
public
:
...
...
@@ -116,11 +116,7 @@ public:
gpointer
user_data
);
private
:
bool
Prepare
(
gint
*
timeout_r
)
{
*
timeout_r
=
PrepareSockets
();
return
false
;
}
bool
Prepare
(
gint
*
timeout_r
);
bool
Check
()
const
;
void
Dispatch
()
{
...
...
src/input/CurlInputPlugin.cxx
View file @
84ac79bb
...
...
@@ -183,18 +183,6 @@ struct input_curl {
* This class monitors all CURL file descriptors.
*/
class
CurlSockets
final
:
private
MultiSocketMonitor
{
/**
* Did CURL give us a timeout? If yes, then we need to call
* curl_multi_perform(), even if there was no event on any
* file descriptor.
*/
bool
have_timeout
;
/**
* The absolute time stamp when the timeout expires.
*/
gint64
absolute_timeout
;
public
:
CurlSockets
(
EventLoop
&
_loop
)
:
MultiSocketMonitor
(
_loop
)
{}
...
...
@@ -205,7 +193,6 @@ private:
void
UpdateSockets
();
virtual
int
PrepareSockets
()
override
;
virtual
bool
CheckSockets
()
const
override
;
virtual
void
DispatchSockets
()
override
;
};
...
...
@@ -541,14 +528,9 @@ CurlSockets::PrepareSockets()
{
UpdateSockets
();
have_timeout
=
false
;
long
timeout2
;
CURLMcode
mcode
=
curl_multi_timeout
(
curl
.
multi
,
&
timeout2
);
if
(
mcode
==
CURLM_OK
)
{
if
(
timeout2
>=
0
)
absolute_timeout
=
GetTime
()
+
timeout2
*
1000
;
if
(
timeout2
>=
0
&&
timeout2
<
10
)
/* CURL 7.21.1 likes to report "timeout=0",
which means we're running in a busy loop.
...
...
@@ -556,7 +538,6 @@ CurlSockets::PrepareSockets()
Let's use a lower limit of 10ms. */
timeout2
=
10
;
have_timeout
=
timeout2
>=
0
;
return
timeout2
;
}
else
{
g_warning
(
"curl_multi_timeout() failed: %s
\n
"
,
...
...
@@ -565,15 +546,6 @@ CurlSockets::PrepareSockets()
}
}
bool
CurlSockets
::
CheckSockets
()
const
{
/* when a timeout has expired, we need to call
curl_multi_perform(), even if there was no file descriptor
event */
return
have_timeout
&&
GetTime
()
>=
absolute_timeout
;
}
void
CurlSockets
::
DispatchSockets
()
{
...
...
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