Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    DuckVador
    @DuckVador
    图片.png
    this test cause double free, when call h->type(). I'm wondering what is the reason.
    Michele Caini
    @skypjack
    is it one of the tests from uvw or one you wrote?
    DuckVador
    @DuckVador
    my own test
    Michele Caini
    @skypjack
    ok, did you try with an interval that is larger than 0ms?
    DuckVador
    @DuckVador
    still double free
    actually, if I call h->active, seems everything is ok.
    I pasted my code here :https://pastebin.com/raw/3xeJHfmp
    Commander Keen
    @madhat1
    Hello people, I'm wondering where I can find real world samples of using UVW.
    Official documentation shows an example of a TCP server, I'm looking for Timer and File I/O examples.
    Michele Caini
    @skypjack
    GitHub contains many example if you like
    Commander Keen
    @madhat1
    I couldn't find timer and file I/O examples, can you direct me to them?
    smalls12
    @smalls12
    I can't figure out how to create a PollHandle for polling a socket to indicate when something is ready to be read
    I don't see any examples, and the tests only test FsPollHandle
    Michele Caini
    @skypjack
    @smalls12 uvw doesn't add up on libuv, if you know how to do that with the latter, you can just translate it to the former
    PollHandle offers start and stop as expected and they work exactly as their counterparts in libuv
    smalls12
    @smalls12
    I should provide more context
    I am trying to integrate a 3rdparty library with libuv / uvw similar to how I would use boost::asio
    basically I just want the libuv event loop to tell me when there is something to read or write and hand that off to the 3rdparty library
    Michele Caini
    @skypjack
    This doesn't really add much :slight_smile: the documentation for a poll handle in libuv is here, with uvw it's just a matter of invoking a member function rather than a free function
    You pass a file descriptor to the constructor and invoke start, that's it
    Events are sent when something relevant happens, you can listen to them with a callback
    All this stuff is described in the readme file though and it's literally the same for all classes
    How you obtain a file descriptor doesn't depende on libuv nor uvw, so it's up to you
    smalls12
    @smalls12
    I'll post the code I have tried when I get back infront of it
    smalls12
    @smalls12
    I'm back looking at this now
    this is the code I have tried, it is seg faulting on me
    auto loop = uvw::Loop::getDefault();
    
        auto poller = loop->resource<uvw::PollHandle>(fd);
        poller->on<uvw::PollEvent>(
        [](const auto &, auto &req)
        {
            std::cout << "poller - some event?\n";
        });
    
        if(poller->init())
        {
            std::cout << "poller - initialized?\n";
            poller->start(uvw::PollHandle::Event::READABLE);
        }
        else
        {
            std::cerr << "poller - error?\n";
        }
    
        loop->run();
    is this what you expected?
    fd is the file descriptor from the other library
    Michele Caini
    @skypjack
    No, it's not expected but it's hard to tell what the problem is without a reproducible example. From what I can see, it can be in uvw, it can be in the other library, it can be elsewhere in the middle...
    smalls12
    @smalls12
    ok the fd was actually -1
    doh
    now it is working
    but I do not see any events indicating something is available to read
    smalls12
    @smalls12
    ok that was my problem again
    I think I did something wrong with the ::on call
    the event is being spammed now with some poll event
    instead of only indicating when there is data to read
    smalls12
    @smalls12

    trying to get some more information from the event

    poller->on<uvw::PollEvent>(
        [](const uvw::PollEvent& event, uvw::PollHandle& handle)
        {
    
        });

    is there anything to be obtained from event or handle?

    Michele Caini
    @skypjack
    You can look at the documentation of either uvw or libuv, because the event wraps the underlying event (if any) and the handle does the same with a libuv's poll handle
    That is, uvw is a layer on top of libuv and makes you available what is exposed by the underlying library
    smalls12
    @smalls12
    I was able to solve it.
    Would you accept a PR showing how to use the poller? Since it is not explicitly captured in an example?
    Michele Caini
    @skypjack
    Sure thing, PRs are always welcome :slight_smile:
    Stefano Fiorentino
    @stefanofiorentino
    Sorry to be absent from this room so far ;)
    Michele Caini
    @skypjack
    No worries man, it's a very low traffic one
    KartikAiyer
    @KartikAiyer

    Hi folks, I have a question about best practices and design choices
    I've written up a small mDNS library with service discovery and querying being the key use cases. I using uvw which means I don't have to deal with sockets and can get a good set of platform agnostic APIs like ntohs etc. My question is what is the best way to post callbacks given that everything is async. e.g
    I have the following API which performs a discovery query and the API accepts callbacks

      void discover(discovery_response_f fn,
                    std::function<void(const uvw::ErrorEvent&)> error_fn);

    where discovery_response_f is a client supplied function pointer which receives a parsed response. In the implementation, those are called in the listeners for UDPDataEvent and ErrorEvent. I'm wondering if the more idiomatic way would be have my classes inherit from Emitter and provide similar Events that client can listen on. Looking at uvw, its obvious it would need a good dose of template wizardry, but I'm just what would others recommend ? No rush here. Just looking for wisdom :)

    Michele Caini
    @skypjack
    @KartikAiyer not sure I get why you want to inherit from the emitter (granted, 11PM here, probably the problem is on this side of the keyboard :sweat_smile:). Using a callback as you did already is literally the way uwv works and is meant to work.
    KartikAiyer
    @KartikAiyer
    Got it. Definitely don't think the problem is on your end. I kind of wanted to get an idea of how you intended clients of uvw to handle their own async jobs. The listener and publisher APIs that uvw has are really very nice and I was wondering if clients using uvw should also aspire to using a similar approach to provide async notifications.
    Michele Caini
    @skypjack
    Oh, well, yeah, emitter is publicly available because you can make the same api leak to the user codebase
    Though, I've not a strong opinion about it, I think it's more a matter of tastes
    skebanga
    @skebanga_gitlab
    Hi all. Does uvw support SSL and/or HTTP and/or websockets? If not, are there any recommended libraries which build on top of it which offer these things?
    Michele Caini
    @skypjack
    Hi @skebanga_gitlab no, there is not actually, uvw wraps libuv and only offers what the latter offers, that is, no http nor ssl support