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
e846b1a9
Commit
e846b1a9
authored
Jun 16, 2017
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io: allow overriding poll function.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
d00c9d1b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
2 deletions
+77
-2
ccan/io/backend.h
ccan/io/backend.h
+0
-1
ccan/io/io.h
ccan/io/io.h
+11
-0
ccan/io/poll.c
ccan/io/poll.c
+9
-1
ccan/io/test/run-41-io_poll_override.c
ccan/io/test/run-41-io_poll_override.c
+57
-0
No files found.
ccan/io/backend.h
View file @
e846b1a9
...
...
@@ -2,7 +2,6 @@
#ifndef CCAN_IO_BACKEND_H
#define CCAN_IO_BACKEND_H
#include <stdbool.h>
#include <poll.h>
#include "io_plan.h"
#include <ccan/list/list.h>
...
...
ccan/io/io.h
View file @
e846b1a9
...
...
@@ -4,6 +4,7 @@
#include <ccan/tal/tal.h>
#include <ccan/typesafe_cb/typesafe_cb.h>
#include <stdbool.h>
#include <poll.h>
#include <unistd.h>
struct
timers
;
...
...
@@ -701,4 +702,14 @@ bool io_flush_sync(struct io_conn *conn);
*/
struct
timemono
(
*
io_time_override
(
struct
timemono
(
*
now
)(
void
)))(
void
);
/**
* io_poll_override - override the normal call for poll.
* @pollfn: the function to call.
*
* io usually uses poll() internally, but this forces it to use your
* function (eg. for debugging, suppressing fds, or polling on others unknown
* to ccan/io). Returns the old one.
*/
int
(
*
io_poll_override
(
int
(
*
poll
)(
struct
pollfd
*
fds
,
nfds_t
nfds
,
int
timeout
)))(
struct
pollfd
*
,
nfds_t
,
int
);
#endif
/* CCAN_IO_H */
ccan/io/poll.c
View file @
e846b1a9
...
...
@@ -17,6 +17,7 @@ static struct fd **fds = NULL;
static
LIST_HEAD
(
closing
);
static
LIST_HEAD
(
always
);
static
struct
timemono
(
*
nowfn
)(
void
)
=
time_mono
;
static
int
(
*
pollfn
)(
struct
pollfd
*
fds
,
nfds_t
nfds
,
int
timeout
)
=
poll
;
struct
timemono
(
*
io_time_override
(
struct
timemono
(
*
now
)(
void
)))(
void
)
{
...
...
@@ -25,6 +26,13 @@ struct timemono (*io_time_override(struct timemono (*now)(void)))(void)
return
old
;
}
int
(
*
io_poll_override
(
int
(
*
poll
)(
struct
pollfd
*
fds
,
nfds_t
nfds
,
int
timeout
)))(
struct
pollfd
*
,
nfds_t
,
int
)
{
int
(
*
old
)(
struct
pollfd
*
fds
,
nfds_t
nfds
,
int
timeout
)
=
pollfn
;
pollfn
=
poll
;
return
old
;
}
static
bool
add_fd
(
struct
fd
*
fd
,
short
events
)
{
if
(
!
max_fds
)
{
...
...
@@ -269,7 +277,7 @@ void *io_loop(struct timers *timers, struct timer **expired)
}
}
r
=
poll
(
pollfds
,
num_fds
,
ms_timeout
);
r
=
poll
fn
(
pollfds
,
num_fds
,
ms_timeout
);
if
(
r
<
0
)
break
;
...
...
ccan/io/test/run-41-io_poll_override.c
0 → 100644
View file @
e846b1a9
#include <ccan/io/io.h>
/* Include the C files directly. */
#include <ccan/io/poll.c>
#include <ccan/io/io.c>
#include <ccan/tap/tap.h>
#include <sys/wait.h>
#include <stdio.h>
#define PORT "65020"
/* Should be looking to read from one fd. */
static
int
mypoll
(
struct
pollfd
*
fds
,
nfds_t
nfds
,
int
timeout
)
{
ok1
(
nfds
==
1
);
ok1
(
fds
[
0
].
fd
>=
0
);
ok1
(
fds
[
0
].
events
&
POLLIN
);
ok1
(
!
(
fds
[
0
].
events
&
POLLOUT
));
/* Pretend it's readable. */
fds
[
0
].
revents
=
POLLIN
;
return
1
;
}
static
int
check_cant_read
(
int
fd
,
struct
io_plan_arg
*
arg
)
{
char
c
;
ssize_t
ret
=
read
(
fd
,
&
c
,
1
);
ok1
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
);
ok1
(
ret
==
-
1
);
return
1
;
}
static
struct
io_plan
*
setup_conn
(
struct
io_conn
*
conn
,
void
*
unused
)
{
/* Need to get this to mark it IO_POLLING */
io_plan_arg
(
conn
,
IO_IN
);
return
io_set_plan
(
conn
,
IO_IN
,
check_cant_read
,
io_close_cb
,
NULL
);
}
int
main
(
void
)
{
int
fds
[
2
];
plan_tests
(
8
);
pipe
(
fds
);
ok1
(
io_poll_override
(
mypoll
)
==
poll
);
io_new_conn
(
NULL
,
fds
[
0
],
setup_conn
,
NULL
);
ok1
(
io_loop
(
NULL
,
NULL
)
==
NULL
);
close
(
fds
[
1
]);
/* This exits depending on whether all tests passed */
return
exit_status
();
}
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