fpagliughi / sockpp

Modern C++ socket library.
BSD 3-Clause "New" or "Revised" License
782 stars 126 forks source link

Error code from getaddrinfo is lost #19

Closed snej closed 5 years ago

snej commented 5 years ago

In inet_address.cpp:

    if (::getaddrinfo(saddr.c_str(), NULL, &hints, &res) != 0)
        throw sys_error();

getaddrinfo doesn't set errno; it returns an error code instead. So this results in throwing a sys_err with a code of zero, which isn't useful.

Worse, these error codes aren't errno values, they're a different numbering system declared in netdb.h, like EAI_NONAME (8), so putting the error code in the sys_error would be a mistake.

Best solution is probably to create a getaddrinfo_error exception class and throw that...

fpagliughi commented 5 years ago

Fixed by PR #20