summaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2018-07-08 02:45:16 +0200
committerBert Belder <bertbelder@gmail.com>2018-07-08 21:01:24 +0200
commit8a17db8266dad0325d04762a27c4f61446d26d2e (patch)
tree7fca8ff2d7936b11d38c0edc972012540580b12e /src/main.cc
parent7c5db007deb43d65550213ff07ad95bc0cce6f00 (diff)
Add 'command id' field to messages
This allows for correlating response messages to the command message that caused them.
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/main.cc b/src/main.cc
index 78c86ee15..a801bc292 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -22,7 +22,7 @@ static char** global_argv;
static int global_argc;
// Sends StartRes message
-void HandleStart(Deno* d) {
+void HandleStart(Deno* d, uint32_t cmd_id) {
flatbuffers::FlatBufferBuilder builder;
char cwdbuf[1024];
@@ -37,20 +37,20 @@ void HandleStart(Deno* d) {
auto start_argv = builder.CreateVector(args);
auto start_msg = CreateStartRes(builder, start_cwd, start_argv);
- auto base = CreateBase(builder, 0, Any_StartRes, start_msg.Union());
+ auto base = CreateBase(builder, cmd_id, 0, Any_StartRes, start_msg.Union());
builder.Finish(base);
deno_buf bufout{reinterpret_cast<const char*>(builder.GetBufferPointer()),
builder.GetSize()};
deno_set_response(d, bufout);
}
-void HandleCodeFetch(Deno* d, const CodeFetch* msg) {
+void HandleCodeFetch(Deno* d, uint32_t cmd_id, const CodeFetch* msg) {
auto module_specifier = msg->module_specifier()->c_str();
auto containing_file = msg->containing_file()->c_str();
printf("HandleCodeFetch module_specifier = %s containing_file = %s\n",
module_specifier, containing_file);
// Call into rust.
- handle_code_fetch(module_specifier, containing_file);
+ handle_code_fetch(cmd_id, module_specifier, containing_file);
}
void MessagesFromJS(Deno* d, deno_buf buf) {
@@ -59,17 +59,18 @@ void MessagesFromJS(Deno* d, deno_buf buf) {
DCHECK(verifier.VerifyBuffer<Base>());
auto base = flatbuffers::GetRoot<Base>(buf.data);
+ auto cmd_id = base->cmdId();
auto msg_type = base->msg_type();
const char* msg_type_name = EnumNamesAny()[msg_type];
- printf("MessagesFromJS msg_type = %d, msg_type_name = %s\n", msg_type,
- msg_type_name);
+ printf("MessagesFromJS cmd_id = %d, msg_type = %d, msg_type_name = %s\n",
+ cmd_id, msg_type, msg_type_name);
switch (msg_type) {
case Any_Start:
- HandleStart(d);
+ HandleStart(d, base->cmdId());
break;
case Any_CodeFetch:
- HandleCodeFetch(d, base->msg_as_CodeFetch());
+ HandleCodeFetch(d, base->cmdId(), base->msg_as_CodeFetch());
break;
case Any_NONE: