You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2015/11/06 13:21:43 UTC

thrift git commit: THRIFT-3402: add unix socket support to perl Client: Perl Patch: James E. King, III

Repository: thrift
Updated Branches:
  refs/heads/master 7f4be5f18 -> 49f4dc0cd


THRIFT-3402: add unix socket support to perl
Client: Perl
Patch: James E. King, III

This closes #670


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/49f4dc0c
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/49f4dc0c
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/49f4dc0c

Branch: refs/heads/master
Commit: 49f4dc0cd8c87213a0f80ae1daba2d094a358ea7
Parents: 7f4be5f
Author: James E. King, III <ji...@simplivity.com>
Authored: Thu Oct 29 15:52:23 2015 -0400
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Fri Nov 6 21:21:01 2015 +0900

----------------------------------------------------------------------
 build/travis/installDependencies.sh     |  3 -
 lib/perl/lib/Thrift/ServerSocket.pm     |  3 -
 lib/perl/lib/Thrift/UnixServerSocket.pm | 84 ++++++++++++++++++++++++++++
 lib/perl/lib/Thrift/UnixSocket.pm       | 68 ++++++++++++++++++++++
 test/perl/TestClient.pl                 |  7 ++-
 test/perl/TestServer.pl                 | 14 ++++-
 test/tests.json                         | 13 +++--
 7 files changed, 177 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/49f4dc0c/build/travis/installDependencies.sh
----------------------------------------------------------------------
diff --git a/build/travis/installDependencies.sh b/build/travis/installDependencies.sh
index eb2f7de..453494c 100755
--- a/build/travis/installDependencies.sh
+++ b/build/travis/installDependencies.sh
@@ -22,9 +22,6 @@ SCRIPTPATH=$( cd $(dirname $0) ; pwd -P )
 # Mainly aiming Travis CI's Ubuntu machines for now
 # see what we need: http://thrift.apache.org/docs/install/ubuntu
 
-# General dependencies
-sh ${SCRIPTPATH}/installCXXDependencies.sh
-
 # Java dependencies
 sudo apt-get install -qq ant openjdk-7-jdk
 sudo update-java-alternatives -s java-1.7.0-openjdk-amd64

http://git-wip-us.apache.org/repos/asf/thrift/blob/49f4dc0c/lib/perl/lib/Thrift/ServerSocket.pm
----------------------------------------------------------------------
diff --git a/lib/perl/lib/Thrift/ServerSocket.pm b/lib/perl/lib/Thrift/ServerSocket.pm
index a41b319..89664f6 100644
--- a/lib/perl/lib/Thrift/ServerSocket.pm
+++ b/lib/perl/lib/Thrift/ServerSocket.pm
@@ -52,9 +52,6 @@ sub new
         $self = { port => $args };
     }
 
-    if (not defined $self->{port}) {
-        die("port number not specified");
-    }
     if (not defined $self->{queue}) {
         $self->{queue} = 128;
     }

http://git-wip-us.apache.org/repos/asf/thrift/blob/49f4dc0c/lib/perl/lib/Thrift/UnixServerSocket.pm
----------------------------------------------------------------------
diff --git a/lib/perl/lib/Thrift/UnixServerSocket.pm b/lib/perl/lib/Thrift/UnixServerSocket.pm
new file mode 100644
index 0000000..3251a00
--- /dev/null
+++ b/lib/perl/lib/Thrift/UnixServerSocket.pm
@@ -0,0 +1,84 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+require 5.6.0;
+use strict;
+use warnings;
+
+use Thrift;
+use Thrift::UnixSocket;
+
+use IO::Socket::UNIX;
+use IO::Select;
+
+package Thrift::UnixServerSocket;
+
+use base qw( Thrift::ServerSocket );
+
+#
+# Constructor.
+# If a single argument is given that is not a hash, that is the unix domain socket path.
+# If a single argument is given that is a hash:
+# @param[in]  path   unix domain socket file name
+# @param[in]  queue  the listen queue size (default is not specified is supplied by ServerSocket)
+# @example    my $serversock = new Thrift::UnixServerSocket($path);
+# @example    my $serversock = new Thrift::UnixServerSocket(path => "somepath", queue => 64);
+#
+sub new
+{
+    my $classname = shift;
+    my $args      = shift;
+    my $self;
+
+    if (ref($args) eq 'HASH') {
+        $self = $classname->SUPER::new($args);
+    } else {
+        $self = $classname->SUPER::new();
+        $self->{path} = $args;
+    }
+
+    return bless($self, $classname);
+}
+
+sub __client
+{
+	return new Thrift::UnixSocket();
+}
+
+sub __listen
+{
+    my $self = shift;
+
+    my $sock = IO::Socket::UNIX->new(
+        Type      => IO::Socket::SOCK_STREAM,
+        Local     => $self->{path},
+        Listen    => $self->{queue})
+    || do {
+        my $error = 'UnixServerSocket: Could not bind to ' .
+                    $self->{path} . ' (' . $! . ')';
+        if ($self->{debug}) {
+            $self->{debugHandler}->($error);
+        }
+        die new Thrift::TException($error);
+    };
+
+    return $sock;
+}
+
+1;

http://git-wip-us.apache.org/repos/asf/thrift/blob/49f4dc0c/lib/perl/lib/Thrift/UnixSocket.pm
----------------------------------------------------------------------
diff --git a/lib/perl/lib/Thrift/UnixSocket.pm b/lib/perl/lib/Thrift/UnixSocket.pm
new file mode 100644
index 0000000..e8317b6
--- /dev/null
+++ b/lib/perl/lib/Thrift/UnixSocket.pm
@@ -0,0 +1,68 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+require 5.6.0;
+use strict;
+use warnings;
+
+use Thrift;
+use Thrift::Transport;
+
+use IO::Socket::UNIX;
+use IO::Select;
+
+package Thrift::UnixSocket;
+
+use base qw( Thrift::Socket );
+
+#
+# Constructor.
+# Takes a unix domain socket filename.
+# See Thirft::Socket for base class parameters.
+# @param[in]  path   path to unix socket file
+# @example    my $sock = new Thrift::UnixSocket($path);
+#
+sub new
+{
+    my $classname = shift;
+    my $self      = $classname->SUPER::new();
+    $self->{path} = shift;     
+    return bless($self, $classname);
+}
+
+sub __open
+{
+    my $self = shift;
+
+    my $sock = IO::Socket::UNIX->new(
+        Type      => IO::Socket::SOCK_STREAM,
+        Peer      => $self->{path})
+    || do {
+        my $error = 'UnixSocket: Could not connect to ' .
+            $self->{path} . ' (' . $! . ')';
+        if ($self->{debug}) {
+            $self->{debugHandler}->($error);
+        }
+        die new Thrift::TException($error);
+    };
+
+    return $sock;
+}
+
+1;

http://git-wip-us.apache.org/repos/asf/thrift/blob/49f4dc0c/test/perl/TestClient.pl
----------------------------------------------------------------------
diff --git a/test/perl/TestClient.pl b/test/perl/TestClient.pl
index 9d4aab2..7ec32bf 100755
--- a/test/perl/TestClient.pl
+++ b/test/perl/TestClient.pl
@@ -35,6 +35,7 @@ use Thrift::BufferedTransport;
 use Thrift::FramedTransport;
 use Thrift::SSLSocket;
 use Thrift::Socket;
+use Thrift::UnixSocket;
 
 use ThriftTest::ThriftTest;
 use ThriftTest::Types;
@@ -48,6 +49,7 @@ Usage: $0 [OPTIONS]
 Options:                          (default)
   --cert                                       Certificate to use.
                                                Required if using --ssl.
+  --domain-socket <file>                       Use a unix domain socket.
   --help                                       Show usage.
   --port <portnum>                9090         Port to use.
   --protocol {binary}             binary       Protocol to use.
@@ -65,6 +67,7 @@ my %opts = (
 
 GetOptions(\%opts, qw (
     cert=s
+    domain-socket=s
     help
     host=s
     port=i
@@ -84,7 +87,9 @@ if ($opts{ssl} and not defined $opts{cert}) {
 }
 
 my $socket = undef;
-if ($opts{ssl}) {
+if ($opts{"domain-socket"}) {
+    $socket = new Thrift::UnixSocket($opts{"domain-socket"});
+} elsif ($opts{ssl}) {
 	$socket = new Thrift::SSLSocket($opts{host}, $opts{port});
 } else {
 	$socket = new Thrift::Socket($opts{host}, $opts{port});

http://git-wip-us.apache.org/repos/asf/thrift/blob/49f4dc0c/test/perl/TestServer.pl
----------------------------------------------------------------------
diff --git a/test/perl/TestServer.pl b/test/perl/TestServer.pl
index 5bfa640..4e0cc79 100644
--- a/test/perl/TestServer.pl
+++ b/test/perl/TestServer.pl
@@ -36,6 +36,7 @@ use Thrift::FramedTransport;
 use Thrift::SSLServerSocket;
 use Thrift::ServerSocket;
 use Thrift::Server;
+use Thrift::UnixServerSocket;
 
 use ThriftTest::ThriftTest;
 use ThriftTest::Types;
@@ -50,6 +51,7 @@ Options:                          (default)
   --ca                                         Certificate authority file (optional).
   --cert                                       Certificate file.
                                                Required if using --ssl.                                               
+  --domain-socket <file>                       Use a unix domain socket.
   --help                                       Show usage.
   --key                                        Private key file for certificate.
                                                Required if using --ssl and private key is
@@ -71,6 +73,7 @@ my %opts = (
 GetOptions(\%opts, qw (
     ca=s
     cert=s
+    domain-socket=s
     help
     host=s
     key=s
@@ -93,7 +96,10 @@ if ($opts{ssl} and not defined $opts{cert}) {
 my $handler = new ThriftTestHandler();
 my $processor = new ThriftTest::ThriftTestProcessor($handler);
 my $serversocket;
-if ($opts{ssl}) {
+if ($opts{"domain-socket"}) {
+    unlink($opts{"domain-socket"});
+    $serversocket = new Thrift::UnixServerSocket($opts{"domain-socket"});
+} elsif ($opts{ssl}) {
     $serversocket = new Thrift::SSLServerSocket(\%opts);
 } else {
     $serversocket = new Thrift::ServerSocket(\%opts);
@@ -119,8 +125,12 @@ my $ssltag = '';
 if ($opts{ssl}) {
     $ssltag = "(SSL)";
 }
+my $listening_on = "$opts{port} $ssltag";
+if ($opts{"domain-socket"}) {
+    $listening_on = $opts{"domain-socket"};
+}
 my $server = new Thrift::SimpleServer($processor, $serversocket, $transport, $protocol);
-print "Starting \"simple\" server ($opts{transport}/$opts{protocol}) listen on: $opts{port} $ssltag\n";
+print "Starting \"simple\" server ($opts{transport}/$opts{protocol}) listen on: $listening_on\n";
 $server->serve();
 
 ###    

http://git-wip-us.apache.org/repos/asf/thrift/blob/49f4dc0c/test/tests.json
----------------------------------------------------------------------
diff --git a/test/tests.json b/test/tests.json
index aeff933..0c35df2 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -126,8 +126,8 @@
       "framed"
     ],
     "sockets": [
-      "ip-ssl",
-      "ip"
+      "ip",
+      "ip-ssl"
     ],
     "protocols": [
       "compact",
@@ -190,8 +190,8 @@
       "framed"
     ],
     "sockets": [
-      "ip-ssl",
-      "ip"
+      "ip",
+      "ip-ssl"
     ],
     "protocols": [
       "compact",
@@ -221,8 +221,8 @@
       "framed"
     ],
     "sockets": [
-      "ip-ssl",
       "ip",
+      "ip-ssl",
       "domain"
     ],
     "protocols": [
@@ -307,7 +307,8 @@
     ],
     "sockets": [
       "ip",
-      "ip-ssl"
+      "ip-ssl",
+      "domain"
     ],
     "protocols": [
       "binary"