Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    leone
    @xiasc01
    @bhorn My operating system is Win10 , and I build oatpp in msys2
    @oatpp_io_twitter What's your email address? Please tell me. Thank you.
    oat++
    @oatpp_io_twitter
    @xiasc01 leonid@oatpp.io
    oat++
    @oatpp_io_twitter
    F20B3C75@ED91040C.44DA685D.jpg.jpg
    Sharing here screen of @xiasc01 problem.
    I'll be able to look at it not earlier than Sunday or even Monday. If you guys have any ideas please advice.
    Rikee Maharjan
    @rikee312
    Can anyone help me with the oatpp-websocket . How can i broadcast the message to all the active socket connection ?
    Benedikt-Alexander Mokroß
    @bhorn
    As i needed this feature, I've written an register (as component) where all newly opened websockets register themself. With this register I can call all websockets
    kapilpipaliya
    @kapilpipaliya
    hi @bhorn on windows which compiler you use?
    Rikee Maharjan
    @rikee312
    thanks @bhorn will try that
    Benedikt-Alexander Mokroß
    @bhorn
    MSVC - Visual Studio 2017 and 2019
    kapilpipaliya
    @kapilpipaliya
    thanks
    Benedikt-Alexander Mokroß
    @bhorn
    @rikee312 don't forget to implement the de-registering upon ws-error or ws-close ;)
    Rikee Maharjan
    @rikee312
    cool
    Benedikt-Alexander Mokroß
    @bhorn
    @rikee312 thats what I'm using: https://gist.github.com/bhorn/fe1348a391b9ea7e4e74d93b761bbe0d There def. are better ways to do it but its simple, quick and works like a charm
    Rikee Maharjan
    @rikee312
    Thanks dude , Really helped it
    Benedikt-Alexander Mokroß
    @bhorn
    np. let me hear if you have any improvements.
    Rikee Maharjan
    @rikee312
    ok
    oat++
    @oatpp_io_twitter
    Hey @bhorn , thanks for sharing your example!
    Hello @xiasc01 , have you managed to fix your compilation error with errno not found on your system?
    oat++
    @oatpp_io_twitter

    @bhorn , @rikee312
    Two comments as for example:

    Benedikt-Alexander Mokroß
    @bhorn
    @oatpp_io_twitter @rikee312 definitely right! Should mutex that. This example is very broken down and not exactly what I run, I tried to focus on the logic. I will update my example with mutexes
    Benedikt-Alexander Mokroß
    @bhorn
    So one should subclass oatpp::websocket::WebSocket to add an Mutex and protect the used functions?
    oat++
    @oatpp_io_twitter

    So one should subclass oatpp::websocket::WebSocket to add an Mutex and protect the used functions?

    It may be a solution in case you use the socket from different places in your code.

    Other example (like in the chat-rooms - Peer.hpp) - is to have wrapper over WebSocket which handles the synchronization and aggregates some user data.

    @bhorn @rikee312
    leone
    @xiasc01
    @oatpp_io_twitter no , It's still unresolved.
    Kun Deng
    @kdeng00
    Hey @/all, is anyone running into double free when implementing your own ReadCallback for streaming?
    oat++
    @oatpp_io_twitter
    Hey @kdeng00 , double free may occur due to multiple different reasons. Most probably it has nothing to do with ReadCallback itself. In majority of cases it is concurrency issue or incorrect memory management.
    The only thing how to fix it - is detailed code-review and debugging.
    Also it would be very helpful if you could provide the code + steps to reproduce + exact place where double free happens.
    Kun Deng
    @kdeng00

    Gotcha, here is the demo endpoint I was testing with

    ENDPOINT("GET", "/demo", streamDemo) {
    
                oatpp::data::v_io_size dSize = 1024;
                auto db = std::make_shared<oatpp::web::protocol::http::outgoing::ChunkedBody>(
                        oatpp::web::protocol::http::outgoing::ChunkedBody(
                            std::shared_ptr<myCallback>(new myCallback()), nullptr, dSize));
    
                auto response = OutgoingResponse::createShared(Status::CODE_200, db);
                response->putHeader(Header::CONNECTION, Header::Value::CONNECTION_KEEP_ALIVE);
                response->putHeader(Header::CONTENT_TYPE, "text/html");
    
                return response;
            }

    Then my implementation of ReadCallback

    class myCallback : public oatpp::data::stream::ReadCallback
        {
        public:
            myCallback() : 
                m_counter(0)
            { }
    
            oatpp::data::v_io_size read(void *buff, oatpp::data::v_io_size count)
            { 
                if (m_counter > 100) {
                    std::cout << "done reading" << std::endl;
                    return 0;
                }
    
                const auto amt = 10;
    
                std::string text(amt, 'a');
                std::memcpy(buff, text.c_str(), amt);
    
                m_counter++;
    
                return amt;
            }
        private:
            v_int32 m_counter;
        };
    Kun Deng
    @kdeng00

    Found the issue. I war constructing the ChunkedBody object with a shared_ptr when I should have made it shared
    This:

    auto db = std::make_shared<oatpp::web::protocol::http::outgoing::ChunkedBody>(
                            std::make_shared<myCallback>(), nullptr, dSize);

    Instead of this:

    auto db = std::make_shared<oatpp::web::protocol::http::outgoing::ChunkedBody>(
                        oatpp::web::protocol::http::outgoing::ChunkedBody(
                            std::shared_ptr<myCallback>(new myCallback()), nullptr, dSize));
    oat++
    @oatpp_io_twitter
    Hey @kdeng00 ,
    thanks for sharing the issue, code and a fix.
    Good you found the fix!
    Bob Tolbert
    @rwtolbert
    anyone see problems returning binary data or ASCII data as application/octet-stream?
        auto data = oatpp::base::StrBuffer::createShared(res.data(), oeCast(v_int32, res.size()), false);
        auto response = createResponse(Status::CODE_200, data);
        response->putHeader(Header::CONTENT_TYPE, "application/octet-stream");
        return response;
    oat++
    @oatpp_io_twitter
    Hello @rwtolbert , what kind of problem do you experiencing when returning data as octet-stream?
    Bob Tolbert
    @rwtolbert
    res is just a std::string
    but the result on the client is corrupted in the first 10-20 bytes
    oat++
    @oatpp_io_twitter
    I see
    Please change false to true
    Thats because your std::string is deleted
    And oatpp string is referensing deleted memory
    You have a memory leak
    @rwtolbert please let me know if it helped
    oat++
    @oatpp_io_twitter

    if res is a local variable then you have memory leak in your endpoint

    auto data = oatpp::base::StrBuffer::createShared(res.data(), oeCast(v_int32, res.size()), false /* try to put true here */);

    The difference:

    std::string a = "text";
    oatpp::base::StrBuffer b(a.data(), a.size(), false);  // <-- b is pointing to data stored in a.
    oatpp::base::StrBuffer c(a.data(), a.size(), true); // <-- c is a copy of data stored in a
    Bob Tolbert
    @rwtolbert
    oh, gotcha
    sorry for the delay
    bingo
    that did it.
    thanks
    oat++
    @oatpp_io_twitter
    Great!