blob: e8317b624f6fb4352a1352d928c4bbd3aacf11f0 [file] [log] [blame]
James E. King, III49f4dc02015-10-29 15:52:23 -04001#
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
20require 5.6.0;
21use strict;
22use warnings;
23
24use Thrift;
25use Thrift::Transport;
26
27use IO::Socket::UNIX;
28use IO::Select;
29
30package Thrift::UnixSocket;
31
32use 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#
41sub new
42{
43 my $classname = shift;
44 my $self = $classname->SUPER::new();
45 $self->{path} = shift;
46 return bless($self, $classname);
47}
48
49sub __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
681;