[MacRuby-devel] How to get handle from Dispatch::Source::DATA type source?

Jordan K. Hubbard jkh at apple.com
Wed Jan 20 00:37:37 PST 2010

Hi guys,

So, now that GCD sources are supported (go Ernie!), I just thought I'd play with a simple echo server example in MacRuby:

require 'socket'

q = Dispatch::Queue.concurrent
m = Dispatch::Queue.main

hostname = "localhost"
port = 25000
s = TCPServer.open(hostname, port)
src = Dispatch::Source.new(Dispatch::Source::READ, s, 0, q) { |src|
	client = s.accept	# XXX Would like to actually get this from src, rather than grabbing the server socket object directly
	client.puts "Closing down, Bunkie!"

The line with the XXX is the issue I'm trying to figure out.  If I look at src.handle or src.data, I end up getting an integer which looks like a fd, not the original TCPSocket instance I passed in, which means I can't call the accept method on it.  Is there some secret to getting at the original handle?


- Jordan

More information about the MacRuby-devel mailing list