GithubHelp home page GithubHelp logo

Comments (8)

Barenboim avatar Barenboim commented on August 15, 2024

Because client’s main function terminates!
Please: wait_group.wait();
BTW, are you sure your encode() doesn’t have memleak?

from workflow.

Barenboim avatar Barenboim commented on August 15, 2024

About exit of the program: https://github.com/sogou/workflow/tree/master/docs/about-exit.md

from workflow.

Barenboim avatar Barenboim commented on August 15, 2024

Your implementation of append() cannot garentee you receive the whole message. You know that, right?

from workflow.

wangh09 avatar wangh09 commented on August 15, 2024

Your implementation of append() cannot garentee you receive the whole message. You know that, right?

Thanks for your reply!
For the append(): yes I know that, just want to see it works for now;
For the enocde(): I have to make the buffer a member of the message right?

from workflow.

Barenboim avatar Barenboim commented on August 15, 2024

Your implementation of append() cannot garentee you receive the whole message. You know that, right?

Thanks for your reply!
For the append(): yes I know that, just want to see it works for now;
For the enocde(): I have to make the buffer a member of the message right?

Yes. Make it a member of the message class, allocate memory in it's constructor or encode() function and release in it's destructor. But don't do this:

        using NTF = WFNetworkTaskFactory<protocol::OrderMessage, protocol::OrderMessage>;
        WFTestTask *task = NTF::create_client_task(TT_TCP, host, port,
                                                       retry_max,
                                                       std::move(callback));
        task->set_keep_alive(30 * 1000);
        task->get_resp()->buffer = new char[MAX];     // not very good.
        return task;

This makes the response class non-RAII. But the response object may be destroyed and reconstructed during communication when retrial occurs. If it's not a RAII class, you have to set prepare function or make a derivation of WFNetworkTask.

from workflow.

wangh09 avatar wangh09 commented on August 15, 2024

Another question about the client: I see it is tasks that can be kept alive, but a task seems to be not thread safe. Then how to reuse the connections?
Say my architecture is Client <-> ServerA <-> ServerB, ServerA accepts stateless http requests from the Client, and passes them to ServerB on persistent tcp connections (10 for example). should I create 10 tasks and use locks to share them?

from workflow.

Barenboim avatar Barenboim commented on August 15, 2024

So you are writing a ServerA? Please refer to tutorial-05-http_proxy
Note: connections can be reused, but tasks cannot be reused by users.

from workflow.

Barenboim avatar Barenboim commented on August 15, 2024

task->set_keep_alive() sets the connection underneath to be reused or not, not the task.
For http protocol, adding http header “Connection” is a better way. Though both ways work.

from workflow.

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.