mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
tcp_client.h bugfix for macOS and add tcp example
-> fix the issue that the head is not compilable bc. of missing declaration -> optimize if/else block in connection function. Else not needed bc. of break in if
This commit is contained in:
parent
3c527488e7
commit
db0d0438ff
@ -75,7 +75,11 @@ public:
|
|||||||
int last_errno = 0;
|
int last_errno = 0;
|
||||||
for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next)
|
for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next)
|
||||||
{
|
{
|
||||||
int const flags = SOCK_CLOEXEC;
|
#if defined(SOCK_CLOEXEC)
|
||||||
|
const int flags = SOCK_CLOEXEC;
|
||||||
|
#else
|
||||||
|
const int flags = 0;
|
||||||
|
#endif
|
||||||
socket_ = ::socket(rp->ai_family, rp->ai_socktype | flags, rp->ai_protocol);
|
socket_ = ::socket(rp->ai_family, rp->ai_socktype | flags, rp->ai_protocol);
|
||||||
if (socket_ == -1)
|
if (socket_ == -1)
|
||||||
{
|
{
|
||||||
@ -87,12 +91,9 @@ public:
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
last_errno = errno;
|
||||||
{
|
::close(socket_);
|
||||||
last_errno = errno;
|
socket_ = -1;
|
||||||
::close(socket_);
|
|
||||||
socket_ = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
::freeaddrinfo(addrinfo_result);
|
::freeaddrinfo(addrinfo_result);
|
||||||
if (socket_ == -1)
|
if (socket_ == -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user