Q: How can server callback the client's function?

38 views
Skip to first unread message

林晓锋

unread,
Oct 28, 2019, 8:41:44 AM10/28/19
to Cap'n Proto
Hi ,all:
    It's memtioned that "Make a request that will call back to a function defined locally." at calculator-client.c++.I'm confused how and where the server holds the function and when to call it. (I guess that it's in the EventLoop::turn() by reading code ,but i'm not sure how it works) 

Kenton Varda

unread,
Oct 28, 2019, 1:13:08 PM10/28/19
to 林晓锋, Cap'n Proto
Hi,

Sorry, I don't really understand the question. The client calls `evaluate()` and passes a `Expression` of type `call` containing a `Function` capability. The server receives this expression, calls `getCall().getFunction()` to receive a `Function::Client`, which it can then use to invoke `Function.call()`.

-Kenton

On Mon, Oct 28, 2019 at 5:41 AM 林晓锋 <lxf4...@gmail.com> wrote:
Hi ,all:
    It's memtioned that "Make a request that will call back to a function defined locally." at calculator-client.c++.I'm confused how and where the server holds the function and when to call it. (I guess that it's in the EventLoop::turn() by reading code ,but i'm not sure how it works) 

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/fc157425-7acb-43a7-845f-7a978e27526f%40googlegroups.com.
Message has been deleted

林晓锋

unread,
Oct 28, 2019, 9:50:22 PM10/28/19
to Cap'n Proto
Hi, 
    Thanks for your response!
    For me, I want to keep the `function` which was sent by the client, so that the server can call it whenever it wants. But it seems that the `function` is called immediately by sever when it is received. And I don't know how I can get the `function`'s name and params list, which may be useful when the server wants to call the `function` with its own params.

在 2019年10月29日星期二 UTC+8上午1:13:08,Kenton Varda写道:
Hi,

Sorry, I don't really understand the question. The client calls `evaluate()` and passes a `Expression` of type `call` containing a `Function` capability. The server receives this expression, calls `getCall().getFunction()` to receive a `Function::Client`, which it can then use to invoke `Function.call()`.

-Kenton

On Mon, Oct 28, 2019 at 5:41 AM 林晓锋 <lxf4...@gmail.com> wrote:
Hi ,all:
    It's memtioned that "Make a request that will call back to a function defined locally." at calculator-client.c++.I'm confused how and where the server holds the function and when to call it. (I guess that it's in the EventLoop::turn() by reading code ,but i'm not sure how it works) 

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capn...@googlegroups.com.

Kenton Varda

unread,
Oct 28, 2019, 10:27:06 PM10/28/19
to 林晓锋, Cap'n Proto
On Mon, Oct 28, 2019 at 6:50 PM 林晓锋 <lxf4...@gmail.com> wrote:
Hi, 
    Thanks for your response!
    For me, I want to keep the `function` which was sent by the client, so that the server can call it whenever it wants. But it seems that the `function` is called immediately by sever when it is received.

You can keep a `Client` as long as you want. The calculator example server sends an RPC to the `Function::Client` immediately, but there's nothing stopping a server from hanging onto this value long-term.

And I don't know how I can get the `function`'s name and params list, which may be useful when the server wants to call the `function` with its own params.

Hmm, I think maybe the specific example here might be causing some confusing. The type `Function` is an interface defined in calculator.capnp -- it is specific to this example case. You can send any interface type over RPC, not just `Function`. You can of course include with it any metadata you want, by encoding the metadata in the Cap'n Proto message.

-Kenton
 

在 2019年10月29日星期二 UTC+8上午1:13:08,Kenton Varda写道:
Hi,

Sorry, I don't really understand the question. The client calls `evaluate()` and passes a `Expression` of type `call` containing a `Function` capability. The server receives this expression, calls `getCall().getFunction()` to receive a `Function::Client`, which it can then use to invoke `Function.call()`.

-Kenton

On Mon, Oct 28, 2019 at 5:41 AM 林晓锋 <lxf4...@gmail.com> wrote:
Hi ,all:
    It's memtioned that "Make a request that will call back to a function defined locally." at calculator-client.c++.I'm confused how and where the server holds the function and when to call it. (I guess that it's in the EventLoop::turn() by reading code ,but i'm not sure how it works) 

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capn...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/fc157425-7acb-43a7-845f-7a978e27526f%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/d1c2f940-e418-4783-8ee4-e30d0535e12d%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages