closing udp sockets

49 views
Skip to first unread message

Joe

unread,
May 25, 2012, 2:03:05 PM5/25/12
to EventMachine
I'm having a problem of "no datagram socket" after 1016 sockets are
opened and closed. The following prints out:
[...]
closed
1017=>no datagram socket

it *appears* that the sockets are being closed, but I can't open any
more after 1016. Any ideas on what I'm doing wrong?

require 'eventmachine'

class A < EM::Connection
def post_init
close_connection
puts "closed"
end
end

EM.run {
70_000.times do |x|
begin
s = EM.open_datagram_socket "0.0.0.0", 0, A
rescue Exception => e
puts [x,e].join("=>")
exit
end
end
}

Carsten Bormann

unread,
May 25, 2012, 3:09:24 PM5/25/12
to eventm...@googlegroups.com
This works better if you give the EM main loop a chance to run and clean up occasionally.

See the (simple-minded) demonstrator below.

Grüße, Carsten


require 'eventmachine-le'

class A < EM::Connection
def post_init
close_connection
puts "closed"
end
end

def run_one(x)
puts x
begin
s = EM.open_datagram_socket "0.0.0.0", 0, A
rescue Exception => e
puts [x,e].join("=>")
exit
end
EM.add_timer(0.01) { run_one(x+1) }
end

EM.run {
run_one(0)
}

Joe

unread,
May 28, 2012, 1:29:59 PM5/28/12
to EventMachine

Thanks Carsten.
That was it. I will give the EM main loop a chance to catch it's
breath from now on.
Joe
Reply all
Reply to author
Forward
0 new messages