运行时出现 Operation aborted
Closed this issue · 1 comments
Cai-Yao commented
client
using namespace rest_rpc;
using namespace rest_rpc::rpc_service;
rpc_client client("127.0.0.1", 9123);
void test_add() {
try {
bool r = client.connect();
if (!r) {
std::cout << "connect timeout" << std::endl;
return;
}
{
auto result = client.call<int>("add", 2, 3);
printf("result: %d\n", result);
}
}
catch (const std::exception & e) {
std::cout << e.what() << std::endl;
}
}
int main()
{
long long start_time = getCurrentPreciseTime();
test_add();
long long end_time = getCurrentPreciseTime();
printf("read cost %lld\n", end_time - start_time);
return 0;
}
server
struct dummy{
int add(rpc_conn conn, int a, int b) {
auto shared_conn = conn.lock();
// if (shared_conn) {
// shared_conn->set_user_data(std::string("aa"));
// auto s = conn.lock()->get_user_data<std::string>();
// std::cout << s << '\n'; //aa
// }
int res = 0;
for (int i = 0; i < 100000; ++i) {
res = (res + i + b + a) % 100000;
}
return a + b;
}
};
int main() {
rpc_server server(9123, std::thread::hardware_concurrency());
dummy d;
server.register_handler("add", &dummy::add, &d);
server.run();
return 0;
result
result: 5
Operation aborted.
请问这个报错应该怎么消除
qicosmos commented
这个提示是正常的,你调用了一次call完成之后client析构了,析构的时候会把socket关掉,这时候会提示一个socket读错误就是Operation aborted.