]> git.ozlabs.org Git - ccan/blob - ccan/io/io.h
1e4e80e7db779410b72a80428c65b12e8137218f
[ccan] / ccan / io / io.h
1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
2 #ifndef CCAN_IO_H
3 #define CCAN_IO_H
4 #include <ccan/tal/tal.h>
5 #include <ccan/typesafe_cb/typesafe_cb.h>
6 #include <stdbool.h>
7 #include <poll.h>
8 #include <unistd.h>
9
10 struct timers;
11 struct timer;
12 struct list_head;
13
14 /**
15  * struct io_plan - a plan for input or output.
16  *
17  * Each io_conn has zero to two of these active at any time.
18  */
19 struct io_plan;
20
21 /**
22  * struct io_conn - a connection associated with an fd.
23  */
24 struct io_conn;
25
26 /**
27  * io_new_conn - create a new connection.
28  * @ctx: the context to tal from (or NULL)
29  * @fd: the file descriptor.
30  * @init: the function to call for a new connection
31  * @arg: the argument to @init.
32  *
33  * This creates a connection which owns @fd, it then calls
34  * @init to initialize the connection, which sets up an io_plan.
35  *
36  * Returns NULL on error (and sets errno).
37  *
38  * Example:
39  * // Dumb init function to print string and tell conn to close.
40  * static struct io_plan *conn_init(struct io_conn *conn, const char *msg)
41  * {
42  *      printf("Created conn %p: %s", conn, msg);
43  *      return io_close(conn);
44  * }
45  *
46  * static void create_self_closing_pipe(void)
47  * {
48  *      int fd[2];
49  *      struct io_conn *conn;
50  *
51  *      if (pipe(fd) != 0)
52  *              exit(1);
53  *      conn = io_new_conn(NULL, fd[0], conn_init, (const char *)"hi!");
54  *      if (!conn)
55  *              exit(1);
56  * }
57  */
58 #define io_new_conn(ctx, fd, init, arg)                                 \
59         io_new_conn_((ctx), (fd),                                       \
60                      typesafe_cb_preargs(struct io_plan *, void *,      \
61                                          (init), (arg),                 \
62                                          struct io_conn *conn),         \
63                      (void *)(arg))
64
65 struct io_conn *io_new_conn_(const tal_t *ctx, int fd,
66                              struct io_plan *(*init)(struct io_conn *, void *),
67                              void *arg);
68
69 /**
70  * io_set_finish - set finish function on a connection.
71  * @conn: the connection.
72  * @finish: the function to call when it's closed or fails.
73  * @arg: the argument to @finish.
74  *
75  * @finish will be called when an I/O operation fails, or you call
76  * io_close() on the connection.  errno will be set to the value
77  * after the failed I/O, or at the call to io_close().  The fd
78  * will be closed before @finish is called.
79  *
80  * Example:
81  * static void finish(struct io_conn *conn, const char *msg)
82  * {
83  *      // errno is not 0 after success, so this is a bit useless.
84  *      printf("Conn %p closed with errno %i (%s)\n", conn, errno, msg);
85  * }
86  *
87  * // Dumb init function to print string and tell conn to close.
88  * static struct io_plan *conn_init(struct io_conn *conn, const char *msg)
89  * {
90  *      io_set_finish(conn, finish, msg);
91  *      return io_close(conn);
92  * }
93  */
94 #define io_set_finish(conn, finish, arg)                                \
95         io_set_finish_((conn),                                          \
96                        typesafe_cb_preargs(void, void *,                \
97                                            (finish), (arg),             \
98                                            struct io_conn *),           \
99                        (void *)(arg))
100 void io_set_finish_(struct io_conn *conn,
101                     void (*finish)(struct io_conn *, void *),
102                     void *arg);
103
104
105 /**
106  * io_new_listener - create a new accepting listener.
107  * @ctx: the context to tal from (or NULL)
108  * @fd: the file descriptor.
109  * @init: the function to call for a new connection
110  * @arg: the argument to @init.
111  *
112  * When @fd becomes readable, we accept(), create a new connection,
113  * (tal'ocated off @ctx) and pass that to init().  Note that if there is
114  * an error on this file descriptor, it will be freed.
115  *
116  * Returns NULL on error (and sets errno).
117  *
118  * Example:
119  * #include <sys/types.h>
120  * #include <sys/socket.h>
121  * #include <netdb.h>
122  *
123  * ...
124  *
125  * // Set up a listening socket, return it.
126  * static struct io_listener *do_listen(const char *port)
127  * {
128  *      struct addrinfo *addrinfo, hints;
129  *      int fd, on = 1;
130  *
131  *      memset(&hints, 0, sizeof(hints));
132  *      hints.ai_family = AF_UNSPEC;
133  *      hints.ai_socktype = SOCK_STREAM;
134  *      hints.ai_flags = AI_PASSIVE;
135  *      hints.ai_protocol = 0;
136  *
137  *      if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
138  *              return NULL;
139  *
140  *      fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
141  *                  addrinfo->ai_protocol);
142  *      if (fd < 0)
143  *              return NULL;
144  *
145  *      freeaddrinfo(addrinfo);
146  *      setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
147  *      if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
148  *              close(fd);
149  *              return NULL;
150  *      }
151  *      if (listen(fd, 1) != 0) {
152  *              close(fd);
153  *              return NULL;
154  *      }
155  *      return io_new_listener(NULL, fd, conn_init, (const char *)"listened!");
156  * }
157  */
158 #define io_new_listener(ctx, fd, init, arg)                             \
159         io_new_listener_((ctx), (fd),                                   \
160                          typesafe_cb_preargs(struct io_plan *, void *,  \
161                                              (init), (arg),             \
162                                              struct io_conn *conn),     \
163                          (void *)(arg))
164 struct io_listener *io_new_listener_(const tal_t *ctx, int fd,
165                                      struct io_plan *(*init)(struct io_conn *,
166                                                              void *),
167                                      void *arg);
168
169 /**
170  * io_close_listener - delete a listener.
171  * @listener: the listener returned from io_new_listener.
172  *
173  * This closes the fd and frees @listener.
174  *
175  * Example:
176  * ...
177  *      struct io_listener *l = do_listen("8111");
178  *      if (l) {
179  *              io_loop(NULL, NULL);
180  *              io_close_listener(l);
181  *      }
182  */
183 void io_close_listener(struct io_listener *listener);
184
185 /**
186  * io_write - output plan to write data.
187  * @conn: the connection that plan is for.
188  * @data: the data buffer.
189  * @len: the length to write.
190  * @next: function to call output is done.
191  * @arg: @next argument
192  *
193  * This updates the output plan, to write out a data buffer.  Once it's all
194  * written, the @next function will be called: on an error, the finish
195  * function is called instead.
196  *
197  * Note that the I/O may actually be done immediately.
198  *
199  * Example:
200  * static struct io_plan *write_to_conn(struct io_conn *conn, const char *msg)
201  * {
202  *      // Write message, then close.
203  *      return io_write(conn, msg, strlen(msg), io_close_cb, NULL);
204  * }
205  */
206 #define io_write(conn, data, len, next, arg)                            \
207         io_write_((conn), (data), (len),                                \
208                   typesafe_cb_preargs(struct io_plan *, void *,         \
209                                       (next), (arg), struct io_conn *), \
210                   (arg))
211 struct io_plan *io_write_(struct io_conn *conn,
212                           const void *data, size_t len,
213                           struct io_plan *(*next)(struct io_conn *, void *),
214                           void *arg);
215
216 /**
217  * io_read - input plan to read data.
218  * @conn: the connection that plan is for.
219  * @data: the data buffer.
220  * @len: the length to read.
221  * @next: function to call once input is done.
222  * @arg: @next argument
223  *
224  * This creates a plan to read data into a buffer.  Once it's all
225  * read, the @next function will be called: on an error, the finish
226  * function is called instead.
227  *
228  * Note that the I/O may actually be done immediately.
229  *
230  * Example:
231  * static struct io_plan *read_from_conn(struct io_conn *conn, char *buf)
232  * {
233  *      // Read message, then close.
234  *      return io_read(conn, buf, 12, io_close_cb, NULL);
235  * }
236  */
237 #define io_read(conn, data, len, next, arg)                             \
238         io_read_((conn), (data), (len),                                 \
239                  typesafe_cb_preargs(struct io_plan *, void *,          \
240                                      (next), (arg), struct io_conn *),  \
241                  (arg))
242 struct io_plan *io_read_(struct io_conn *conn,
243                          void *data, size_t len,
244                          struct io_plan *(*next)(struct io_conn *, void *),
245                          void *arg);
246
247
248 /**
249  * io_read_partial - input plan to read some data.
250  * @conn: the connection that plan is for.
251  * @data: the data buffer.
252  * @maxlen: the maximum length to read
253  * @lenp: set to the length actually read.
254  * @next: function to call once input is done.
255  * @arg: @next argument
256  *
257  * This creates a plan to read data into a buffer.  Once any data is
258  * read, @len is updated and the @next function will be called: on an
259  * error, the finish function is called instead.
260  *
261  * Note that the I/O may actually be done immediately.
262  *
263  * Example:
264  * struct buf {
265  *      size_t len;
266  *      char buf[12];
267  * };
268  *
269  * static struct io_plan *dump(struct io_conn *conn, struct buf *b)
270  * {
271  *      printf("Partial read: '%*s'\n", (int)b->len, b->buf);
272  *      free(b);
273  *      return io_close(conn);
274  * }
275  *
276  * static struct io_plan *read_part(struct io_conn *conn, struct buf *b)
277  * {
278  *      // Read message, then dump and close.
279  *      return io_read_partial(conn, b->buf, sizeof(b->buf), &b->len, dump, b);
280  * }
281  */
282 #define io_read_partial(conn, data, maxlen, lenp, next, arg)            \
283         io_read_partial_((conn), (data), (maxlen), (lenp),              \
284                          typesafe_cb_preargs(struct io_plan *, void *,  \
285                                              (next), (arg),             \
286                                              struct io_conn *),         \
287                          (arg))
288 struct io_plan *io_read_partial_(struct io_conn *conn,
289                                  void *data, size_t maxlen, size_t *lenp,
290                                  struct io_plan *(*next)(struct io_conn *,
291                                                          void *),
292                                  void *arg);
293
294 /**
295  * io_write_partial - output plan to write some data.
296  * @conn: the connection that plan is for.
297  * @data: the data buffer.
298  * @maxlen: the maximum length to write
299  * @lenp: set to the length actually written.
300  * @next: function to call once output is done.
301  * @arg: @next argument
302  *
303  * This creates a plan to write data from a buffer.   Once any data is
304  * written, @len is updated and the @next function will be called: on an
305  * error, the finish function is called instead.
306  *
307  * Note that the I/O may actually be done immediately.
308  *
309  * Example:
310  * struct buf {
311  *      size_t len;
312  *      char buf[12];
313  * };
314  *
315  * static struct io_plan *show_partial(struct io_conn *conn, struct buf *b)
316  * {
317  *      printf("Only wrote: '%*s'\n", (int)b->len, b->buf);
318  *      free(b);
319  *      return io_close(conn);
320  * }
321  *
322  * static struct io_plan *write_part(struct io_conn *conn, struct buf *b)
323  * {
324  *      // Write message, then dump and close.
325  *      strcpy(b->buf, "Hello world");
326  *      return io_write_partial(conn, b->buf, strlen(b->buf),
327  *                              &b->len, show_partial, b);
328  * }
329  */
330 #define io_write_partial(conn, data, maxlen, lenp, next, arg)           \
331         io_write_partial_((conn), (data), (maxlen), (lenp),             \
332                           typesafe_cb_preargs(struct io_plan *, void *, \
333                                               (next), (arg),            \
334                                               struct io_conn *),        \
335                           (arg))
336 struct io_plan *io_write_partial_(struct io_conn *conn,
337                                   const void *data, size_t maxlen, size_t *lenp,
338                                   struct io_plan *(*next)(struct io_conn *,
339                                                           void*),
340                                   void *arg);
341
342 /**
343  * io_always - plan to immediately call next callback
344  * @conn: the connection that plan is for.
345  * @next: function to call.
346  * @arg: @next argument
347  *
348  * Sometimes it's neater to plan a callback rather than call it directly;
349  * for example, if you only need to read data for one path and not another.
350  *
351  * Example:
352  * static struct io_plan *init_conn_with_nothing(struct io_conn *conn,
353  *                                               void *unused)
354  * {
355  *      // Silly example: close on next time around loop.
356  *      return io_always(conn, io_close_cb, NULL);
357  * }
358  */
359 #define io_always(conn, next, arg)                                      \
360         io_always_((conn), typesafe_cb_preargs(struct io_plan *, void *, \
361                                                (next), (arg),           \
362                                                struct io_conn *),       \
363                    (arg))
364
365 struct io_plan *io_always_(struct io_conn *conn,
366                            struct io_plan *(*next)(struct io_conn *, void *),
367                            void *arg);
368
369 /**
370  * io_out_always - output plan to immediately call next callback
371  * @conn: the connection that plan is for.
372  * @next: function to call.
373  * @arg: @next argument
374  *
375  * This is a variant of io_always() which uses the output plan; it only
376  * matters if you are using io_duplex, and thus have two plans running at
377  * once.
378  */
379 #define io_out_always(conn, next, arg)                                  \
380         io_out_always_((conn), typesafe_cb_preargs(struct io_plan *, void *, \
381                                                    (next), (arg),       \
382                                                    struct io_conn *),   \
383                        (arg))
384
385 struct io_plan *io_out_always_(struct io_conn *conn,
386                                struct io_plan *(*next)(struct io_conn *,
387                                                        void *),
388                                void *arg);
389
390 /**
391  * io_connect - create an asynchronous connection to a listening socket.
392  * @conn: the connection that plan is for.
393  * @addr: where to connect.
394  * @init: function to call once it's connected
395  * @arg: @init argument
396  *
397  * This initiates a connection, and creates a plan for
398  * (asynchronously) completing it.  Once complete, the @init function
399  * will be called.
400  *
401  * Example:
402  * #include <sys/types.h>
403  * #include <sys/socket.h>
404  * #include <netdb.h>
405  *
406  * // Write, then close socket.
407  * static struct io_plan *init_connect(struct io_conn *conn,
408  *                                     struct addrinfo *addrinfo)
409  * {
410  *      return io_connect(conn, addrinfo, io_close_cb, NULL);
411  * }
412  *
413  * ...
414  *
415  *      int fd;
416  *      struct addrinfo *addrinfo;
417  *
418  *      fd = socket(AF_INET, SOCK_STREAM, 0);
419  *      getaddrinfo("localhost", "8111", NULL, &addrinfo);
420  *      io_new_conn(NULL, fd, init_connect, addrinfo);
421  */
422 struct addrinfo;
423 #define io_connect(conn, addr, next, arg)                               \
424         io_connect_((conn), (addr),                                     \
425                     typesafe_cb_preargs(struct io_plan *, void *,       \
426                                         (next), (arg),                  \
427                                         struct io_conn *),              \
428                     (arg))
429
430 struct io_plan *io_connect_(struct io_conn *conn, const struct addrinfo *addr,
431                             struct io_plan *(*next)(struct io_conn *, void *),
432                             void *arg);
433
434 /**
435  * io_duplex - set plans for both input and output.
436  * @conn: the connection that plan is for.
437  * @in: the input plan
438  * @out: the output plan
439  *
440  * Most plans are either for input or output; io_duplex creates a plan
441  * which does both.  This is often used in the init function to create
442  * two independent streams, though it can be used once on any connection.
443  *
444  * Note that if either plan closes the connection, it will be closed.
445  *
446  * Example:
447  * struct buf {
448  *      char in[100];
449  *      char out[100];
450  * };
451  *
452  * static struct io_plan *read_and_write(struct io_conn *conn, struct buf *b)
453  * {
454  *      return io_duplex(conn,
455  *                       io_read(conn, b->in, sizeof(b->in), io_close_cb, b),
456  *                       io_write(conn, b->out, sizeof(b->out), io_close_cb,b));
457  * }
458  */
459 struct io_plan *io_duplex(struct io_conn *conn,
460                           struct io_plan *in_plan, struct io_plan *out_plan);
461
462 /**
463  * io_halfclose - close half of an io_duplex connection.
464  * @conn: the connection that plan is for.
465  *
466  * It's common to want to close a duplex connection after both input and
467  * output plans have completed.  If either calls io_close() the connection
468  * closes immediately.  Instead, io_halfclose() needs to be called twice.
469  *
470  * Example:
471  * struct buf {
472  *      char in[100];
473  *      char out[100];
474  * };
475  *
476  * static struct io_plan *finish(struct io_conn *conn, struct buf *b)
477  * {
478  *      return io_halfclose(conn);
479  * }
480  *
481  * static struct io_plan *read_and_write(struct io_conn *conn, struct buf *b)
482  * {
483  *      return io_duplex(conn,
484  *                       io_read(conn, b->in, sizeof(b->in), finish, b),
485  *                       io_write(conn, b->out, sizeof(b->out), finish, b));
486  * }
487  */
488 struct io_plan *io_halfclose(struct io_conn *conn);
489
490 /**
491  * io_wait - leave a plan idle until something wakes us.
492  * @conn: the connection that plan is for.
493  * @waitaddr: the address to wait on.
494  * @next: function to call after waiting.
495  * @arg: @next argument
496  *
497  * This leaves the input or output idle: io_wake(@waitaddr) will be
498  * called later to restart the connection.
499  *
500  * Example:
501  * // Silly example to wait then close.
502  * static struct io_plan *wait(struct io_conn *conn, void *b)
503  * {
504  *      return io_wait(conn, b, io_close_cb, NULL);
505  * }
506  */
507 #define io_wait(conn, waitaddr, next, arg)                              \
508         io_wait_((conn), (waitaddr),                                    \
509                  typesafe_cb_preargs(struct io_plan *, void *,          \
510                                      (next), (arg),                     \
511                                      struct io_conn *),                 \
512                  (arg))
513
514 struct io_plan *io_wait_(struct io_conn *conn,
515                          const void *wait,
516                          struct io_plan *(*next)(struct io_conn *, void *),
517                          void *arg);
518
519
520 /**
521  * io_out_wait - leave the output plan idle until something wakes us.
522  * @conn: the connection that plan is for.
523  * @waitaddr: the address to wait on.
524  * @next: function to call after waiting.
525  * @arg: @next argument
526  *
527  * io_wait() makes the input plan idle: if you're not using io_duplex it
528  * doesn't matter which plan is waiting.  Otherwise, you may need to use
529  * io_out_wait() instead, to specify explicitly that the output plan is
530  * waiting.
531  */
532 #define io_out_wait(conn, waitaddr, next, arg)                          \
533         io_out_wait_((conn), (waitaddr),                                \
534                      typesafe_cb_preargs(struct io_plan *, void *,      \
535                                          (next), (arg),                 \
536                                          struct io_conn *),             \
537                      (arg))
538
539 struct io_plan *io_out_wait_(struct io_conn *conn,
540                              const void *wait,
541                              struct io_plan *(*next)(struct io_conn *, void *),
542                              void *arg);
543
544 /**
545  * io_wake - wake up any connections waiting on @wait
546  * @waitaddr: the address to trigger.
547  *
548  * All io_conns who have returned io_wait() on @waitaddr will move on
549  * to their next callback.
550  *
551  * Example:
552  * static struct io_plan *wake_it(struct io_conn *conn, void *b)
553  * {
554  *      io_wake(b);
555  *      return io_close(conn);
556  * }
557  */
558 void io_wake(const void *wait);
559
560 /**
561  * io_break - return from io_loop()
562  * @ret: non-NULL value to return from io_loop().
563  *
564  * This breaks out of the io_loop.  As soon as the current function
565  * returns, any io_close()'d connections will have their finish
566  * callbacks called, then io_loop() with return with @ret.
567  *
568  * If io_loop() is called again, then @plan will be carried out.
569  *
570  * Example:
571  *      static struct io_plan *fail_on_timeout(struct io_conn *conn, char *msg)
572  *      {
573  *              io_break(msg);
574  *              return io_close(conn);
575  *      }
576  */
577 void io_break(const void *ret);
578
579 /**
580  * io_never - assert if callback is called.
581  * @conn: the connection that plan is for.
582  * @unused: an unused parameter to make this suitable for use as a callback.
583  *
584  * Sometimes you want to make it clear that a callback should never happen
585  * (eg. for io_break).  This will assert() if called.
586  *
587  * Example:
588  * static struct io_plan *break_out(struct io_conn *conn, void *unused)
589  * {
590  *      io_break(conn);
591  *      // We won't ever return from io_break
592  *      return io_never(conn, NULL);
593  * }
594  */
595 struct io_plan *io_never(struct io_conn *conn, void *unused);
596
597 /* FIXME: io_recvfrom/io_sendto */
598
599 /**
600  * io_close - close a connection.
601  * @conn: the connection to close.
602  *
603  * The connection is immediately freed: it doesn't have to be the
604  * current connection and it doesn't need to be idle.  No more IO or
605  * callbacks will occur, but if a function was added by io_set_finish()
606  * it will be called with the current errno preserved.
607  *
608  * This is equivalent to tal_free(io_conn), except it returns an io_plan
609  * for use in an io callback.
610  *
611  * Example:
612  * static struct io_plan *close_on_timeout(struct io_conn *conn, const char *msg)
613  * {
614  *      printf("closing: %s\n", msg);
615  *      return io_close(conn);
616  * }
617  */
618 struct io_plan *io_close(struct io_conn *conn);
619
620 /**
621  * io_close_cb - helper callback to close a connection.
622  * @conn: the connection.
623  *
624  * This is closes a connection; designed to be used as a callback
625  * function.
626  *
627  * Example:
628  *      #define close_on_timeout io_close_cb
629  */
630 struct io_plan *io_close_cb(struct io_conn *, void *unused);
631
632 /**
633  * io_close_taken_fd - close a connection, but remove the filedescriptor first.
634  * @conn: the connection to take the file descriptor from and close.
635  *
636  * io_close closes the file descriptor underlying the io_conn; this version does
637  * not.  Presumably you have used io_conn_fd() on it beforehand and will take
638  * care of the fd yourself.
639  *
640  * Note that this also turns off O_NONBLOCK on the fd.
641  *
642  * Example:
643  * static struct io_plan *steal_fd(struct io_conn *conn, int *fd)
644  * {
645  *      *fd = io_conn_fd(conn);
646  *      printf("stealing fd %i and closing\n", *fd);
647  *      return io_close_taken_fd(conn);
648  * }
649  */
650 struct io_plan *io_close_taken_fd(struct io_conn *conn);
651
652 /**
653  * io_loop - process fds until all closed on io_break.
654  * @timers - timers which are waiting to go off (or NULL for none)
655  * @expired - an expired timer (can be NULL if @timers is)
656  *
657  * This is the core loop; it exits with the io_break() arg, or NULL if
658  * all connections and listeners are closed, or with @expired set to an
659  * expired timer (if @timers isn't NULL).
660  *
661  * Example:
662  *      io_loop(NULL, NULL);
663  */
664 void *io_loop(struct timers *timers, struct timer **expired);
665
666 /**
667  * io_conn_fd - get the fd from a connection.
668  * @conn: the connection.
669  *
670  * Sometimes useful, eg for getsockname().  Note that the fd is O_NONBLOCK.
671  *
672  * See Also:
673  *      io_close_taken_fd
674  */
675 int io_conn_fd(const struct io_conn *conn);
676
677 /**
678  * io_flush_sync - (synchronously) complete any outstanding output.
679  * @conn: the connection.
680  *
681  * This is generally used as an emergency escape, for example when we
682  * want to write an error message on a socket before terminating, but it may
683  * be in the middle of existing I/O.  We don't want to service any other
684  * IO, either.
685  *
686  * This returns true if all pending output is complete, false on error.
687  * The next callback is not called on the conn, but will be as soon as
688  * io_loop() is called.
689  *
690  * See Also:
691  *      io_close_taken_fd
692  */
693 bool io_flush_sync(struct io_conn *conn);
694
695 /**
696  * io_fd_block - helper to set an fd blocking/nonblocking.
697  * @fd: the file descriptor
698  * @block: true to set blocking, false to set non-blocking.
699  *
700  * Generally only fails is @fd isn't a valid file descriptor, otherwise
701  * returns true.
702  */
703 bool io_fd_block(int fd, bool block);
704
705 /**
706  * io_time_override - override the normal call for time.
707  * @nowfn: the function to call.
708  *
709  * io usually uses time_mono() internally, but this forces it
710  * to use your function (eg. for debugging).  Returns the old
711  * one.
712  */
713 struct timemono (*io_time_override(struct timemono (*now)(void)))(void);
714
715 /**
716  * io_poll_override - override the normal call for poll.
717  * @pollfn: the function to call.
718  *
719  * io usually uses poll() internally, but this forces it to use your
720  * function (eg. for debugging, suppressing fds, or polling on others unknown
721  * to ccan/io).  Returns the old one.
722  */
723 int (*io_poll_override(int (*poll)(struct pollfd *fds, nfds_t nfds, int timeout)))(struct pollfd *, nfds_t, int);
724
725 #endif /* CCAN_IO_H */