Index: perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
===================================================================
--- perl/modules/IRC/lib/BarnOwl/Module/IRC.pm	(revision cab045b76d772fbed102254200b99c9c1ec3565a)
+++ perl/modules/IRC/lib/BarnOwl/Module/IRC.pm	(revision 9c7a701363179369d764454b0d99e559ab89ed9e)
@@ -69,5 +69,13 @@
 }
 
-sub mainloop_hook {
+#sub mainloop_hook {
+#    return unless defined $irc;
+#    eval {
+#        $irc->do_one_loop();
+#    };
+#    return;
+#}
+
+sub OwlProcess {
     return unless defined $irc;
     eval {
@@ -76,4 +84,5 @@
     return;
 }
+
 
 sub register_handlers {
@@ -109,5 +118,5 @@
 $BarnOwl::Hooks::startup->add(\&startup);
 $BarnOwl::Hooks::shutdown->add(\&shutdown);
-$BarnOwl::Hooks::mainLoop->add(\&mainloop_hook);
+#$BarnOwl::Hooks::mainLoop->add(\&mainloop_hook);
 
 ################################################################################
@@ -165,4 +174,7 @@
         BarnOwl::admin_message("IRC", "Connected to $alias as $nick");
         $ircnets{$alias} = $conn;
+        my $fd = $conn->getSocket()->fileno();
+        BarnOwl::add_dispatch($fd, \&OwlProcess);
+        $conn->{FD} = $fd;
     } else {
         die("IRC::Connection->connect failed: $!");
Index: perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
===================================================================
--- perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	(revision 5ff830a145bf5f2e869a06f9dc2d43f97773d189)
+++ perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	(revision 9c7a701363179369d764454b0d99e559ab89ed9e)
@@ -69,4 +69,10 @@
 }
 
+sub getSocket
+{
+    my $self = shift;
+    return $self->conn->socket;
+}
+
 ################################################################################
 ############################### IRC callbacks ##################################
@@ -168,5 +174,5 @@
     my $self = shift;
     delete $BarnOwl::Module::IRC::ircnets{$self->alias};
-
+    BarnOwl::remove_dispatch($self->{FD});
     BarnOwl::admin_message('IRC',
                            "[" . $self->alias . "] Disconnected from server");
Index: perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
===================================================================
--- perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	(revision 879e7e9461c653e47de1977e9abb6ba1af6fea08)
+++ perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	(revision 9c7a701363179369d764454b0d99e559ab89ed9e)
@@ -116,13 +116,7 @@
             BarnOwl::error("Connection for $jid undefined -- error in reload?");
         }
-
-        my $status = $client->Process(0);
-        if ( !defined($status) ) {
-            BarnOwl::error("Jabber account $jid disconnected!");
-            do_logout($jid);
-        }
         if ($::shutdown) {
             do_logout($jid);
-            return;
+            next;
         }
         if ($vars{status_changed}) {
@@ -387,4 +381,7 @@
 		$conn->renameConnection($jidStr, $fullJid);
                 queue_admin_msg("Connected to jabber as $fullJid");
+                # The remove_dispatch() method is called from the
+                # ConnectionManager's removeConnection() method.
+                BarnOwl::add_dispatch($client->getSocket()->fileno(), sub { $client->OwlProcess() });
             }
         }
Index: perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm
===================================================================
--- perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm	(revision 892568bf6e3ceea8724cef719078e5f6c2455b16)
+++ perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm	(revision 9c7a701363179369d764454b0d99e559ab89ed9e)
@@ -110,4 +110,43 @@
 
 
+=head2 getSID
+
+Returns the StreamID for this connection.
+
+=cut
+
+sub getStreamID {
+    my $self = shift;
+    return $self->{SESSION}->{id} || "";
+}
+
+=head2 getSocket
+
+Returns the IO::Socket for this connection.
+
+=cut
+
+sub getSocket {
+    my $self = shift;
+    my $sid = getStreamID($self);
+    return $self->{STREAM}->{SIDS}->{$sid}->{sock} || -1;
+}
+
+=head2 OwlProcess
+
+Non-blocking connection processing. For use in a select loop.
+
+=cut
+
+sub OwlProcess {
+    my $self = shift;
+    my $status = $self->Process(0);
+    if ( !defined($status) ) {
+        my $jid = $self->{SESSION}->{FULLJID};
+        BarnOwl::error("Jabber account $jid disconnected!");
+        do_logout($jid);
+    }
+}
+
 =head1 SEE ALSO
 
Index: perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm
===================================================================
--- perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm	(revision 7f33c18e0188d1359c7b0981d9e26757a4f01bb4)
+++ perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm	(revision 9c7a701363179369d764454b0d99e559ab89ed9e)
@@ -37,4 +37,5 @@
     return 0 unless exists $self->{$jidStr};
 
+    BarnOwl::remove_dispatch($self->{$jidStr}->{Client}->getSocket()->fileno());
     $self->{$jidStr}->{Client}->Disconnect()
       if $self->{$jidStr}->{Client};
@@ -51,5 +52,5 @@
     return 0 if $oldJidStr eq $newJidStr;
 
-    $self->{$newJidStr} = $self->{$oldJidStr}; 
+    $self->{$newJidStr} = $self->{$oldJidStr};
     delete $self->{$oldJidStr};
     return 1;
