Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
69215cf9
Commit
69215cf9
authored
Mar 13, 2016
by
Deomid Ryabkov
Committed by
rojer
Mar 13, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjust poll timeout if there are timers enabled
PUBLISHED_FROM=bbdc998ab4170d55d40d067bab027ae52c9304ec
parent
f89b51ea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
8 deletions
+30
-8
mongoose.c
mongoose.c
+30
-8
No files found.
mongoose.c
View file @
69215cf9
...
...
@@ -3706,13 +3706,14 @@ void mg_add_to_set(sock_t sock, fd_set *set, sock_t *max_fd) {
}
}
time_t
mg_mgr_poll
(
struct
mg_mgr
*
mgr
,
int
milli
)
{
time_t
mg_mgr_poll
(
struct
mg_mgr
*
mgr
,
int
timeout_ms
)
{
double
now
=
mg_time
();
double
min_timer
;
struct
mg_connection
*
nc
,
*
tmp
;
struct
timeval
tv
;
fd_set
read_set
,
write_set
,
err_set
;
sock_t
max_fd
=
INVALID_SOCKET
;
int
num_fds
,
num_
selected
;
int
num_fds
,
num_
ev
,
num_timers
=
0
;
FD_ZERO
(
&
read_set
);
FD_ZERO
(
&
write_set
);
...
...
@@ -3721,6 +3722,7 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
mg_add_to_set
(
mgr
->
ctl
[
1
],
&
read_set
,
&
max_fd
);
#endif
min_timer
=
0
;
for
(
nc
=
mgr
->
active_connections
,
num_fds
=
0
;
nc
!=
NULL
;
nc
=
tmp
)
{
tmp
=
nc
->
next
;
...
...
@@ -3742,17 +3744,37 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
mg_add_to_set
(
nc
->
sock
,
&
write_set
,
&
max_fd
);
mg_add_to_set
(
nc
->
sock
,
&
err_set
,
&
max_fd
);
}
if
(
nc
->
ev_timer_time
>
0
)
{
if
(
num_timers
==
0
||
nc
->
ev_timer_time
<
min_timer
)
{
min_timer
=
nc
->
ev_timer_time
;
}
num_timers
++
;
}
}
/*
* If there is a timer to be fired earlier than the requested timeout,
* adjust the timeout.
*/
if
(
num_timers
>
0
)
{
double
timer_timeout_ms
=
(
min_timer
-
mg_time
())
*
1000
+
1
/* rounding */
;
if
(
timer_timeout_ms
<
timeout_ms
)
{
timeout_ms
=
timer_timeout_ms
;
}
}
if
(
timeout_ms
<
0
)
timeout_ms
=
0
;
tv
.
tv_sec
=
milli
/
1000
;
tv
.
tv_usec
=
(
milli
%
1000
)
*
1000
;
tv
.
tv_sec
=
timeout_ms
/
1000
;
tv
.
tv_usec
=
(
timeout_ms
%
1000
)
*
1000
;
num_
selected
=
select
((
int
)
max_fd
+
1
,
&
read_set
,
&
write_set
,
&
err_set
,
&
tv
);
num_
ev
=
select
((
int
)
max_fd
+
1
,
&
read_set
,
&
write_set
,
&
err_set
,
&
tv
);
now
=
mg_time
();
DBG
((
"select @ %ld num_ev=%d of %d"
,
(
long
)
now
,
num_selected
,
num_fds
));
DBG
((
"select @ %ld num_ev=%d of %d, timeout=%d"
,
(
long
)
now
,
num_ev
,
num_fds
,
timeout_ms
));
#ifndef MG_DISABLE_SOCKETPAIR
if
(
num_
selected
>
0
&&
mgr
->
ctl
[
1
]
!=
INVALID_SOCKET
&&
if
(
num_
ev
>
0
&&
mgr
->
ctl
[
1
]
!=
INVALID_SOCKET
&&
FD_ISSET
(
mgr
->
ctl
[
1
],
&
read_set
))
{
mg_mgr_handle_ctl_sock
(
mgr
);
}
...
...
@@ -3760,7 +3782,7 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
for
(
nc
=
mgr
->
active_connections
;
nc
!=
NULL
;
nc
=
tmp
)
{
int
fd_flags
=
0
;
if
(
num_
selected
>
0
)
{
if
(
num_
ev
>
0
)
{
fd_flags
=
(
FD_ISSET
(
nc
->
sock
,
&
read_set
)
?
_MG_F_FD_CAN_READ
:
0
)
|
(
FD_ISSET
(
nc
->
sock
,
&
write_set
)
?
_MG_F_FD_CAN_WRITE
:
0
)
|
(
FD_ISSET
(
nc
->
sock
,
&
err_set
)
?
_MG_F_FD_ERROR
:
0
);
...
...
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