From 1b0f0f17b3c0c6762d6289b1bf7e0e65292f6348 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 12 Nov 2009 12:53:05 -0800 Subject: [PATCH] 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. --- ovsdb/ovsdb-client.1.in | 8 ++++++++ ovsdb/ovsdb-client.c | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ovsdb/ovsdb-client.1.in b/ovsdb/ovsdb-client.1.in index 8bdaae81..c07a88c1 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 10b27ce6..93a91e7c 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); } -- 2.30.2