mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-29 21:08:24 +00:00
Update docs for mg_rpc_process()
This commit is contained in:
1 parent
79c49e64e8
commit
24cb9467c0
1 file changed
+15
-15
+15
-15
@@ -3152,25 +3152,25 @@ Parameters:
|
|||||||
Usage example:
|
Usage example:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
struct mg_rpc *s_rpc_head = NULL;
|
struct mg_rpc *s_rpcs = NULL; // Empty RPC list head
|
||||||
// add methods
|
mg_rpc_add(&s_rpcs, mg_str("rpc.list"), mg_rpc_list, NULL); // Add rpc.list
|
||||||
// ...
|
// ... add more RPC methods
|
||||||
|
|
||||||
char *resp = NULL;
|
// On request, process the incoming frame
|
||||||
// get a request, pass it into r.frame
|
struct mg_str req = mg_str("{\"id\":1,\"method\":\"sum\",\"params\":[1,2]}");
|
||||||
|
struct mg_iobuf io = {0, 0, 0, 512}; // Empty IO buf, with 512 realloc granularity
|
||||||
struct mg_rpc_req r = {
|
struct mg_rpc_req r = {
|
||||||
.head = &s_rpc_head,
|
.head = &s_rpcs, // RPC list head
|
||||||
.rpc = NULL,
|
.rpc = NULL, // This will be set by mg_rpc_process()
|
||||||
.pfn = mg_pfn_realloc,
|
.pfn = mg_pfn_iobuf, // Printing function: print into the io buffer
|
||||||
.pfn_data = &resp,
|
.pfn_data = &io, // Pass our io buffer as a parameter
|
||||||
.req_data = NULL,
|
.req_data = NULL, // No specific request data
|
||||||
.frame = mg_str("{\"id\":1,\"method\":\"sum\",\"params\":[1,2]}")
|
.frame = req, // Specify incoming frame
|
||||||
};
|
};
|
||||||
|
|
||||||
mg_rpc_process(&r);
|
mg_rpc_process(&r);
|
||||||
|
if (io.buf != NULL) printf("Response: %s\n", (char *) io.buf);
|
||||||
if (resp) printf("%s\n", resp);
|
mg_iobuf_free(&io);
|
||||||
free(resp);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### mg\_rpc\_ok(), mg\_rpc\_vok()
|
### mg\_rpc\_ok(), mg\_rpc\_vok()
|
||||||
|
|||||||
Reference in new issue
Block a user