ovsdb-client: Support listening for incoming connections too.
authorBen Pfaff <blp@nicira.com>
Thu, 12 Nov 2009 20:53:05 +0000 (12:53 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 12 Nov 2009 20:58:57 +0000 (12:58 -0800)
This makes it easier to test ovsdb-server's support for active connections.
It might also be useful occasionally, too.

ovsdb/ovsdb-client.1.in
ovsdb/ovsdb-client.c

index 8bdaae8..c07a88c 100644 (file)
@@ -35,6 +35,14 @@ the following forms:
 Connect to the given TCP \fIport\fR on \fIip\fR.
 .IP "\fBunix:\fIfile\fR"
 Connect to the Unix domain server socket named \fIfile\fR.
+.IP "\fBptcp:\fIport\fR[\fB:\fIip\fR]"
+Listen on the given TCP \fIport\fR for a connection.  By default,
+\fB\*(PN\fR listens for connections to any local IP address, but
+\fIip\fR may be specified to listen only for connections to the given
+\fIip\fR.
+.IP "\fBpunix:\fIfile\fR"
+Listen on the Unix domain server socket named \fIfile\fR for a
+connection.
 .
 .SS "Commands"
 The following commands are implemented:
index 10b27ce..93a91e7 100644 (file)
@@ -148,7 +148,7 @@ usage(void)
            "\n  list-columns SERVER [TABLE]\n"
            "    list columns in TABLE (or all tables) on SERVER\n",
            program_name, program_name);
-    stream_usage("SERVER", true, false);
+    stream_usage("SERVER", true, true);
     printf("\nOutput formatting options:\n"
            "  -f, --format=FORMAT         set output formatting to FORMAT\n"
            "                              (\"table\", \"html\", or \"csv\"\n"
@@ -168,7 +168,22 @@ open_jsonrpc(const char *server)
     int error;
 
     error = stream_open_block(server, &stream);
-    if (error) {
+    if (error == EAFNOSUPPORT) {
+        struct pstream *pstream;
+
+        error = pstream_open(server, &pstream);
+        if (error) {
+            ovs_fatal(error, "failed to connect or listen to \"%s\"", server);
+        }
+
+        VLOG_INFO("%s: waiting for connection...", server);
+        error = pstream_accept_block(pstream, &stream);
+        if (error) {
+            ovs_fatal(error, "failed to accept connection on \"%s\"", server);
+        }
+
+        pstream_close(pstream);
+    } else if (error) {
         ovs_fatal(error, "failed to connect to \"%s\"", server);
     }