X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXChannel.pm;h=b661510040eebe5954bf7063b24169a2a435fa5c;hb=f77b59f4fcceb428142461972e94345419cbda28;hp=d4b20a2bedffe94f48dc1ab40e5fd83215259133;hpb=0017002e2dc438d49fcc090dc99b6d22f7037aa7;p=spider.git diff --git a/perl/DXChannel.pm b/perl/DXChannel.pm index d4b20a2b..b6615100 100644 --- a/perl/DXChannel.pm +++ b/perl/DXChannel.pm @@ -10,6 +10,9 @@ package DXChannel; require Exporter; @ISA = qw(Exporter); +use Msg; +use DXUtil; + %connects = undef; # create a new connection object [$obj = Connect->new($call, $msg_conn_obj, $user_obj)] @@ -18,7 +21,7 @@ sub new my ($pkg, $call, $conn, $user) = @_; my $self = {}; - die "trying to create a duplicate Connect for call $call\n" if $connects{$call}; + die "trying to create a duplicate channel for $call" if $connects{$call}; $self->{call} = $call; $self->{conn} = $conn; $self->{user} = $user; @@ -61,5 +64,55 @@ sub del delete $connects{$self->{call}}; } + +# handle out going messages +sub send_now +{ + my $self = shift; + my $sort = shift; + my $call = $self->{call}; + my $conn = $self->{conn}; + my $line; + + foreach $line (@_) { + my $t = atime; + chomp $line; + print main::DEBUG "$t > $sort $call $line\n" if defined DEBUG; + print "> $sort $call $line\n"; + $conn->send_now("$sort$call|$line"); + } +} + +sub send_later +{ + my $self = shift; + my $sort = shift; + my $call = $self->{call}; + my $conn = $self->{conn}; + my $line; + + foreach $line (@_) { + my $t = atime; + chomp $line; + print main::DEBUG "$t > $sort $call $line\n" if defined DEBUG; + print "> $sort $call $line\n"; + $conn->send_later("$sort$call|$line"); + } +} + +# send a file (always later) +sub send_file +{ + my ($self, $fn) = @_; + my $call = $self->{call}; + my $conn = $self->{conn}; + my @buf; + + open(F, $fn) or die "can't open $fn for sending file ($!)"; + @buf = ; + close(F); + $self->send_later('D', @buf); +} + 1; __END__;