Skip to content

Commit eebdabe

Browse files
author
Daniel Kang
committed
detail::error -> detail::resval; and it is evaluated as 'true' when there's no error.
1 parent b7fde2b commit eebdabe

File tree

7 files changed

+162
-190
lines changed

7 files changed

+162
-190
lines changed

native/detail/base.h

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ namespace native
5555
else return et_none;
5656
}
5757

58-
class error
58+
class resval
5959
{
6060
public:
61-
error() : err_() {} // default: no error
62-
error(uv_err_t e) : err_(e) {}
63-
error(uv_err_code code) : err_ {code, 0} {}
64-
~error() {}
61+
resval() : err_() {} // default: no error
62+
explicit resval(uv_err_t e) : err_(e) {}
63+
explicit resval(uv_err_code code) : err_ {code, 0} {}
64+
explicit resval(std::nullptr_t) : err_() {}
65+
resval(const resval& c) : err_(c.err_) {}
66+
resval(resval&& c) : err_(std::move(c.err_)) {}
67+
~resval() {}
6568

66-
operator bool() { return err_.code != UV_OK; }
69+
operator bool() { return err_.code == UV_OK; }
6770

6871
uv_err_code code() const { return err_.code; }
6972
const char* name() const { return uv_err_name(err_); }
@@ -79,33 +82,29 @@ namespace native
7982
int port;
8083
};
8184

82-
error get_last_error() { return error(uv_last_error(uv_default_loop())); }
85+
resval get_last_error() { return resval(uv_last_error(uv_default_loop())); }
8386

8487
sockaddr_in to_ip4_addr(const std::string& ip, int port) { return uv_ip4_addr(ip.c_str(), port); }
8588
sockaddr_in6 to_ip6_addr(const std::string& ip, int port) { return uv_ip6_addr(ip.c_str(), port); }
8689

87-
error from_ip4_addr(sockaddr_in* src, std::string& ip, int& port)
90+
resval from_ip4_addr(sockaddr_in* src, std::string& ip, int& port)
8891
{
8992
char dest[16];
90-
if(uv_ip4_name(src, dest, 16) == 0)
91-
{
92-
ip = dest;
93-
port = static_cast<int>(ntohs(src->sin_port));
94-
return error();
95-
}
96-
return get_last_error();
93+
if(uv_ip4_name(src, dest, 16)) get_last_error();
94+
95+
ip = dest;
96+
port = static_cast<int>(ntohs(src->sin_port));
97+
return resval();
9798
}
9899

99-
error from_ip6_addr(sockaddr_in6* src, std::string& ip, int& port)
100+
resval from_ip6_addr(sockaddr_in6* src, std::string& ip, int& port)
100101
{
101102
char dest[46];
102-
if(uv_ip6_name(src, dest, 46) == 0)
103-
{
104-
ip = dest;
105-
port = static_cast<int>(ntohs(src->sin6_port));
106-
return error();
107-
}
108-
return get_last_error();
103+
if(uv_ip6_name(src, dest, 46)) get_last_error();
104+
105+
ip = dest;
106+
port = static_cast<int>(ntohs(src->sin6_port));
107+
return resval();
109108
}
110109

111110
class callback_object_base

0 commit comments

Comments
 (0)