Giter Club home page Giter Club logo

Comments (8)

skypjack avatar skypjack commented on June 9, 2024

Can I ask you to provide a reproducible example? Also, why do you use a check in the first case while you don't do that in the second case?

from uvw.

smalls12 avatar smalls12 commented on June 9, 2024

I can work on providing a full example sure.
As for the ErrorEvent/CheckEvent, I was just copying the examples from tests.

from uvw.

smalls12 avatar smalls12 commented on June 9, 2024

Here is full example with a chunk for uvw and a chunk for libuv.
I expect that the loop simply blocks until a SIGINT is captured.

#include <uvw.hpp>

#include <iostream>
#include <unistd.h>

void on_uv_walk(uv_handle_t* handle, void*)
{
    std::cout << "on_uv_walk()\n";
    uv_close(handle, NULL);
}

void on_sigint_received(uv_signal_t *handle, int)
{
    std::cout << "on_sigint_received()\n";
    int result = uv_loop_close(handle->loop);
    if(result == UV_EBUSY)
    {
        uv_walk(handle->loop, on_uv_walk, NULL);
    }
}

int main()
{
    // ---------------------------------------------------------------
    // uvw
    // ---------------------------------------------------------------
    // auto loop = uvw::Loop::getDefault();
    // auto signal_ = loop->resource<uvw::SignalHandle>();
    // signal_->on<uvw::ErrorEvent>(
    // [](const uvw::ErrorEvent&, uvw::SignalHandle&)
    // {
    //     std::cerr << "uvw::ErrorEvent()\n";
    // });

    // signal_->on<uvw::CheckEvent>(
    // [&](const uvw::CheckEvent&, uvw::SignalHandle&)
    // {
    //     std::cout << "uvw::CheckEvent()\n";
    //     loop->stop();
    // });

    // if(signal_->init())
    // {
    //     std::cout << "signal - initialized?\n";
    //     signal_->start(2);
    // }
    // else
    // {
    //     std::cerr << "signal - error?\n";
    // }
    
    // std::cout << "start\n";
    // loop->run();
    // std::cout << "stop\n";

    // ---------------------------------------------------------------

    // ---------------------------------------------------------------
    // libuv
    // ---------------------------------------------------------------
    uv_signal_t *sigint = new uv_signal_t;
    uv_signal_init(uv_default_loop(), sigint);
    uv_signal_start(sigint, on_sigint_received, SIGINT);
    uv_loop_t* main_loop = uv_default_loop();
    std::cout << "start\n";
    uv_run(main_loop, UV_RUN_DEFAULT);
    std::cout << "stop\n";
    // ---------------------------------------------------------------

    return 0;
}

from uvw.

smalls12 avatar smalls12 commented on June 9, 2024

I can work on providing a full example sure. As for the ErrorEvent/CheckEvent, I was just copying the examples from tests.

Disregard this, I see what you are asking now.

I'm not sure where I saw the return code being checked on init() for uvw but I'm sure I just copied it.
I didn't use it for libuv as I was just quickly testing for comparison purposes.

from uvw.

skypjack avatar skypjack commented on June 9, 2024

No, I mean, you have a check handle in one case while you don't have it in the other case.
It's like comparing apples and pears, you know. That is why I'm not fully getting what you're doing here.
Also, with libuv you're attaching a listener for a sigint while you aren't doing the same when using uvw.
So, it's quite obvious that the two examples work differently maybe?

from uvw.

smalls12 avatar smalls12 commented on June 9, 2024

I'll just rephrase.
Can you point me to an example of how to capture a SIGINT with a listener?
Thanks.

from uvw.

skypjack avatar skypjack commented on June 9, 2024

I'm afraid I can't. If there isn't one in the testsuite, then I can't really help.

from uvw.

smalls12 avatar smalls12 commented on June 9, 2024

Something has clearly been lost in translation here,
I was able to solve the problem on my own switching CheckEvent to SignalEvent.
This will capture the SIGINT and run my callback.
This behaviour is not in the test suite which lead to my confusion as the test suite only uses CheckEvent.

from uvw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.