Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
8cb4a3ed
Commit
8cb4a3ed
authored
Oct 31, 2016
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io: update to use time_mono() for timers.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
4ba10490
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
18 deletions
+17
-18
ccan/io/io.h
ccan/io/io.h
+2
-2
ccan/io/poll.c
ccan/io/poll.c
+5
-5
ccan/io/test/run-15-timeout.c
ccan/io/test/run-15-timeout.c
+3
-4
ccan/io/test/run-20-io_time_override.c
ccan/io/test/run-20-io_time_override.c
+7
-7
No files found.
ccan/io/io.h
View file @
8cb4a3ed
...
...
@@ -654,11 +654,11 @@ int io_conn_fd(const struct io_conn *conn);
* io_time_override - override the normal call for time.
* @nowfn: the function to call.
*
* io usually uses time_
now
() internally, but this forces it
* io usually uses time_
mono
() internally, but this forces it
* to use your function (eg. for debugging). Returns the old
* one.
*/
struct
time
abs
(
*
io_time_override
(
struct
timeabs
(
*
now
)(
void
)))(
void
);
struct
time
mono
(
*
io_time_override
(
struct
timemono
(
*
now
)(
void
)))(
void
);
/**
* io_set_debug - set synchronous mode on a connection.
...
...
ccan/io/poll.c
View file @
8cb4a3ed
...
...
@@ -16,11 +16,11 @@ static struct pollfd *pollfds = NULL;
static
struct
fd
**
fds
=
NULL
;
static
LIST_HEAD
(
closing
);
static
LIST_HEAD
(
always
);
static
struct
time
abs
(
*
nowfn
)(
void
)
=
time_now
;
static
struct
time
mono
(
*
nowfn
)(
void
)
=
time_mono
;
struct
time
abs
(
*
io_time_override
(
struct
timeabs
(
*
now
)(
void
)))(
void
)
struct
time
mono
(
*
io_time_override
(
struct
timemono
(
*
now
)(
void
)))(
void
)
{
struct
time
abs
(
*
old
)(
void
)
=
nowfn
;
struct
time
mono
(
*
old
)(
void
)
=
nowfn
;
nowfn
=
now
;
return
old
;
}
...
...
@@ -262,7 +262,7 @@ void *io_loop(struct timers *timers, struct timer **expired)
assert
(
num_waiting
);
if
(
timers
)
{
struct
time
abs
now
,
first
;
struct
time
mono
now
,
first
;
now
=
nowfn
();
...
...
@@ -274,7 +274,7 @@ void *io_loop(struct timers *timers, struct timer **expired)
/* Now figure out how long to wait for the next one. */
if
(
timer_earliest
(
timers
,
&
first
))
{
uint64_t
next
;
next
=
time_to_msec
(
time_between
(
first
,
now
));
next
=
time_to_msec
(
time
mono
_between
(
first
,
now
));
if
(
next
<
INT_MAX
)
ms_timeout
=
next
;
else
...
...
ccan/io/test/run-15-timeout.c
View file @
8cb4a3ed
...
...
@@ -47,8 +47,7 @@ static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
d
->
conn
=
conn
;
io_set_finish
(
conn
,
finish_ok
,
d
);
timer_add
(
&
d
->
timers
,
&
d
->
timer
,
timeabs_add
(
time_now
(),
time_from_usec
(
d
->
timeout_usec
)));
timer_addrel
(
&
d
->
timers
,
&
d
->
timer
,
time_from_usec
(
d
->
timeout_usec
));
return
io_read
(
conn
,
d
->
buf
,
sizeof
(
d
->
buf
),
no_timeout
,
d
);
}
...
...
@@ -97,7 +96,7 @@ int main(void)
plan_tests
(
21
);
d
->
state
=
0
;
d
->
timeout_usec
=
100000
;
timers_init
(
&
d
->
timers
,
time_
now
());
timers_init
(
&
d
->
timers
,
time_
mono
());
timer_init
(
&
d
->
timer
);
fd
=
make_listen_fd
(
PORT
,
&
addrinfo
);
ok1
(
fd
>=
0
);
...
...
@@ -131,7 +130,7 @@ int main(void)
/* One element, d->timer. */
ok1
(
expired
==
&
d
->
timer
);
ok1
(
!
timers_expire
(
&
d
->
timers
,
time_
now
()));
ok1
(
!
timers_expire
(
&
d
->
timers
,
time_
mono
()));
ok1
(
d
->
state
==
1
);
io_close
(
d
->
conn
);
...
...
ccan/io/test/run-20-io_time_override.c
View file @
8cb4a3ed
...
...
@@ -45,9 +45,9 @@ static int make_listen_fd(const char *port, struct addrinfo **info)
return
fd
;
}
static
struct
time
abs
fake_time
;
static
struct
time
mono
fake_time
;
static
struct
time
abs
get_fake_time
(
void
)
static
struct
time
mono
get_fake_time
(
void
)
{
return
fake_time
;
}
...
...
@@ -63,12 +63,12 @@ int main(void)
/* This is how many tests you plan to run */
plan_tests
(
7
);
fake_time
=
time_
now
();
fake_time
=
time_
mono
();
timers_init
(
&
timers
,
fake_time
);
timer_init
(
&
timer
);
timer_add
(
&
timers
,
&
timer
,
timeabs
_add
(
fake_time
,
time_from_sec
(
1000
)));
timer_add
mono
(
&
timers
,
&
timer
,
timemono
_add
(
fake_time
,
time_from_sec
(
1000
)));
fd
=
make_listen_fd
(
PORT
,
&
addrinfo
);
freeaddrinfo
(
addrinfo
);
...
...
@@ -77,12 +77,12 @@ int main(void)
ok1
(
l
);
fake_time
.
ts
.
tv_sec
+=
1000
;
ok1
(
io_time_override
(
get_fake_time
)
==
time_
now
);
ok1
(
io_time_override
(
get_fake_time
)
==
time_
mono
);
ok1
(
io_loop
(
&
timers
,
&
expired
)
==
NULL
);
ok1
(
expired
==
&
timer
);
ok1
(
!
timers_expire
(
&
timers
,
fake_time
));
ok1
(
io_time_override
(
time_
now
)
==
get_fake_time
);
ok1
(
io_time_override
(
time_
mono
)
==
get_fake_time
);
io_close_listener
(
l
);
timers_cleanup
(
&
timers
);
...
...
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