core :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Minimal usage example of libevent
module libevent_example is example
import libevent
# Factory creating instances of `EchoConnection` to handle new connections
class MyFactory
super ConnectionFactory
redef fun spawn_connection(buf, address)
do
return new EchoConnection(buf)
end
end
# Connection echoing data received from clients back at them
class EchoConnection
super Connection
redef fun read_callback(content)
do
print "Received: {content}"
write content
end
end
# Skip the actual execution when testing
if "NIT_TESTING".environ == "true" then exit 0
# Setup libevent system
var event_base = new NativeEventBase
var factory = new MyFactory(event_base)
# Open a TCP socket for listening
factory.bind_tcp("localhost", 8888)
# Open a UNIX domain socket for listening
factory.bind_unix("/tmp/my.sck")
# Launch event loop
event_base.dispatch
event_base.free
lib/libevent/libevent_example.nit:15,1--57,15