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 724707 - some GSocket source improvements
some GSocket source improvements
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-02-19 02:52 UTC by Allison Karlitskaya (desrt)
Modified: 2014-02-22 15:30 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gsocket: trivial typo fix (844 bytes, patch)
2014-02-19 02:52 UTC, Allison Karlitskaya (desrt)
committed Details | Review
gsocket: use cancellable child source (2.12 KB, patch)
2014-02-19 02:52 UTC, Allison Karlitskaya (desrt)
committed Details | Review
gsocket: don't abuse GPollFD.revents field (1.50 KB, patch)
2014-02-19 02:52 UTC, Allison Karlitskaya (desrt)
needs-work Details | Review
gsocket: make use of g_source_set_ready_time() (3.03 KB, patch)
2014-02-19 02:52 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review
gsocket: use _add_unix_fd() instead of _add_poll() (2.00 KB, patch)
2014-02-19 02:52 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review
gsocket: use check/prepare only on win32 (1.85 KB, patch)
2014-02-19 02:52 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review
gsocket: don't abuse GPollFD.revents field (1.56 KB, patch)
2014-02-21 00:07 UTC, Allison Karlitskaya (desrt)
committed Details | Review
GSource: mark some API as "implementation only" (3.53 KB, patch)
2014-02-21 00:08 UTC, Allison Karlitskaya (desrt)
committed Details | Review
gsocket: make use of g_source_set_ready_time() (3.00 KB, patch)
2014-02-21 00:10 UTC, Allison Karlitskaya (desrt)
committed Details | Review
gsocket: use _add_unix_fd() instead of _add_poll() (2.00 KB, patch)
2014-02-21 00:10 UTC, Allison Karlitskaya (desrt)
committed Details | Review
gsocket: use check/prepare only on win32 (1.99 KB, patch)
2014-02-21 00:11 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Allison Karlitskaya (desrt) 2014-02-19 02:52:03 UTC
Move away from old GSource API -- GSocket is the last user of
_add_poll() in GLib, for example.
Comment 1 Allison Karlitskaya (desrt) 2014-02-19 02:52:05 UTC
Created attachment 269653 [details] [review]
gsocket: trivial typo fix
Comment 2 Allison Karlitskaya (desrt) 2014-02-19 02:52:10 UTC
Created attachment 269654 [details] [review]
gsocket: use cancellable child source

Now that GCancellable's GSource is based on _set_ready_time() instead of
an fd, we should use it as a child source, instead of forcing the
creation of the fd and adding it as a poll.
Comment 3 Allison Karlitskaya (desrt) 2014-02-19 02:52:13 UTC
Created attachment 269655 [details] [review]
gsocket: don't abuse GPollFD.revents field

We are reusing the GPollFD.revents field of the source to store a
temporary value.  Use a local variable for that instead.

This is a refactor to make the next commit easier to understand.
Comment 4 Allison Karlitskaya (desrt) 2014-02-19 02:52:17 UTC
Created attachment 269656 [details] [review]
gsocket: make use of g_source_set_ready_time()

Drop our own hand-rolled version of the same functionality.
Comment 5 Allison Karlitskaya (desrt) 2014-02-19 02:52:21 UTC
Created attachment 269657 [details] [review]
gsocket: use _add_unix_fd() instead of _add_poll()

Use g_source_add_unix_fd() on UNIX instead of using a GPollFD.
Comment 6 Allison Karlitskaya (desrt) 2014-02-19 02:52:24 UTC
Created attachment 269658 [details] [review]
gsocket: use check/prepare only on win32

There is no longer any code left in the check/prepare functions on UNIX,
so put %NULL in the GSourceFuncs vtable.
Comment 7 Dan Winship 2014-02-19 14:59:53 UTC
Comment on attachment 269655 [details] [review]
gsocket: don't abuse GPollFD.revents field

>+#else
>+  events = socket_source->pollfd.revents;
> #endif
>   if (socket_source->socket->priv->timed_out)
>     socket_source->pollfd.revents |= socket_source->condition & (G_IO_IN | G_IO_OUT);

the last line needs to be changed to modify events, not pollfd.revents

(and if you want, it doesn't actually need to reference socket_source->condition, since events gets &'ed against that later anyway)
Comment 8 Dan Winship 2014-02-19 15:05:33 UTC
Comment on attachment 269656 [details] [review]
gsocket: make use of g_source_set_ready_time()

>+  timeout = g_source_get_ready_time (source);
>+  if (timeout >= 0 && timeout < g_source_get_time (source))
>+    {
>+      socket->priv->timed_out = TRUE;

This assumes g_source_set_ready_time() will never be used for any other purpose on a GSocketSource... 

I guess g_source_set_ready_time() is only meant to be used from within GSource implementations? You're not allowed to call it on an arbitrary source to cause it to fire? If so, its docs should mention that.
Comment 9 Dan Winship 2014-02-19 15:09:57 UTC
Comment on attachment 269657 [details] [review]
gsocket: use _add_unix_fd() instead of _add_poll()

>@@ -3219,10 +3223,10 @@ socket_source_prepare (GSource *source,
> 
> #ifdef G_OS_WIN32
>   socket_source->pollfd.revents = update_condition (socket_source->socket);
>-#endif
> 
>   if ((socket_source->condition & socket_source->pollfd.revents) != 0)
>     return TRUE;
>+#endif

pollfd.revents is being used as a temporary variable here too
Comment 10 Dan Winship 2014-02-19 15:11:55 UTC
Comment on attachment 269658 [details] [review]
gsocket: use check/prepare only on win32

>   if ((socket_source->condition & socket_source->pollfd.revents) != 0)
>     return TRUE;
>-#endif
> 
>   return FALSE;

can be simplified to just

  return ((socket_source->condition & socket_source->pollfd.revents) != 0);
Comment 11 Allison Karlitskaya (desrt) 2014-02-21 00:07:31 UTC
Created attachment 269853 [details] [review]
gsocket: don't abuse GPollFD.revents field

Good catch!  Fixed.
Comment 12 Allison Karlitskaya (desrt) 2014-02-21 00:08:22 UTC
Created attachment 269854 [details] [review]
GSource: mark some API as "implementation only"

Clarify that _add_poll() _remove_poll() _add_unix_fd(),
_modify_unix_fd(), _remove_unix_fd(), _query_unix_fd() and
_set_ready_time() are only intended to be used by the implementation of
a particular GSource -- not its consumers.
Comment 13 Allison Karlitskaya (desrt) 2014-02-21 00:10:03 UTC
Created attachment 269855 [details] [review]
gsocket: make use of g_source_set_ready_time()

No changes, but rebased.
Comment 14 Allison Karlitskaya (desrt) 2014-02-21 00:10:52 UTC
Created attachment 269856 [details] [review]
gsocket: use _add_unix_fd() instead of _add_poll()

Rebased only -- your suggested changes are in the next commit instead.
Comment 15 Allison Karlitskaya (desrt) 2014-02-21 00:11:36 UTC
Created attachment 269857 [details] [review]
gsocket: use check/prepare only on win32

With the simplified logic as suggested, and also avoiding touching
revents.
Comment 16 Allison Karlitskaya (desrt) 2014-02-21 16:49:50 UTC
Review of attachment 269854 [details] [review]:

Might make sense as well to add this notice for adding and removing child sources.  Probably people outside of a source implementation should not do that...
Comment 17 Allison Karlitskaya (desrt) 2014-02-22 15:29:45 UTC
Attachment 269653 [details] pushed as d8263dd - gsocket: trivial typo fix
Attachment 269654 [details] pushed as ff96f88 - gsocket: use cancellable child source
Attachment 269853 [details] pushed as 1f71005 - gsocket: don't abuse GPollFD.revents field
Attachment 269854 [details] pushed as 12d65f2 - GSource: mark some API as "implementation only"
Attachment 269855 [details] pushed as 04aee2d - gsocket: make use of g_source_set_ready_time()
Attachment 269856 [details] pushed as e8f26ef - gsocket: use _add_unix_fd() instead of _add_poll()
Attachment 269857 [details] pushed as 8da795d - gsocket: use check/prepare only on win32