reconnecting a plugin

Franky liedekef at telenet.be
Mon Dec 3 10:45:16 UTC 2007


Franky Van Liedekerke wrote:
> Franky wrote:
>> Franky wrote:
>>> Hi,
>>>
....
> 
> Ok, further testing shows me that the problem is in Socket.pm
> (Danga::Socket), in the EpollEventLoop implementation.
> If I use the normal PollEventLoop instead of EpollEventLoop (in the
> function FirstTimeEventLoop), then all works just fine.
> So for now, this seems like the best solution (haven't tried KQueue
> yet). Any comments on this?
> 
> Franky
> 

Ok, even more testing reveals the error:

the EpollEventLoop function in Socket.pm does a epoll_ctl on the file
descriptors in %OtherFds, but this is only done once, before the
while(1) loop. So, adding other filedescriptors later on just fails
because epoll_ctl is never executed again. The same is valid for KQueue
btw, but not for the normal PollEventLoop, where this happens within the
while(1) loop.
So changing the code in Socket.pm from:
--------------------------------------------------
sub EpollEventLoop {
    my $class = shift;

    foreach my $fd ( keys %OtherFds ) {
        if (epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, EPOLLIN) == -1) {
            warn "epoll_ctl(): failure adding fd=$fd; $! (", $!+0, ")\n";
        }
    }

    while (1) {
--------------------------------------------------

to:
--------------------------------------------------
sub EpollEventLoop {
    my $class = shift;

    while (1) {
        my @events;
        my $i;
        my $timeout = RunTimers();

        foreach my $fd ( keys %OtherFds ) {
            epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, EPOLLIN);
        }

--------------------------------------------------

fixes it for Epoll (same for KQueue). I'm not checking the return code
of epoll_ctl because of the warnings it would create for already
existing and controlled fd's.
An even better solution would be to add the epoll and KQueue codes to
the function AddOtherFds, so the epoll_ctl isn't executed every time.
Some comments from the Danga::Socket author would be nice here ... Brad?

Franky



More information about the Djabberd mailing list