After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 333098 - Add support for write FDs to GIOChannel
Add support for write FDs to GIOChannel
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: win32
2.10.x
Other All
: Normal enhancement
: ---
Assigned To: gtk-win32 maintainers
gtk-win32 maintainers
Depends on:
Blocks:
 
 
Reported: 2006-03-02 08:45 UTC by Marcus Brinkmann
Modified: 2006-03-11 21:03 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Patch to add support for write FDs to GIOChannel on w32 targets (10.02 KB, patch)
2006-03-02 08:46 UTC, Marcus Brinkmann
none Details | Review

Description Marcus Brinkmann 2006-03-02 08:45:20 UTC
Hi,

this patch adds support for write fds to the w32 backend of
GIOChannel.  Currently, only read fds are supported.  In GPGME, we
need bidirectional communication to a child process, so we had to add
this feature.

The code was developed with the constraint that only minimal changes
are made to the existing code base.  This has caused a little bit of
awkwardness: The same events as for the read thread are used, but with
reversed meaning (ie, data_avail means space is availabel and vice
versa).  That's the only wart in the code that's specific to the write
support.

If you check out the code, ignoring the new functions write_thread and
buffer_write, these are the changes to the generic code: A new
field DIRECTION has been added to the channel structure, and in a
couple of places the DIRECTION field or the condition flag
(G_IO_IN/G_IO_OUT) is used to dispatch to the correct implementation.
Also, the write function calls buffer_write if there is a writer thread now.

This patch was developed as part of the GPG4Win project by g10 Code GmbH.

If you have any questions, please don't hesitate to contact me.

Thanks,
Marcus Brinkmann
mb@g10code.de
Comment 1 Marcus Brinkmann 2006-03-02 08:46:56 UTC
Created attachment 60468 [details] [review]
Patch to add support for write FDs to GIOChannel on w32 targets
Comment 2 Tor Lillqvist 2006-03-02 09:03:52 UTC
Thanks. Looks nice, don't see any reason not to accept and commit this. Later tonight. Will be in GLib 2.10.1.
Comment 3 Tor Lillqvist 2006-03-02 12:18:14 UTC
Do you think there should be some check to catch if somebody for some reasons tries to watch a fd for both G_IO_IN and G_IO_OUT? There is just one thread_id field, will it confuse the code if first a G_IO_IN watch is created, then a G_IO_OUT (or vice versa)? Or should we have separate read_thread_id and write_thread_id fields?
Comment 4 Marcus Brinkmann 2006-03-02 17:33:20 UTC
Yes, I think there should be such a check.  I didn't put it in because it can change the behaviour of existing code.  Currently, with both flags set it will default to the reader implementation consistently.  This is preserved by my patch.  But yes, I think it would be a good idea to catch this case and bail out.

Also, buffer_read and buffer_write should probably check the direction field if there is a thread running.

Comment 5 Marcus Brinkmann 2006-03-02 17:35:45 UTC
I forgot to respond to the separate thread ids issue.  This is only necessary if you want to actually support waiting for both reading and writing, because then there will be both threads.  Of course, then you also need separate events and buffers, etc.

With a IN/OUT flag check, and the direction field, I think you can robustly catch all misuses of a channel object even with only one thread id field (as long as only unidirectional communication needs to be supported).
Comment 6 Tor Lillqvist 2006-03-11 21:03:27 UTC
Thinking more about this, I guess it's pretty unlikely that anyone would want to have both a read and write watch for a normal file descriptor. That happens only for sockets. Applied the patch as such.