Ejemplo n.º 1
0
bool
sol_mainloop_impl_fd_set_flags(void *handle, uint32_t flags)
{
    struct sol_fd_glib *fd_handle = handle;

    SOL_NULL_CHECK(fd_handle, false);

    if (fd_handle->flags == flags)
        return true;

    /* remove the watch but keep the data */
    fd_handle->refcnt++;
    if (!g_source_remove(fd_handle->id))
        return false;

    fd_handle->flags = flags;
    fd_handle->id = g_unix_fd_add_full(0, fd_handle->fd, sol_to_glib_flags(flags), on_fd, fd_handle, unref_fd);
    if (fd_handle->id <= 0) {
        SOL_WRN("Error setting new flags");
        unref_fd(fd_handle);
        return false;
    }

    return true;
}
Ejemplo n.º 2
0
/**
 * g_unix_fd_add:
 * @fd: a file descriptor
 * @condition: IO conditions to watch for on @fd
 * @function: a #GUnixFDSourceFunc
 * @user_data: data to pass to @function
 *
 * Sets a function to be called when the IO condition, as specified by
 * @condition becomes true for @fd.
 *
 * @function will be called when the specified IO condition becomes
 * %TRUE.  The function is expected to clear whatever event caused the
 * IO condition to become true and return %TRUE in order to be notified
 * when it happens again.  If @function returns %FALSE then the watch
 * will be cancelled.
 *
 * The return value of this function can be passed to g_source_remove()
 * to cancel the watch at any time that it exists.
 *
 * The source will never close the fd -- you must do it yourself.
 *
 * Returns: the ID (greater than 0) of the event source
 *
 * Since: 2.36
 **/
guint
g_unix_fd_add (gint              fd,
               GIOCondition      condition,
               GUnixFDSourceFunc function,
               gpointer          user_data)
{
  return g_unix_fd_add_full (G_PRIORITY_DEFAULT, fd, condition, function, user_data, NULL);
}
Ejemplo n.º 3
0
void *
sol_mainloop_impl_fd_add(int fd, uint32_t flags, bool (*cb)(void *data, int fd, uint32_t active_flags), const void *data)
{
    struct sol_fd_glib *fd_handle = malloc(sizeof(*fd_handle));

    SOL_NULL_CHECK(fd_handle, NULL);

    fd_handle->refcnt = 1;

    fd_handle->cb = cb;
    fd_handle->data = data;
    fd_handle->fd = fd;
    fd_handle->flags = flags;

    fd_handle->id = g_unix_fd_add_full(0, fd, sol_to_glib_flags(flags), on_fd, fd_handle, unref_fd);

    return fd_handle;
}