Re: Error converting a pipe (Handler) to fd on vs 2003 to use with g_io_channel_win32_new_fd



> when I can this g_io_channel_win32_new_fd, I see this warning,
>
> GLib-WARNING **: giowin32.c:1564: 3 isn't a C library file descriptor

> and thus pipe isn't created at all :(

Hmm, you already created the pipe in the CreatePipe() call. You mean
the watch isn't created.

Most likely this is because your code is using a different C library
than GLib is. GLib (as normally built, as in the binaries provided on
ftp.gnome.org) uses the msvcrt.dll C library. Code compiled using
Microsoft's newer compilers use msvcr80.dll or msvcr90.dll. "file
descriptors" are specific to the C library that they are passed to.
Are you using Microsoft's compiler? In that case the return value from
_open_osfhandle() called by your code has no meaning to the functions
in the C library that GLib uses.

A solution would  be to compile your code with mingw instead.

Another solution would be to use the msvcrt.dll runtime even if you
use Microsoft's current compiler. This requires some trickery, see for
instance http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-using-visual-c-2005/
. (I have not tried that myself, but others have. I don't know how
well it works with MSVS2008.)

A third solution would be to not use g_io_channel_win32_new_fd() but
instead put the HANDLE to the pipe's read end in a GPollFD and
continue that way. Unfortunately it gets a bit complex then, and I
can't describe how to proceed off-hand.

Yes, all this is a mess. It is unfortunate.

>       gioChannels[0] =g_io_channel_win32_new_fd(fds[0] );
>       gioChannels[1] =g_io_channel_win32_new_fd(fds[0] );

Did you notice that you pass fds[0] in both cases? copy/paste error?

>       g_io_add_watch( gioChannels[1],(GIOCondition) (G_IO_IN |

Here you probably mean gioChannels[0] ?

> The goal is to notify main application that something occurred in
> thread thread. In my case, I can't use gtk in multi-threaded way
> (calling functions of main thread from spawned one), so I am trying to
> do it via pipes.

Much simpler to use some other GLib API for this. Or Windows events,
if you want Windows-specific code.

> I also saw that it could be a visual studio issue in this thread
> http://mail.nl.linux.org/xchat-discuss/2004-03/msg00177.html

Yes, that describes the multiple C library issue.

--tml


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]