Giter Site home page Giter Site logo

Comments (6)

holmes1412 avatar holmes1412 commented on May 8, 2024

你好,这三个其实都是srpc中的series使用和上下文共享的经典问题:

  1. buf中的数据想要传给pread_task的回调,有很多种方法,比如把buf捕获到lambda中,或者把buf当作当前series的context也可以。捕获的方法如下:
pread_task = WFTaskFactory::create_pread_task(fd, buf, size, 0,
                                             [buf](WFFileIOTask *) {
                                                // 这里可以拿到捕获进来的buf指针
                                             });

设置到series上下文的做法:

ctx->get_series()->set_context(buf);
pread_task = WFTaskFactory::create_pread_task(fd, buf, size, 0,
                                             [](WFFileIOTask *task) {
                                               buf = series_of(task)->get_context();
                                             });
  1. 那么上边的两种写法同样适合第二个问题:把buf捕获进去或者设置到series的context上,这里演示下第二种写法:
ctx->get_series()->set_context(buf);
ctx->get_series()->set_callback([](const SeriesWork *series) {
                                   free(series->get_context());
                                });
  1. 你的写法ok~

from srpc.

Barenboim avatar Barenboim commented on May 8, 2024

是的呢。因为rpc里,server task用户无法直接接触到,所以,server task的信息在RPCContext里。RPCContext::get_series()就是得到server task所在的series。
如果反过来,想着http server里访问rpc,那么可以用Client::create_xxx_task的方式产生一个rpc任务,然后调用task->serialize_input的接口,序列化rpc任务,再调用series_of(http_server_task)->push_back(rpc_task)。rpc_task的user_data可以利用,done里也是通过RPCContext::get_user_data()拿回。
示例里这些用法都有。

from srpc.

Barenboim avatar Barenboim commented on May 8, 2024

workflow里http_file_server示例用server_task的user_data存buf,不是一个很好的方法。rpc server task的user_data好像用户无法利用。所以,你可以利用series context来存放数据,或用fileio_task的user_data似乎也可以。

from srpc.

heroinhell avatar heroinhell commented on May 8, 2024

感谢!非常详尽!

from srpc.

heroinhell avatar heroinhell commented on May 8, 2024

感谢指导,get_series()和workflow自己还没理解特别清楚,不能流畅的使用。
自己再好好研究一下所有的示例和源码。

from srpc.

Barenboim avatar Barenboim commented on May 8, 2024

我觉得你理解得挺对的啊:)总之就是一切运行中的task一定处于某个series,server task也不例外。rpc task的series是通过ctx->get_series()得到的。

from srpc.

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.