Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Jan 2, 2024
1 parent 70038de commit f2f6da1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions include/ylt/coro_rpc/impl/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct err_code {
public:
errc ec;
err_code() : ec(errc::ok) {}
err_code(uint16_t ec) : ec{ec} {};
explicit err_code(uint16_t ec) : ec{ec} {};
err_code(errc ec) : ec(ec){};
err_code& operator=(errc ec) {
this->ec = ec;
Expand All @@ -51,7 +51,8 @@ struct err_code {
err_code& operator=(const err_code& o) = default;
bool operator!() const { return ec == errc::ok; }
operator errc() const { return ec; }
operator uint16_t() const { return static_cast<uint16_t>(ec); }
operator bool() const { return static_cast<uint16_t>(ec); }
explicit operator uint16_t() const { return static_cast<uint16_t>(ec); }
uint16_t val() const { return static_cast<uint16_t>(ec); }
};
inline bool operator!(errc ec) { return ec == errc::ok; }
Expand Down
6 changes: 4 additions & 2 deletions src/coro_rpc/examples/base_examples/rpc_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <ylt/coro_rpc/coro_rpc_client.hpp>
#include <ylt/easylog.hpp>

#include "ylt/coro_rpc/impl/errno.h"

using namespace coro_rpc;

std::string hello_world() {
Expand Down Expand Up @@ -100,13 +102,13 @@ void HelloService::hello_with_delay(
}

void return_error(coro_rpc::context<std::string> conn) {
conn.response_error(404, "404 Not Found.");
conn.response_error(coro_rpc::err_code{404}, "404 Not Found.");
}
void rpc_with_state_by_tag(coro_rpc::context<std::string> conn) {
if (!conn.tag().has_value()) {
conn.tag() = uint64_t{0};
}
auto &cnter = std::any_cast<uint64_t&>(conn.tag());
auto &cnter = std::any_cast<uint64_t &>(conn.tag());
ELOGV(INFO, "call count: %d", ++cnter);
conn.response_msg(std::to_string(cnter));
}
2 changes: 1 addition & 1 deletion src/coro_rpc/tests/rpc_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct my_context {
};
void echo_with_attachment(coro_rpc::context<void> conn);
inline void error_with_context(coro_rpc::context<void> conn) {
conn.response_error(104, "My Error.");
conn.response_error(coro_rpc::err_code{104}, "My Error.");
}
void coro_fun_with_user_define_connection_type(my_context conn);
void coro_fun_with_delay_return_void(coro_rpc::context<void> conn);
Expand Down

0 comments on commit f2f6da1

Please sign in to comment.