James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 1 | # |
| 2 | # Licensed to the Apache Software Foundation (ASF) under one |
| 3 | # or more contributor license agreements. See the NOTICE file |
| 4 | # distributed with this work for additional information |
| 5 | # regarding copyright ownership. The ASF licenses this file |
| 6 | # to you under the Apache License, Version 2.0 (the |
| 7 | # "License"); you may not use this file except in compliance |
| 8 | # with the License. You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, |
| 13 | # software distributed under the License is distributed on an |
| 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | # KIND, either express or implied. See the License for the |
| 16 | # specific language governing permissions and limitations |
| 17 | # under the License. |
| 18 | # |
| 19 | |
| 20 | require 5.6.0; |
| 21 | use strict; |
| 22 | use warnings; |
| 23 | |
| 24 | use Thrift; |
| 25 | use Thrift::Transport; |
| 26 | |
| 27 | use IO::Socket::UNIX; |
| 28 | use IO::Select; |
| 29 | |
| 30 | package Thrift::UnixSocket; |
| 31 | |
| 32 | use base qw( Thrift::Socket ); |
| 33 | |
| 34 | # |
| 35 | # Constructor. |
| 36 | # Takes a unix domain socket filename. |
| 37 | # See Thirft::Socket for base class parameters. |
| 38 | # @param[in] path path to unix socket file |
| 39 | # @example my $sock = new Thrift::UnixSocket($path); |
| 40 | # |
| 41 | sub new |
| 42 | { |
| 43 | my $classname = shift; |
| 44 | my $self = $classname->SUPER::new(); |
| 45 | $self->{path} = shift; |
| 46 | return bless($self, $classname); |
| 47 | } |
| 48 | |
| 49 | sub __open |
| 50 | { |
| 51 | my $self = shift; |
| 52 | |
| 53 | my $sock = IO::Socket::UNIX->new( |
| 54 | Type => IO::Socket::SOCK_STREAM, |
| 55 | Peer => $self->{path}) |
| 56 | || do { |
| 57 | my $error = 'UnixSocket: Could not connect to ' . |
| 58 | $self->{path} . ' (' . $! . ')'; |
| 59 | if ($self->{debug}) { |
| 60 | $self->{debugHandler}->($error); |
| 61 | } |
| 62 | die new Thrift::TException($error); |
| 63 | }; |
| 64 | |
| 65 | return $sock; |
| 66 | } |
| 67 | |
| 68 | 1; |