Skip Menu |

This queue is for tickets about the AnyEvent-MtGox-Stream CPAN distribution.

Report information
The Basics
Id: 79928
Status: stalled
Priority: 0/
Queue: AnyEvent-MtGox-Stream

People
Owner: Nobody in particular
Requestors: qd1qupwe.hs2 [...] 20minutemail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: New features. Patchfile included.
Hi. New features in patchfile: What's new? # example 0: # AnyEvent::HTTP initialization parameters my $client = AnyEvent::MtGox::Stream->new( request_params => {timeout => 30, headers => {'user-agent' => 'MySearchClient 1.0'},}, on_message => sub { }, on_error => sub { }, on_disconnect => sub { }, ); # example 1: custom service url my $client = AnyEvent::MtGox::Stream->new( url => 'http://socketio.mtgox.com/socket.io/', on_message => sub { }, on_error => sub { }, on_disconnect => sub { }, ); # example 2: custom heartbeat period my $client = AnyEvent::MtGox::Stream->new( heartbeat_eval => sub { $_[0] - 10; }, on_message => sub { }, on_error => sub { }, on_disconnect => sub { }, ); # example 3: dynamic heartbeat timer my $time0; my $scalar = {heartbeat_timer => undef,}; $cl = AnyEvent::MtGox::Stream->new( heartbeat_eval => sub{ ($time0 = $_[0]) / 2 }, # set half of time0 store => \$scalar, on_message => sub { }, on_error => sub { }, on_disconnect => sub { }, ); ... $store->{heartbeat_timer}->set(1, $time0 * 2/3 ); # set 2/3 of time0 Regards, Anonymous.
Subject: patchfile.patch
diff --git a/Stream.pm b/Stream.pm index d31e73f..10ef937 100644 --- a/Stream.pm +++ b/Stream.pm @@ -16,6 +16,11 @@ use URI; our $VERSION = '0.02'; $VERSION = eval $VERSION; +our $conf = { + def_url => 'http://socketio.mtgox.com/socket.io/1', + heartbeat_dec => 2, + }; + sub new { my ($class, %params) = @_; @@ -24,14 +29,16 @@ sub new { my $on_error = $params{on_error} || sub { croak @_ }; my $on_message = $params{on_message} || sub { }; - my $server = 'socketio.mtgox.com'; + my $store = $params{store} || \{}; my $handle; + my @rqst_params = []; + $params{request_params} and @rqst_params = %{$params{request_params}}; # Socket.IO handshake. - my $uri = URI->new("http://$server/socket.io/1"); + my $uri = URI->new($params{url} || $conf->{def_url}); $uri->scheme('https') if $secure; AE::log debug => "Making Socket.IO handshake to $uri"; - http_post $uri, undef, sub { + http_post $uri, undef, @rqst_params, sub { my ($body, $headers) = @_; return $on_error->('Socket.IO handshake failed') unless '200' eq $headers->{Status} and defined $body; @@ -75,8 +82,15 @@ sub new { $send_message->('2::'); }; - $timer = AE::timer $heartbeat - 2, $heartbeat - 2, $send_heartbeat - if $heartbeat; + $heartbeat and ( + ($timer = AE::timer $heartbeat - 2, + ($params{heartbeat_eval} + and abs(int $params{heartbeat_eval}->($heartbeat))) || + ($heartbeat - $conf->{heartbeat_dec}), + $send_heartbeat), + (exists $$store->{heartbeat_timer} and $$store->{heartbeat_timer} = $timer + ) + ); my $json = JSON->new; diff --git a/out.patch b/out.patch new file mode 100644 index 0000000..e69de29
On Sat Sep 29 11:49:06 2012, anonymous wrote: Show quoted text
> New features in patchfile:
Thanks Show quoted text
> # example 0: # AnyEvent::HTTP initialization parameters
I can see the benefit in this. Show quoted text
> # example 1: custom service url
Is this for future-proofing or are there existing alternate endpoints? Show quoted text
> # example 2: custom heartbeat period > # example 3: dynamic heartbeat timer
Please explain what the practical benefit of these are. Is the 2 second padding not sufficient in some cases.
From: qd1qupwe.hs2 [...] 20minutemail.com
Show quoted text
> > # example 1: custom service url
> > Is this for future-proofing or are there existing alternate endpoints?
API documentation report about https://socketio.mtgox.com/mtgox and, of course, users search url-like parameter (Yes, I did). Option can be applicable in future and now it's usable for tests (experiments). Show quoted text
> > # example 2: custom heartbeat period > > # example 3: dynamic heartbeat timer
> > Please explain what the practical benefit of these are. Is the 2 second > padding not sufficient in some cases.
there are 2 ways to customization: - static (on init; simple way to static customization. What about slow connections?) - dynamic (usable if you want to work over tor and you want to control heartbeat period real-time because lagometer reports (otherwise you will get disconnects from server). I'm using it to work over TOR-network). Thanks, Anonymous.
From: qd1qupwe.hs2 [...] 20minutemail.com
Hello. Please, reject that ugly patch. I have found better way. In next days I'll send new patchfile. Regards.