def sender_loop
loop {
begin
entry = nil
@sending_lock.synchronize do
if @sending_queue.size > 0 then
entry = @sending_queue.shift
dputs ": -Queue[#{@sending_queue.size}] : #{entry.sid}"
end
end
if entry then
entry.exec(@socket)
dputs ": sent a message : #{entry.sid}"
end
rescue => evar
mes = evar.message
dputs "[senderloop] #{evar.to_s} "
if mes["abort"] then
dputs ": [sendloop] disconnected by remote host."
elsif evar.class == IOError then
dputs ": [sendloop] try to reset the connection."
@socket_lock.synchronize do
@socket_state = :socket_closing
end
else
dputs ": [sendloop] going to recover the communication."
end
if entry then
@receiving_lock.synchronize do
@receiving_table[entry.sid] = ResultObject.new.build_by_sender_error(entry.sid,R_PROTOCOL_ERROR,"IOError",evar.message,evar.backtrace.join("\n"))
@receiving_waiter.broadcast
end
end
end
@socket_lock.synchronize do
if @socket_state == :socket_closing then
dputs ": sender-thread terminating..."
return
end
end
@sending_lock.synchronize do
next if @sending_queue.size > 0
dputs ": sender-thread wait..."
@sending_waiter.wait
dputs ": sender-thread wakeup"
end
}
end