aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@83718e91-0e4f-0410-abf4-91180603181f>2006-06-15 13:39:16 +0000
committertradke <tradke@83718e91-0e4f-0410-abf4-91180603181f>2006-06-15 13:39:16 +0000
commit53d1f98dd14016d8363550b536321bbab51749c1 (patch)
tree0c8b1ebe222dd4fff5966aa12d819285d75c1779
parent9ad0d8657a8038306889f47d9b743f9565abf9b8 (diff)
Make Formaline::rdf_hostname and Formaline::rdf_port array parameters so that
more than one RDF server can be specified. git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@86 83718e91-0e4f-0410-abf4-91180603181f
-rw-r--r--param.ccl6
-rw-r--r--src/rdf.cc60
2 files changed, 52 insertions, 14 deletions
diff --git a/param.ccl b/param.ccl
index e77fa35..3193ddd 100644
--- a/param.ccl
+++ b/param.ccl
@@ -53,12 +53,12 @@ BOOLEAN send_as_rdf "Send meta as RDF to a server" STEERABLE=always
{
} no
-STRING rdf_hostname "RDF server host name" STEERABLE=always
+STRING rdf_hostname[5] "RDF server host name" STEERABLE=always
{
"" :: ""
-} "rdf.cct.lsu.edu"
+} ""
-INT rdf_port "RDF server port" STEERABLE=always
+INT rdf_port[5] "RDF server port" STEERABLE=always
{
1:65535 :: ""
} 9296
diff --git a/src/rdf.cc b/src/rdf.cc
index af7fccd..cffa6de 100644
--- a/src/rdf.cc
+++ b/src/rdf.cc
@@ -119,21 +119,59 @@ namespace Formaline
<< "use Socket;" << endl
<< endl
<< "my $input = '" << datafilename << "';" << endl
-<< "my $host = '" << rdf_hostname << "';" << endl
-<< "my $port = '" << rdf_port << "';" << endl
+<< "my @hostlist = (";
+
+ // NUM_RDF_ENTRIES must match the size of the
+ // Formaline::rdf_hostname and Formaline::rdf_port parameter arrays
+#define NUM_RDF_ENTRIES 5
+
+ // add all array parameters which have been set
+ for (int i = 0; i < NUM_RDF_ENTRIES; i++) {
+ if (*rdf_hostname[i]) {
+ if (i) scriptbuf << "," << endl << " ";
+ scriptbuf << "'" << rdf_hostname[i] << ":" << rdf_port[i] << "'";
+ }
+ }
+ scriptbuf
+<< ");" << endl
<< endl
-<< "open (my $FH, '<' . $input);" << endl
+<< "foreach my $entry (@hostlist) {" << endl
+<< " next if ($entry !~ /^(.+):(\\d+)$/);" << endl
<< endl
-<< "socket (my $SH, PF_INET, SOCK_STREAM, getprotobyname ('tcp'));" << endl
-<< "my $sin = sockaddr_in ($port, inet_aton ($host));" << endl
-<< "connect ($SH, $sin) || exit -1;" << endl
+<< " my $host = $1;" << endl
+<< " my $port = $2;" << endl
<< endl
-<< "while (my $line = <$FH>)" << endl
-<< "{" << endl
-<< " print $SH $line;" << endl
-<< "}" << endl
+<< " my $SH;" << endl
+<< endl
+<< " # try to use IO::Socket::INET if the module exists;" << endl
+<< " # it accepts a timeout for its internal connect call" << endl
+<< " eval 'use IO::Socket::INET;" << endl
<< endl
-<< "close $SH;" << endl;
+<< " $SH = IO::Socket::INET->new (PeerAddr => $host," << endl
+<< " PeerPort => $port," << endl
+<< " Proto => \\'tcp\\'," << endl
+<< " Type => SOCK_STREAM," << endl
+<< " Timeout => 0.2);';" << endl
+<< " # if that failed, fall back to making the standard socket/connect calls" << endl
+<< " # (with their built-in fixed timeout)" << endl
+<< " if ($@) {" << endl
+<< " my $iaddr = inet_aton ($host);" << endl
+<< " next if (not $iaddr);" << endl
+<< "" << endl
+<< " socket ($SH, PF_INET, SOCK_STREAM, getprotobyname ('tcp'));" << endl
+<< " my $sin = sockaddr_in ($port, $iaddr);" << endl
+<< " connect ($SH, $sin) || next;" << endl
+<< " }" << endl
+<< endl
+<< " # send off the data" << endl
+<< " if (defined $SH) {" << endl
+<< " open (my $FH, '<' . $input);" << endl
+<< " print $SH $_ while (<$FH>);" << endl
+<< " close $FH;" << endl
+<< " close $SH;" << endl
+<< " }" << endl
+<< "}" << endl
+<< endl;
string const scriptstr = scriptbuf.str();
ostringstream scriptfilenamebuf;