775: def send(wait=false, ttl=nil, &block)
776: if wait
777: message = nil
778: blockedThread = Thread.current
779: timer_thread = nil
780: timeout = false
781: unless ttl.nil?
782: timer_thread = Thread.new {
783: sleep ttl
784: timeout = true
785: blockedThread.wakeup
786: }
787: end
788: @session.connection.send(self.to_s, block) do |je|
789: if je.element_tag == "message" and je.thread.element_data == @thread
790: je.consume_element
791: message = Message.from_element(@session, je)
792: blockedThread.wakeup unless timeout
793: unless timer_thread.nil?
794: timer_thread.kill
795: timer_thread = nil
796: end
797: end
798: end
799: Thread.stop
800: return message
801: else
802: @session.connection.send(self.to_s, block) if @session
803: end
804: end