]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: card: add an argument for open(2) flag into API to open ALSA control character...
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 10 Feb 2020 08:02:03 +0000 (17:02 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Tue, 11 Feb 2020 12:01:11 +0000 (21:01 +0900)
As long as using the created Gsource with GMainContext, the call of poll(2)
system call with infinite timeout surely returns when quit() method is
called for the context. All of GMainContext implements GWakeup with eventfd
and the call of quit() emits event via file descriptor of eventfd. This
brings wakeup from blocking when poll(2) is called with inifinite timeout.
This means that it's safe for event polling without O_NONBLOCK.

On the other hand, there are many options for file descriptors; e.g.
O_APPEND and O_CLOEXEC. For the case, glib framework has no support.

This commit adds an argument for the open flags.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/ctl/card.c
src/ctl/card.h

index 0a53a7ccfa17437a7196ef1f0171f2fb6f7af3c2..953920f99c8c130e2a13194eeb0da17fb6438113 100644 (file)
@@ -161,11 +161,13 @@ ALSACtlCard *alsactl_card_new()
  * alsactl_card_open:
  * @self: A #ALSACtlCard.
  * @card_id: The numerical ID of sound card.
+ * @open_flag: The flag of open(2) system call. O_RDONLY is forced to fulfil internally.
  * @error: A #GError.
  *
  * Open ALSA control character device for the sound card.
  */
-void alsactl_card_open(ALSACtlCard *self, guint card_id, GError **error)
+void alsactl_card_open(ALSACtlCard *self, guint card_id, gint open_flag,
+                       GError **error)
 {
     ALSACtlCardPrivate *priv;
     char *devnode;
@@ -177,7 +179,8 @@ void alsactl_card_open(ALSACtlCard *self, guint card_id, GError **error)
     if (*error != NULL)
         return;
 
-    priv->fd = open(devnode, O_RDONLY | O_NONBLOCK);
+    open_flag |= O_RDONLY;
+    priv->fd = open(devnode, open_flag);
     if (priv->fd < 0) {
         generate_error(error, errno);
         g_free(devnode);
index c932d00f2c9a8faad170896555144c5731268463..c2247b24eafa7804868c2e4952f406c882e2f77f 100644 (file)
@@ -76,7 +76,8 @@ GType alsactl_card_get_type() G_GNUC_CONST;
 
 ALSACtlCard *alsactl_card_new();
 
-void alsactl_card_open(ALSACtlCard *self, guint card_id, GError **error);
+void alsactl_card_open(ALSACtlCard *self, guint card_id, gint open_flag,
+                       GError **error);
 
 void alsactl_card_get_info(ALSACtlCard *self, ALSACtlCardInfo **card_info,
                            GError **error);