net/SocketDescriptor: use method GetOption() internally

This commit is contained in:
Max Kellermann 2023-11-22 11:58:40 +01:00 committed by Max Kellermann
parent 60033f3eb4
commit 6dc708f53f

View File

@ -191,12 +191,9 @@ SocketDescriptor::CreateSocketPairNonBlock(int domain, int type, int protocol,
int int
SocketDescriptor::GetError() const noexcept SocketDescriptor::GetError() const noexcept
{ {
assert(IsDefined());
int s_err = 0; int s_err = 0;
socklen_t s_err_size = sizeof(s_err); return GetOption(SOL_SOCKET, SO_ERROR,
return getsockopt(fd, SOL_SOCKET, SO_ERROR, &s_err, sizeof(s_err)) == sizeof(s_err)
(char *)&s_err, &s_err_size) == 0
? s_err ? s_err
: errno; : errno;
} }