Today I tried to run a FXRuby app on Windows for the first time and
discovered that addInput on Ruby IO objects doesn't work on Windows.
The same code works OK on Linux. I thought it was a problem
in my code but then I tried to run FXRuby inputs.rb example and
noticed that it doesn't work either on Windows (works ok on Linux).
I haven't played with addInput() too much and so I wouldn't be surprised
to find there are some bugs (for FXRuby, not FOX). Just out of
curiosity, what kind of command did you try to run from the "inputs.rb"
example under Windows? For example, if I run the "inputs.rb" example on
Windows and type:
DIR c:\
in the input field and then press <Enter>, the text window is filled
with the list of files as expected.
Then I looked at the FOX FAQ I found the following note on addInput:
"On MS-Windows, instead of a POSIX file descriptor, you must use a
handle. Thus, under MS-Windows, the addInput() API can be used to wait
on a great variety of kernel objects, ranging from event objects
(which is what you need to use for sockets), to process and thread
handles, and so on. Please consult the MSDN documentation on Winsock2
for details"
Looking at the file io.c in Ruby I'm under the impression that even on
Win32, Ruby uses POSIX file descriptor for IO objects and not Win32
handles?
Yes, you are correct that Ruby uses file descriptors for its I/O objects
while FOX's addInput() function expects a HANDLE to some kernel object
on Windows. To accommodate this difference I use the _get_osfhandle()
function on Windows to convert the POSIX file handle for the Ruby I/O
object into a HANDLE; it happens in the FXRbGetInputHandle() function,
defined in FXRuby.cpp:
// Returns an FXInputHandle for this Ruby file object
FXInputHandle FXRbGetInputHandle(VALUE obj) {
int fd=FIX2INT(rb_funcall(obj,rb_intern("fileno"),0));
#ifdef WIN32
#ifdef __CYGWIN__
return (FXInputHandle) get_osfhandle(fd);
#else
return (FXInputHandle) _get_osfhandle(fd);
#endif
#else
return (FXInputHandle) fd;
#endif
}
Is my understanding correct? And if so is there a workarounf to make
addInput() on Ruby/Win32?
This mapping *should* address the difference in file handle types you
referred to; but there may very well be some other stuff going on. Is
there an example program that you can send me (or, tell me what you were
doing with "inputs.rb" that made it fail)? Seems like we should be able
to make this work OK under Windows without too much trouble.