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
36bfb66b
Commit
36bfb66b
authored
Oct 29, 2014
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io: update for new timer API.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
a9d42b8d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
14 deletions
+16
-14
ccan/io/io.h
ccan/io/io.h
+5
-4
ccan/io/poll.c
ccan/io/poll.c
+5
-5
ccan/io/test/run-15-timeout.c
ccan/io/test/run-15-timeout.c
+6
-5
No files found.
ccan/io/io.h
View file @
36bfb66b
...
...
@@ -7,6 +7,7 @@
#include <unistd.h>
struct
timers
;
struct
timer
;
struct
list_head
;
/**
...
...
@@ -629,16 +630,16 @@ struct io_plan *io_close_cb(struct io_conn *, void *unused);
/**
* io_loop - process fds until all closed on io_break.
* @timers - timers which are waiting to go off (or NULL for none)
* @expired - a
list filled with expired timers
(can be NULL if @timers is)
* @expired - a
n expired timer
(can be NULL if @timers is)
*
* This is the core loop; it exits with the io_break() arg, or NULL if
* all connections and listeners are closed, or with @expired set to a
*
list of expired timers
(if @timers isn't NULL).
* all connections and listeners are closed, or with @expired set to a
n
*
expired timer
(if @timers isn't NULL).
*
* Example:
* io_loop(NULL, NULL);
*/
void
*
io_loop
(
struct
timers
*
timers
,
struct
list_head
*
expired
);
void
*
io_loop
(
struct
timers
*
timers
,
struct
timer
*
*
expired
);
/**
* io_conn_fd - get the fd from a connection.
...
...
ccan/io/poll.c
View file @
36bfb66b
...
...
@@ -222,16 +222,16 @@ static bool handle_always(void)
}
/* This is the main loop. */
void
*
io_loop
(
struct
timers
*
timers
,
struct
list_head
*
expired
)
void
*
io_loop
(
struct
timers
*
timers
,
struct
timer
*
*
expired
)
{
void
*
ret
;
/* if timers is NULL, expired must be. If not, not. */
assert
(
!
timers
==
!
expired
);
/* Make sure this is
empty
if we exit for some other reason. */
/* Make sure this is
NULL
if we exit for some other reason. */
if
(
expired
)
list_head_init
(
expired
)
;
*
expired
=
NULL
;
while
(
!
io_loop_return
)
{
int
i
,
r
,
ms_timeout
=
-
1
;
...
...
@@ -259,8 +259,8 @@ void *io_loop(struct timers *timers, struct list_head *expired)
now
=
time_now
();
/* Call functions for expired timers. */
timers_expire
(
timers
,
now
,
expired
);
if
(
!
list_empty
(
expired
)
)
*
expired
=
timers_expire
(
timers
,
now
);
if
(
*
expired
)
break
;
/* Now figure out how long to wait for the next one. */
...
...
ccan/io/test/run-15-timeout.c
View file @
36bfb66b
...
...
@@ -90,7 +90,7 @@ int main(void)
struct
data
*
d
=
malloc
(
sizeof
(
*
d
));
struct
addrinfo
*
addrinfo
;
struct
io_listener
*
l
;
struct
list_head
expired
;
struct
timer
*
expired
;
int
fd
,
status
;
/* This is how many tests you plan to run */
...
...
@@ -98,6 +98,7 @@ int main(void)
d
->
state
=
0
;
d
->
timeout_usec
=
100000
;
timers_init
(
&
d
->
timers
,
time_now
());
timer_init
(
&
d
->
timer
);
fd
=
make_listen_fd
(
PORT
,
&
addrinfo
);
ok1
(
fd
>=
0
);
l
=
io_new_listener
(
NULL
,
fd
,
init_conn
,
d
);
...
...
@@ -129,15 +130,15 @@ int main(void)
ok1
(
io_loop
(
&
d
->
timers
,
&
expired
)
==
NULL
);
/* One element, d->timer. */
ok1
(
list_pop
(
&
expired
,
struct
timer
,
list
)
==
&
d
->
timer
);
ok1
(
list_empty
(
&
expired
));
ok1
(
expired
==
&
d
->
timer
);
ok1
(
!
timers_expire
(
&
d
->
timers
,
time_now
()
));
ok1
(
d
->
state
==
1
);
io_close
(
d
->
conn
);
/* Finished will be called, d will be returned */
ok1
(
io_loop
(
&
d
->
timers
,
&
expired
)
==
d
);
ok1
(
list_empty
(
&
expired
)
);
ok1
(
expired
==
NULL
);
ok1
(
d
->
state
==
2
);
/* It should have died. */
...
...
@@ -174,7 +175,7 @@ int main(void)
}
ok1
(
io_loop
(
&
d
->
timers
,
&
expired
)
==
d
);
ok1
(
d
->
state
==
3
);
ok1
(
list_empty
(
&
expired
)
);
ok1
(
expired
==
NULL
);
ok1
(
wait
(
&
status
));
ok1
(
WIFEXITED
(
status
));
ok1
(
WEXITSTATUS
(
status
)
>=
sizeof
(
d
->
buf
));
...
...
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