Coder Social home page Coder Social logo

Comments (4)

Barenboim avatar Barenboim commented on August 16, 2024

CommTarget是通讯目标,基本上就是ip+port, 还有两个超时参数。连接池什么的都在target里。
CommSession是一次req->resp的交互,主要要实现message_in(), message_out()等几个虚函数,让核心知道怎么产生消息。
CommService就是服务了,主要是new_session()的实现,因为对server来讲,session是被动产生的。
Communicator::request(CommSession *session, CommTarget *target)这个接口就可以实现一个异步的网络请求了,你可以写个程序试试,Session大概这么派生:

class MyHttpSession : public CommSession
{
private:
    CommMessageOut *message_out() override { return new protocol::HttpRequest; }
    CommMessageIn *message_in() override { return new protocol::HttpResponse; }
    void handle(int state, int error) override
    {
        protocol::HttpResponse *resp = (protocol::HttpResponse *)this->get_message_in();
        // print resp
        ...
        delete this->get_message_out();
        delete this->get_message_in();
        delete this;
    }
};

int main()
{
    Communicator comm;
    comm.init(2, 10);
    CommTarget target;
    target.init(...);
    comm.request(new MyHttpSession, &target);
    ...
}

from workflow.

sourcema avatar sourcema commented on August 16, 2024

image
请问下CommConnection只有析构方法,为什么这么定义呢,出于什么考虑呢?

from workflow.

Barenboim avatar Barenboim commented on August 16, 2024

image 请问下CommConnection只有析构方法,为什么这么定义呢,出于什么考虑呢?

Target或Service里有个new_connection可以产生这个类的派生,用户可以给连接设置上下文。

from workflow.

sourcema avatar sourcema commented on August 16, 2024

image 请问下CommConnection只有析构方法,为什么这么定义呢,出于什么考虑呢?

Target或Service里有个new_connection可以产生这个类的派生,用户可以给连接设置上下文。

多谢

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.