#!/usr/bin/perl -w
#$Id: dchub 998 2013-08-14 12:21:20Z pro $ $URL: svn://svn.setun.net/dcppp/trunk/examples/dchub $

=r

dev hub test

=cut

use strict;
no strict qw(refs);
use warnings "NONFATAL" => "all";
no warnings qw(uninitialized);
no if $] >= 5.017011, warnings => 'experimental::smartmatch';
use Time::HiRes;
use Data::Dumper;    #dev only
$Data::Dumper::Sortkeys = $Data::Dumper::Useqq = $Data::Dumper::Indent = 1;
use lib::abs '../lib';
use Net::DirectConnect::hub;
our %config;
use Net::DirectConnect::pslib::psmisc;
psmisc->import(qw(:log));
psmisc::configure();
#my $dc = Net::DirectConnect::hub->new( no_print => undef, );
my $dc = Net::DirectConnect->new(
  protocol => 'adc',
  hub      => 1,
  no_print => undef,
  myport   => 413,
  log      => sub {
    my $dc = ref $_[0] ? shift : {};
    #psmisc::printlog shift(), $dc->{'number'}, join ' ', psmisc::human('time'), @_, "\n";
    psmisc::printlog shift(), "[$dc->{'number'}]", @_,;
  },
  auto_work => sub {
    my $dc = shift;
    #warn('hubwork');
    #Time::HiRes::sleep 0.1;
  },
  %{ $config{dc} },
  %{ $config{dchub} },
);
#$dc->work(100);      #seconds

=without auto_work
while ( $dc->active() ) {
  $dc->work();    #forever
  psmisc::schedule(
    [ 20, 10 ],
    our $dump_sub__ ||= sub {
      print "Writing dump\n";
      psmisc::file_rewrite( 'dump.hub', Dumper $dc);
    }
  );
}
#$dc->wait_finish();
$dc->disconnect();
=cut

#$dc = undef;