XMPP4R uses a thread that is separate from the main thread to do its I/O
over the XML stream. Whenever that thread receives a message that has
callbacks associated, those callback routines are executed in the context of
that separate thread. It might be the case that if you create new XML
stream I/O activity from within that same thread, then it could lead to a
deadlock or some other side effect under certain conditions--which might
explain the intermittent nature of your problem. I think this happens
because if you block execution inside a callback, then all stream I/O is
also blocked (although I don't have the code in front of me now, so I'm
going from memory here).
When my code receives a message to which respond with another message, I
spawn a new thread to get that work done. The following code snippet is
(mostly) taken directly from a bot framework I've been working on. This
method is for message handling (as opposed to presence handling like yours),
so it checks to make sure the message contains a recognized command string
and that the message is not a delayed delivery (which might not matter in a
join callback). Look at how lines 6 to 13 establish a new thread to send
the reply and also set up the proper error handling so it doesn't just crash
without telling you. I should add that having it log errors instead of
sending them as XMPP messages would be better, but I was lazy that day.
@client is the Jabber::Client object and @muc is a related
Jabber::MUC::MUCClient object.
http://pastie.textmate.org/886921
def base_message_handler( msg )
msg_handled = false
if !msg.body.nil? && (m = @cmd_rx.match(msg.body.strip)) &&
@commands.keys.include?(m[1])
msg_handled = true
Thread.new do
begin
@muc.send Jabber::Message.new(nil, "some message")
rescue Exception => e
reply = "Error while responding to command:\n%s\n%s" % [e.message,
e.backtrace.join("\n")]
@client.send(Jabber::Message.new(msg.from, reply))
end
end unless msg.delayed?
end
msg_handled
end
+=
Erik Elmore
Post by StuFF mc? In the same thread? How would you do else?
Post by Erik ElmoreYou are trying to send a message in the same thread as the handler. I
know
Post by Erik Elmorethat isn't ideal, but I don't know if it might cause a deadlock condition
or
Post by Erik Elmoreraise errors, however.
+=
Erik Elmore
Post by StuFF mchttp://pastie.textmate.org/private/h8tmlxwwahv0rbhrcsw7rg
Anybody would know why?
Cheers.
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel