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>
/**
* alsatimer_user_instance_open:
* @self: A #ALSATimerUserInstance.
+ * @open_flag: The flag of open(2) system call. O_RDONLY is forced to fulfil internally.
* @error: A #GError.
*
* Open ALSA Timer character device to allocate queue.
*/
-void alsatimer_user_instance_open(ALSATimerUserInstance *self, GError **error)
+void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag,
+ GError **error)
{
ALSATimerUserInstancePrivate *priv;
char *devnode;
if (*error != NULL)
return;
- priv->fd = open(devnode, O_RDONLY);
+ open_flag |= O_RDONLY;
+ priv->fd = open(devnode, open_flag);
g_free(devnode);
if (priv->fd < 0) {
generate_error(error, errno);
ALSATimerUserInstance *alsatimer_user_instance_new();
-void alsatimer_user_instance_open(ALSATimerUserInstance *self, GError **error);
+void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag,
+ GError **error);
void alsatimer_user_instance_attach(ALSATimerUserInstance *self,
ALSATimerDeviceId *device_id,