]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/io.h
ccan/io: save errno on io_close, for finish functions.
[ccan] / ccan / io / io.h
index 5820f87750059ebf3fd9a1bfaaac14a0bbc51df8..6553e7ab29b93de5bc1bd5118f63745f81b5279b 100644 (file)
@@ -16,7 +16,7 @@ struct io_conn;
 struct io_plan {
        int pollflag;
        /* Only NULL if idle. */
-       bool (*io)(int fd, struct io_plan *plan);
+       int (*io)(int fd, struct io_plan *plan);
        /* Only NULL if closing. */
        struct io_plan (*next)(struct io_conn *, void *arg);
        void *next_arg;
@@ -38,6 +38,9 @@ struct io_plan {
                        const char *buf;
                        size_t *lenp;
                } writepart;
+               struct {
+                       int saved_errno;
+               } close;
                struct {
                        void *p;
                        size_t len;
@@ -84,7 +87,8 @@ struct io_conn *io_new_conn_(int fd, struct io_plan plan);
  * @arg: the argument to @finish.
  *
  * @finish will be called when an I/O operation fails, or you call
- * io_close() on the connection.
+ * io_close() on the connection.  errno will be set to the value
+ * after the failed I/O, or at the call to io_close().
  */
 #define io_set_finish(conn, finish, arg)                               \
        io_set_finish_((conn),                                          \
@@ -290,17 +294,20 @@ struct io_plan io_break_(void *ret, struct io_plan plan);
 /* FIXME: io_recvfrom/io_sendto */
 
 /**
- * io_close - terminate a connection.
- * @conn: any connection.
+ * io_close - plan to close a connection.
  *
- * The schedules a connection to be closed.  It can be done on any
- * connection, whether it has I/O queued or not (though that I/O may
- * be performed first).
+ * On return to io_loop, the connection will be closed.
+ */
+struct io_plan io_close(void);
+
+/**
+ * io_close_cb - helper callback to close a connection.
+ * @conn: the connection.
  *
- * It's common to 'return io_close(...)' from a @next function, but
- * io_close can also be used as an argument to io_next().
+ * This schedules a connection to be closed; designed to be used as
+ * a callback function.
  */
-struct io_plan io_close(struct io_conn *, void *unused);
+struct io_plan io_close_cb(struct io_conn *, void *unused);
 
 /**
  * io_loop - process fds until all closed on io_break.