Ejemplo n.º 1
0
int main(int argc, char **argv)
{
    long flags;
    assert(ecore_init());
    mgr = upump_ecore_mgr_alloc(UPUMP_POOL, UPUMP_BLOCKER_POOL);
    assert(mgr != NULL);

    /* Create a pipe with non-blocking write */
    assert(pipe(pipefd) != -1);
    flags = fcntl(pipefd[1], F_GETFL);
    assert(flags != -1);
    flags |= O_NONBLOCK;
    assert(fcntl(pipefd[1], F_SETFL, flags) != -1);

    /* Create watchers */
    write_idler = upump_alloc_idler(mgr, write_idler_cb, NULL, NULL);
    assert(write_idler != NULL);
    write_watcher = upump_alloc_fd_write(mgr, write_watcher_cb, NULL, NULL,
                                         pipefd[1]);
    assert(write_watcher != NULL);
    read_timer = upump_alloc_timer(mgr, read_timer_cb, NULL, NULL, timeout, 0);
    assert(read_timer != NULL);
    read_watcher = upump_alloc_fd_read(mgr, read_watcher_cb, NULL, NULL,
                                       pipefd[0]);
    assert(read_watcher != NULL);

    /* Start tests */
    upump_start(write_idler);

    ecore_main_loop_begin();
    printf("\nread: \t%zd\nwrite: \t%zd\n", bytes_read, bytes_written);
    assert(bytes_read);
    assert(bytes_read == bytes_written);

    /* Clean up */
    upump_free(write_idler);
    upump_free(write_watcher);
    upump_free(read_timer);
    upump_free(read_watcher);
    upump_mgr_release(mgr);

    ecore_shutdown();

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    long flags;
    loop = ev_default_loop(0);
    mgr = upump_ev_mgr_alloc(loop, UPUMP_POOL, UPUMP_BLOCKER_POOL);
    assert(mgr != NULL);

    /* Create a pipe with non-blocking write */
    assert(pipe(pipefd) != -1);
    flags = fcntl(pipefd[1], F_GETFL);
    assert(flags != -1);
    flags |= O_NONBLOCK;
    assert(fcntl(pipefd[1], F_SETFL, flags) != -1);

    /* Create watchers */
    write_idler = upump_alloc_idler(mgr, write_idler_cb, NULL);
    assert(write_idler != NULL);
    write_watcher = upump_alloc_fd_write(mgr, write_watcher_cb, NULL,
                                         pipefd[1]);
    assert(write_watcher != NULL);
    read_timer = upump_alloc_timer(mgr, read_timer_cb, NULL, timeout, 0);
    assert(read_timer != NULL);
    read_watcher = upump_alloc_fd_read(mgr, read_watcher_cb, NULL, pipefd[0]);
    assert(read_watcher != NULL);

    /* Start tests */
    upump_start(write_idler);
    ev_loop(loop, 0);
    assert(bytes_read);
    assert(bytes_read == bytes_written);

    /* Clean up */
    upump_free(write_idler);
    upump_free(write_watcher);
    upump_free(read_timer);
    upump_free(read_watcher);
    upump_mgr_release(mgr);

    ev_default_destroy();
    return 0;
}
Ejemplo n.º 3
0
void run(struct upump_mgr *mgr)
{
    long flags;
    assert(mgr != NULL);

    /* Create a pipe with non-blocking write */
    assert(pipe(pipefd) != -1);
    flags = fcntl(pipefd[1], F_GETFL);
    assert(flags != -1);
    flags |= O_NONBLOCK;
    assert(fcntl(pipefd[1], F_SETFL, flags) != -1);

    /* Create watchers */
    write_idler = upump_alloc_idler(mgr, write_idler_cb, NULL, NULL);
    assert(write_idler != NULL);
    write_watcher = upump_alloc_fd_write(mgr, write_watcher_cb, NULL, NULL,
                                         pipefd[1]);
    assert(write_watcher != NULL);
    read_timer = upump_alloc_timer(mgr, read_timer_cb, NULL, NULL, timeout, 0);
    assert(read_timer != NULL);
    read_watcher = upump_alloc_fd_read(mgr, read_watcher_cb, NULL, NULL,
                                       pipefd[0]);
    assert(read_watcher != NULL);

    /* Start tests */
    upump_start(write_idler);
    upump_mgr_run(mgr, NULL);
    assert(bytes_read);
    assert(bytes_read == bytes_written);

    /* Clean up */
    upump_free(write_idler);
    upump_free(write_watcher);
    upump_free(read_timer);
    upump_free(read_watcher);

    upump_mgr_release(mgr);
}
Ejemplo n.º 4
0
/** @internal @This checks if the pump may be allocated.
 *
 * @param upipe description structure of the pipe
 * @param flow requested output flow format
 * @return an error code
 */
static int upipe_voidsrc_check(struct upipe *upipe, struct uref *flow)
{
    struct upipe_voidsrc *upipe_voidsrc = upipe_voidsrc_from_upipe(upipe);

    if (flow != NULL)
        upipe_voidsrc_store_flow_def(upipe, flow);

    if (!upipe_voidsrc->uref_mgr) {
        upipe_voidsrc_require_uref_mgr(upipe);
        return UBASE_ERR_NONE;
    }

    if (!upipe_voidsrc->uclock) {
        upipe_voidsrc_require_uclock(upipe);
        return UBASE_ERR_NONE;
    }

    upipe_voidsrc_check_upump_mgr(upipe);
    if (unlikely(!upipe_voidsrc->upump_mgr))
        return UBASE_ERR_NONE;

    if (!upipe_voidsrc->timer) {
        struct upump *timer = upump_alloc_timer(upipe_voidsrc->upump_mgr,
                                                upipe_voidsrc_worker,
                                                upipe, upipe->refcount,
                                                upipe_voidsrc->interval, 0);
        if (unlikely(!timer)) {
            upipe_throw_fatal(upipe, UBASE_ERR_UPUMP);
            return UBASE_ERR_UPUMP;
        }
        upipe_voidsrc_set_timer(upipe, timer);
        upump_start(timer);
    }

    return UBASE_ERR_NONE;
}