… | |
… | |
61 | |
61 | |
62 | use common::sense; |
62 | use common::sense; |
63 | |
63 | |
64 | use Carp; |
64 | use Carp; |
65 | |
65 | |
66 | our $VERSION = '0.3'; |
66 | our $VERSION = 0.4; |
67 | |
67 | |
68 | use Scalar::Util (); |
68 | use Scalar::Util (); |
69 | |
69 | |
70 | use AnyEvent; |
70 | use AnyEvent; |
71 | use AnyEvent::Handle; |
71 | use AnyEvent::Handle; |
… | |
… | |
105 | |
105 | |
106 | my $self = bless { |
106 | my $self = bless { |
107 | host => $ENV{FREDHOST} || "127.0.0.1", |
107 | host => $ENV{FREDHOST} || "127.0.0.1", |
108 | port => $ENV{FREDPORT} || 9481, |
108 | port => $ENV{FREDPORT} || 9481, |
109 | timeout => 3600 * 2, |
109 | timeout => 3600 * 2, |
|
|
110 | keepalive => 9 * 60, |
110 | name => time.rand.rand.rand, # lame |
111 | name => time.rand.rand.rand, # lame |
111 | @_, |
112 | @_, |
112 | queue => [], |
113 | queue => [], |
113 | req => {}, |
114 | req => {}, |
114 | prefix => "..:aefcpid:$rand:", |
115 | prefix => "..:aefcpid:$rand:", |
115 | idseq => "a0", |
116 | idseq => "a0", |
116 | }, $class; |
117 | }, $class; |
117 | |
118 | |
118 | { |
119 | { |
119 | Scalar::Util::weaken (my $self = $self); |
120 | Scalar::Util::weaken (my $self = $self); |
|
|
121 | |
|
|
122 | $self->{kw} = AE::timer $self->{keepalive}, $self->{keepalive}, sub { |
|
|
123 | $self->{hdl}->push_write ("\n"); |
|
|
124 | }; |
120 | |
125 | |
121 | our $ENDMESSAGE = qr<\012(EndMessage|Data)\012>; |
126 | our $ENDMESSAGE = qr<\012(EndMessage|Data)\012>; |
122 | |
127 | |
123 | # these are declared here for performance reasons |
128 | # these are declared here for performance reasons |
124 | my ($k, $v, $type); |
129 | my ($k, $v, $type); |
… | |
… | |
185 | |
190 | |
186 | $self->{hdl} = new AnyEvent::Handle |
191 | $self->{hdl} = new AnyEvent::Handle |
187 | connect => [$self->{host} => $self->{port}], |
192 | connect => [$self->{host} => $self->{port}], |
188 | timeout => $self->{timeout}, |
193 | timeout => $self->{timeout}, |
189 | on_error => sub { |
194 | on_error => sub { |
190 | warn "@_\n";#d# |
195 | warn "$self->{host}: $_[2]\n";#d# |
191 | exit 1; |
196 | exit 1; |
192 | }, |
197 | }, |
193 | on_read => $on_read, |
198 | on_read => $on_read, |
194 | on_eof => $self->{on_eof} || sub { }, |
199 | on_eof => $self->{on_eof} || sub { }, |
195 | ; |
200 | ; |