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 658020 - GSource for a single GPollFD
GSource for a single GPollFD
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: mainloop
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-09-01 22:56 UTC by Allison Karlitskaya (desrt)
Modified: 2013-01-15 19:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add a GPollFD source (6.53 KB, patch)
2011-09-01 23:44 UTC, Allison Karlitskaya (desrt)
none Details | Review

Description Allison Karlitskaya (desrt) 2011-09-01 22:56:56 UTC
Rumour has it that lots of people would find a GSource that polls a single GPollFD very handy.


gboolean (*GPollFDFunc) (GPollFD *poll_fd,
                         GIOCondition revents,
                         gpointer data);

/* note: makes copy of GPollFD structure */
GSource *    g_poll_fd_source_new   (GPollFD        *poll_fd);

guint        g_poll_fd_add          (GPollFD        *poll_fd,
                                     GPollFDFunc     func,
                                     gpointer        data);

guint        g_poll_fd_add_full     (gint            priority,
                                     GPollFD        *poll_fd,
                                     GPollFDFunc     func,
                                     gpointer        user_data,
                                     GDestroyNotify  notify);

I'll do that now, using the new GSource API from bug #657729.
Comment 1 Colin Walters 2011-09-01 23:14:21 UTC
Sounds good to me; I would crosslink in the docs between this and g_io_create_watch(); mention that this is the new (better) way to make watches for a file descriptor.
Comment 2 Dan Winship 2011-09-01 23:33:48 UTC
(In reply to comment #1)
> Sounds good to me; I would crosslink in the docs between this and
> g_io_create_watch(); mention that this is the new (better) way to make watches
> for a file descriptor.

Well, on UNIX maybe, but GPollFD doesn't take file descriptors on Windows, so you still need to use a GIOWatch (or better yet, libgio) if you want to be portable.

Which leads to the question: should this be a UNIX-only API, or should it document that on UNIX it takes a file descriptor, and on Windows it takes a waitable HANDLE?

(In reply to comment #0)
> gboolean (*GPollFDFunc) (GPollFD *poll_fd,
>                          GIOCondition revents,
>                          gpointer data);

If the callback function includes the revents as a parameter, then is there any point in using a GPollFD at all? Just have the caller pass a file descriptor and an events mask, and g_poll_fd_add() can create the GPollFD for you.
Comment 3 Allison Karlitskaya (desrt) 2011-09-01 23:39:29 UTC
I dropped the revents field while I was writing the patch specifically because it was redundant.

GPollFD makes sense on Windows.  We have g_cancellable_make_pollfd() for example.  If you take the result of that function and create a pollfd source from it, then it would work.
Comment 4 Allison Karlitskaya (desrt) 2011-09-01 23:44:46 UTC
Created attachment 195448 [details] [review]
Add a GPollFD source
Comment 5 Dan Winship 2011-09-02 12:36:28 UTC
(In reply to comment #3)
> GPollFD makes sense on Windows.  We have g_cancellable_make_pollfd() for
> example.  If you take the result of that function and create a pollfd source
> from it, then it would work.

But we only have that function because we belatedly realized that g_cancellable_get_fd() wasn't portably usable.

Anyway, I wasn't saying it didn't make sense on Windows, I was saying that it doesn't work with "file descriptors" on Windows
Comment 6 Allison Karlitskaya (desrt) 2011-09-02 13:40:08 UTC
ahh.  I see what you're saying.

I wonder if maybe we should change the structure definition of GPollFD on Windows to actually contain a field called 'handle'...  This is technically an API change, but it would only impact people whose code is already broken...

Then we could advertise that it was a meaningful thing to use.