---
generator/generator | 37 ++++++++++++++++++++++++++++---------
lib/aio.c | 26 ++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 9 deletions(-)
diff --git a/generator/generator b/generator/generator
index f665475..d31f060 100755
--- a/generator/generator
+++ b/generator/generator
@@ -1344,9 +1344,12 @@ let connection_calls = [
args = [ SockAddrAndLen ("addr", "addrlen") ]; ret = RErr;
shortdesc = "connect to the NBD server";
longdesc = "\
-Begin connecting to the NBD server. You can check if the
-connection has connected to the server and completed the NBD
-handshake by calling C<nbd_aio_is_ready> on the connection.";
+Begin connecting to the NBD server.
+
+You can check if the connection is still connecting by calling
+C<nbd_aio_is_connecting>, or if it has connected to the server
+and completed the NBD handshake by calling C<nbd_aio_is_ready>,
+on the connection.";
};
"aio_connect_tcp", {
@@ -1355,9 +1358,11 @@ handshake by calling C<nbd_aio_is_ready> on the
connection.";
shortdesc = "connect to the NBD server over a TCP port";
longdesc = "\
Begin connecting to the NBD server listening on C<hostname:port>.
-You can check if the connection has connected to the server and
-completed the NBD handshake by calling C<nbd_aio_is_ready> on
-the connection.";
+
+You can check if the connection is still connecting by calling
+C<nbd_aio_is_connecting>, or if it has connected to the server
+and completed the NBD handshake by calling C<nbd_aio_is_ready>,
+on the connection.";
};
"aio_connect_command", {
@@ -1366,9 +1371,12 @@ the connection.";
shortdesc = "connect to the NBD server";
longdesc = "\
Run the command as a subprocess and begin connecting to it over
-stdin/stdout. You can check if the connection has connected to
-the server and completed the NBD handshake by calling
-C<nbd_aio_is_ready> on the connection.";
+stdin/stdout.
+
+You can check if the connection is still connecting by calling
+C<nbd_aio_is_connecting>, or if it has connected to the server
+and completed the NBD handshake by calling C<nbd_aio_is_ready>,
+on the connection.";
};
"aio_pread", {
@@ -1548,6 +1556,17 @@ connecting to a server. In this state the handle can start
to be connected by calling functions such as C<nbd_aio_connect>.";
};
+ "aio_is_connecting", {
+ default_call with
+ args = []; ret = RBool;
+ shortdesc = "check if the connection is connecting or handshaking";
+ longdesc = "\
+Return true if this connection is connecting to the server
+or in the process of handshaking and negotiating options
+which happens before the connection object becomes ready to
+issue commands (see C<nbd_aio_is_ready>).";
+ };
+
"aio_is_ready", {
default_call with
args = []; ret = RBool;
diff --git a/lib/aio.c b/lib/aio.c
index 79c89d5..1152c9e 100644
--- a/lib/aio.c
+++ b/lib/aio.c
@@ -53,6 +53,32 @@ nbd_unlocked_aio_is_created (struct nbd_connection *conn)
return conn->state == STATE_START;
}
+static int
+is_connecting_group (enum state_group group)
+{
+ switch (group) {
+ case GROUP_TOP:
+ return 0;
+ case GROUP_CONNECT:
+ case GROUP_CONNECT_TCP:
+ case GROUP_CONNECT_COMMAND:
+ case GROUP_MAGIC:
+ case GROUP_OLDSTYLE:
+ case GROUP_NEWSTYLE:
+ return 1;
+ default:
+ return is_connecting_group (nbd_internal_state_group_parent (group));
+ }
+}
+
+int
+nbd_unlocked_aio_is_connecting (struct nbd_connection *conn)
+{
+ enum state_group group = nbd_internal_state_group (conn->state);
+
+ return is_connecting_group (group);
+}
+
int
nbd_unlocked_aio_is_ready (struct nbd_connection *conn)
{
--
2.21.0