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

Ernest N. Prabhakar, Ph.D. prabhaka at apple.com
Wed Jan 20 07:04:22 PST 2010

Hi Jordan,

I actually thought about adding a "file" method on Dispatch::Source that (in cases where you passed in an IO object instead of an file descriptor), would return that object.  Of course it would return nothing in other cases, but maybe that's OK.  Still not sure what to call it -- any suggestions?

Alternatively, we could only add that method to a subclass of Source, so it only existed when valid.  If we did that, we should probably do the same for the "merge" method on custom sources - but having a subclass with only a single method seems lame.  Maybe implement it in the superclass, but raise an exception if called for an invalid type?

-- Ernie P.

On Jan 20, 2010, at 12:37 AM, Jordan K. Hubbard wrote:

> 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(Time.now.ctime)
> 	client.puts "Closing down, Bunkie!"
> 	client.close
> }
> m.run
> 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?
> Thanks!
> - Jordan
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

More information about the MacRuby-devel mailing list