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

Ernest N. Prabhakar, Ph.D. prabhaka at apple.com
Wed Jan 20 10:49:39 PST 2010


Hi Jordan,

On Jan 20, 2010, at 9:35 AM, Jordan K. Hubbard wrote:
> On Jan 20, 2010, at 7:04 AM, Ernest N. Prabhakar, Ph.D. wrote:
> 
>> 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?
> 
> Well, frankly, I expected the handle method to return the original handle - that's sort of what the principle of least astonishment would suggest, no?

Unfortunately, there's two principles at work. One is fidelity with the underlying GCD code, where "handle" is always an integer -- which is what we do now, where we auto-convert the File object into an Integer to give to GCD.

But you're right, a better application would be to simply store the passed handle in the Source object, and pass -that- back for the handle method (which would also save us from boxing/unboxing).

Feel free to file a bug and assign it to me...

-- Ernie P.


> I could see file as a method which returns the underlying fd, assuming you needed that for some reason, though you should also be able to extract that from handle if it's an IO Object, no?  I'm trying to figure out why you would want anything but the original handle...
> 
>> 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?
> 
> See above - do we really need to go through all that indirection?

Well, right now 


> 
> - 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