Function create

Summary

#include <src/uvw/loop.h>

(1) static std::shared_ptr< Loop > create()

(2) static std::shared_ptr< Loop > create(uv_loop_t *loop)

Function overload

Synopsis

#include <src/uvw/loop.h>

static std::shared_ptr< Loop > create()

Description

Initializes a new Loop instance.

Returns
A pointer to the newly created loop.

Source

Lines 16-28 in src/uvw/loop.cpp. Line 94 in src/uvw/loop.h.

UVW_INLINE std::shared_ptr<Loop> Loop::create() {
    auto ptr = std::unique_ptr<uv_loop_t, Deleter>{new uv_loop_t, [](uv_loop_t *l) {
        delete l;
    }};

    auto loop = std::shared_ptr<Loop>{new Loop{std::move(ptr)}};

    if(uv_loop_init(loop->loop.get())) {
        loop = nullptr;
    }

    return loop;
}

Synopsis

#include <src/uvw/loop.h>

static std::shared_ptr< Loop > create(uv_loop_t *loop)

Description

Initializes a new Loop instance from an existing resource.

The lifetime of the resource must exceed that of the instance to which it's associated. Management of the memory associated with the resource is in charge of the user.

Parameters

loop - A valid pointer to a correctly initialized resource.

Returns
A pointer to the newly created loop.

Source

Lines 31-34 in src/uvw/loop.cpp. Line 106 in src/uvw/loop.h.

UVW_INLINE std::shared_ptr<Loop> Loop::create(uv_loop_t *loop) {
    auto ptr = std::unique_ptr<uv_loop_t, Deleter>{loop, [](uv_loop_t *) {}};
    return std::shared_ptr<Loop>{new Loop{std::move(ptr)}};
}





Add Discussion as Guest

Log in