feat: add thespian_unexpected to C API
This commit is contained in:
parent
5789db98fc
commit
e9c1758101
3 changed files with 17 additions and 4 deletions
|
|
@ -17,6 +17,7 @@ void thespian_receive(thespian_receiver, thespian_behaviour_state,
|
|||
thespian_receiver_dtor);
|
||||
|
||||
thespian_result thespian_exit(const char *status);
|
||||
thespian_result thespian_unexpected(cbor_buffer msg);
|
||||
|
||||
bool thespian_get_trap();
|
||||
bool thespian_set_trap(bool);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,18 @@ auto thespian_exit(const char *status) -> thespian_result {
|
|||
return &exit_error_buf;
|
||||
}
|
||||
|
||||
auto thespian_unexpected(cbor_buffer m) -> thespian_result {
|
||||
cbor::buffer buf;
|
||||
const uint8_t *data = m.base;
|
||||
std::copy(data, data + m.len, back_inserter(buf)); // NOLINT
|
||||
auto r = thespian::unexpected(buf);
|
||||
if (r)
|
||||
return nullptr;
|
||||
exit_msg_buf = r.error();
|
||||
exit_error_buf = {exit_msg_buf.data(), exit_msg_buf.size()};
|
||||
return &exit_error_buf;
|
||||
}
|
||||
|
||||
void thespian_link(thespian_handle h) {
|
||||
thespian::handle *h_{
|
||||
reinterpret_cast<thespian::handle *>( // NOLINT(*-reinterpret-cast)
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ static thespian_result cc_receive(thespian_behaviour_state s, thespian_handle,
|
|||
send(st->client, cbor::array("client_connection", "done"));
|
||||
return thespian_exit("normal");
|
||||
} else {
|
||||
LOG("cc_receive: UNEXPECTED msg=%s\n", msg_json);
|
||||
return thespian_unexpected(m);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ static thespian_result client_receive(thespian_behaviour_state s,
|
|||
send(st->server, cbor::array("client", "done"));
|
||||
return thespian_exit("normal");
|
||||
} else {
|
||||
LOG("client_receive: UNEXPECTED msg=%s\n", msg_json);
|
||||
return thespian_unexpected(m);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ static thespian_result sc_receive(thespian_behaviour_state s, thespian_handle,
|
|||
send(st->server, cbor::array("server_connection", "done"));
|
||||
return thespian_exit("normal");
|
||||
} else {
|
||||
LOG("sc_receive: UNEXPECTED msg=%s\n", msg_json);
|
||||
return thespian_unexpected(m);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -245,7 +245,7 @@ static thespian_result server_receive(thespian_behaviour_state s,
|
|||
st->acceptor_closed, st->client_done);
|
||||
st->server_conn_done = true;
|
||||
} else {
|
||||
LOG("server_receive: UNEXPECTED msg=%s\n", msg_json);
|
||||
return thespian_unexpected(m);
|
||||
}
|
||||
if (st->acceptor_closed && st->client_done && st->server_conn_done) {
|
||||
LOG("server_receive: all done, exiting success\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue