]>
jfr.im git - irc/SurrealServices/srsv.git/blob - branches/erry-devel/SrSv/IRCd/Queue.pm
1 # This file is part of SurrealServices.
3 # SurrealServices is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # SurrealServices is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with SurrealServices; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 package SrSv
::IRCd
::Queue
;
19 # The purpose of this module is to make sure lines get processed in an
20 # order that makes sense, e.g., a JOIN should not be processed before
21 # the corresponding NICKCONN has been.
23 # FIXME: This may not be well optimized. It also can be fouled up by
24 # conflicting messages with the same WF value, such as the same nick
25 # disconnecting and connecting at once.
29 use Exporter
'import';
30 BEGIN { our @EXPORT_OK = qw(ircd_enqueue queue_size) }
33 use SrSv
::Message
qw(message);
35 our @queue = map [], 0..3; # 3 is the maximum WF value
39 my ($ircline, $wf) = @$message{'IRCLINE', 'WF'};
46 push @{$queue[$wf]}, $message;
48 if(_is_runnable
($message)) {
49 print "$message->{IRCLINE} is runnable immediately. (WF=$message->{WF})\n" if DEBUG
;
51 $message->{_Q_RUNNING
} = 1;
57 foreach (@queue) { $r += @$_ }
63 my ($ircline, $wf) = @$message{'IRCLINE', 'WF'};
65 print "Called finished() for $ircline\n" if DEBUG
();
67 for(my $i; $i < @{$queue[$wf]}; $i++) {
68 if($queue[$wf][$i]{IRCLINE
} == $ircline) {
69 splice(@{$queue[$wf]}, $i, 1);
74 if($message->{TYPE
} eq 'SEOS') {
75 $message->{TYPE
} = 'POSTSEOS';
84 my ($ircline, $wf) = @$message{'IRCLINE', 'WF'};
87 if(defined($queue[$_][0]) and $queue[$_][0]{IRCLINE
} < $ircline) {
88 print "Line $ircline must wait for $queue[$_][0]{IRCLINE}\n" if DEBUG
;
97 foreach my $q (@queue) {
98 INNER
: foreach my $message (@$q) {
99 next INNER
if $message->{_Q_RUNNING
};
101 if(_is_runnable
($message)) {
102 print "$message->{IRCLINE} is now runnable\n" if DEBUG
;
105 $message->{_Q_RUNNING
} = 1;