Hi,
I'm not sure what's going on here. I have a simple script that reaches the
end (and prints out "here") but the script never ends and I have to ctrl-c
it.
below is the simple script that never ends, and below that is the
Finance::InteractiveBrokers::TWS code that implements and wraps the
Inline::Java
I think here must be some thread that is still active or some other resource
that is not terminated that's hanging my program, but I can't tell what it
is.
Thanks for any help
Jay
#!/usr/bin/perl
use strict;
use warnings;
package Local::Callback;
sub new {
my $class = shift;
return bless {}, $class;
}
sub AUTOLOAD {
my ($self, @args) = @_;
our $AUTOLOAD;
print "$AUTOLOAD called with: ", join '^', @args, "\n";
return;
}
package main;
use Finance::InteractiveBrokers::TWS;
my $cb = Local::Callback->new();
my $tws = Finance::InteractiveBrokers::TWS->new(callback=>$cb);
my $client_socket = $tws->get_EClientSocket();
my $api = $tws->get_api();
my $host = "pt";
my $port = 7496;
my $client_id = $$;
$api->OpenCallbackStream();
while (! $tws->get_EClientSocket->isConnected()) {
$client_socket->eConnect($host, $port, $client_id);
}
while ((my $rc = $api->WaitForCallback(1)) > -1){
if ($rc > 0){
$api->ProcessNextCallback() ;
last if ! $tws->get_EClientSocket->isConnected();
}
else {
# A timeout has occured after, in this case, 5 secs.
print "5 seconds have passed, still waiting for callback...\n" ;
$client_socket->eDisconnect();
}
}
print "here\n";
A link to Finance::InteractiveBrokers::TWS
http://search.cpan.org/src/JSTRAUSS/Finance-InteractiveBrokers-TWS-v0.0.5/lib/Finance/InteractiveBrokers/TWS.pm