File: | blib/lib/FUSE/Client.pm |
Coverage: | 26.7% |
line | stmt | bran | cond | sub | time | code |
---|---|---|---|---|---|---|
1 | package FUSE::Client; | |||||
2 | ||||||
3 | require 5; | |||||
4 | 1 1 1 | 8 3 9 | use strict; | |||
5 | ||||||
6 | 1 1 1 | 9 4 8 | use vars qw($VERSION @ISA @EXPORT); | |||
7 | ||||||
8 | 1 1 1 | 13 4 8 | use IO::Socket; | |||
9 | ||||||
10 | require Exporter; | |||||
11 | ||||||
12 | @ISA = qw(Exporter); | |||||
13 | @EXPORT = qw(); | |||||
14 | $VERSION = '1.08'; | |||||
15 | ||||||
16 | sub new { | |||||
17 | 0 | my ($class,$params) = @_; | ||||
18 | 0 | my $self = {}; | ||||
19 | 0 | bless $self,ref $class || $class; | ||||
20 | 0 0 | $self->{quiet} = ${$params}{Quiet}; | ||||
21 | 0 0 | $self->{port} = ${$params}{Port} || 1024; | ||||
22 | 0 | $self->{sock} = 0; | ||||
23 | 0 | return $self; | ||||
24 | } | |||||
25 | ||||||
26 | sub connect { | |||||
27 | 0 | my ($self,$host) = @_; | ||||
28 | 0 | $self->{sock} = new IO::Socket::INET ( PeerAddr => $host, PeerPort => $self->{port}, Proto => 'tcp' ); | ||||
29 | 0 | $self->{sock}->autoflush(1); | ||||
30 | 0 | die "Could not create socket: $!\n" unless $self->{sock}; | ||||
31 | } | |||||
32 | ||||||
33 | sub disconnect { | |||||
34 | 0 | my ($self) = @_; | ||||
35 | 0 | close($self->{sock}); | ||||
36 | } | |||||
37 | ||||||
38 | sub send { | |||||
39 | 0 | my ($self,$msg,$params) = @_; | ||||
40 | ||||||
41 | 0 | $msg = "$msg $params"; | ||||
42 | 0 | my $msg_frm = sprintf("%04d%s",length($msg),$msg); | ||||
43 | ||||||
44 | 0 | print "sending $msg_frm\n" unless $self->{Quiet}; | ||||
45 | ||||||
46 | 0 | syswrite($self->{sock}, $msg_frm, length($msg_frm)); | ||||
47 | } | |||||
48 | ||||||
49 | ||||||
50 | 1; |