]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/io.h
ccan/io: io_connect()
[ccan] / ccan / io / io.h
index c85a5b8c5abda95afae4463574f0c648a60a6b3d..772db9293ab068e7ed425ea282d6b7e0fc07b7ce 100644 (file)
@@ -160,6 +160,31 @@ struct io_plan io_write_partial_(const void *data, size_t *len,
                                 struct io_plan (*cb)(struct io_conn *, void*),
                                 void *arg);
 
                                 struct io_plan (*cb)(struct io_conn *, void*),
                                 void *arg);
 
+/**
+ * io_connect - plan to connect to a listening socket.
+ * @fd: file descriptor.
+ * @addr: where to connect.
+ * @cb: function to call once it's done.
+ * @arg: @cb argument
+ *
+ * This initiates a connection, and creates a plan for
+ * (asynchronously).  completing it.  Once complete, @len is updated
+ * and the @cb function will be called: on an error, the finish
+ * function is called instead.
+ *
+ * Note that the connect may actually be done immediately.
+ */
+struct addrinfo;
+#define io_connect(fd, addr, cb, arg)                                  \
+       io_debug(io_connect_((fd), (addr),                              \
+                            typesafe_cb_preargs(struct io_plan, void *, \
+                                                (cb), (arg),           \
+                                                struct io_conn *),     \
+                            (arg)))
+struct io_plan io_connect_(int fd, const struct addrinfo *addr,
+                          struct io_plan (*cb)(struct io_conn *, void*),
+                          void *arg);
+
 /**
  * io_idle - plan to do nothing.
  *
 /**
  * io_idle - plan to do nothing.
  *