From: Ben Pfaff <blp@nicira.com>
Date: Thu, 12 Nov 2009 20:53:05 +0000 (-0800)
Subject: ovsdb-client: Support listening for incoming connections too.
X-Git-Tag: v1.0.0~259^2~505
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=1b0f0f17b3c0c6762d6289b1bf7e0e65292f6348;p=sliver-openvswitch.git

ovsdb-client: Support listening for incoming connections too.

This makes it easier to test ovsdb-server's support for active connections.
It might also be useful occasionally, too.
---

diff --git a/ovsdb/ovsdb-client.1.in b/ovsdb/ovsdb-client.1.in
index 8bdaae81f..c07a88c13 100644
--- a/ovsdb/ovsdb-client.1.in
+++ b/ovsdb/ovsdb-client.1.in
@@ -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:
diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c
index 10b27ce65..93a91e7c0 100644
--- a/ovsdb/ovsdb-client.c
+++ b/ovsdb/ovsdb-client.c
@@ -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);
     }