]>
jfr.im git - irc/SurrealServices/srsv.git/blob - tags/0.4.3.1-pre2/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);
34 use SrSv
::Constants
qw( WF_MAX );
36 our @queue = map [], 0..WF_MAX
;
40 my ($ircline, $wf) = @$message{'IRCLINE', 'WF'};
47 push @{$queue[$wf]}, $message;
49 if(_is_runnable
($message)) {
50 print "$message->{IRCLINE} is runnable immediately. (WF=$message->{WF})\n" if DEBUG
;
52 $message->{_Q_RUNNING
} = 1;
62 for(my $i = 0; $i < $depth; ++$i) {
63 $r += scalar @{$queue[$i]};
70 my ($ircline, $wf) = @$message{'IRCLINE', 'WF'};
72 print "Called finished() for $ircline\n" if DEBUG
();
74 for(my $i; $i < @{$queue[$wf]}; $i++) {
75 if($queue[$wf][$i]{IRCLINE
} == $ircline) {
76 splice(@{$queue[$wf]}, $i, 1);
81 if($message->{TYPE
} eq 'SEOS') {
82 $message->{TYPE
} = 'POSTSEOS';
91 my ($ircline, $wf) = @$message{'IRCLINE', 'WF'};
94 if(defined($queue[$_][0]) and $queue[$_][0]{IRCLINE
} < $ircline) {
95 print "Line $ircline must wait for $queue[$_][0]{IRCLINE}\n" if DEBUG
;
104 foreach my $q (@queue) {
105 INNER
: foreach my $message (@$q) {
106 next INNER
if $message->{_Q_RUNNING
};
108 if(_is_runnable
($message)) {
109 print "$message->{IRCLINE} is now runnable\n" if DEBUG
;
112 $message->{_Q_RUNNING
} = 1;