Explicitly set SO_SNDBUF size to fix drops on Windows and address other PR feedback
This commit is contained in:
parent
2d1217006b
commit
497fa60f57
@ -26,6 +26,7 @@ namespace spdlog {
|
|||||||
namespace details {
|
namespace details {
|
||||||
class udp_client
|
class udp_client
|
||||||
{
|
{
|
||||||
|
const int TX_BUFFER_SIZE = 10240;
|
||||||
SOCKET socket_ = INVALID_SOCKET;
|
SOCKET socket_ = INVALID_SOCKET;
|
||||||
sockaddr_in addr_ = { 0 };
|
sockaddr_in addr_ = { 0 };
|
||||||
|
|
||||||
@ -92,8 +93,16 @@ public:
|
|||||||
int last_error = ::WSAGetLastError();
|
int last_error = ::WSAGetLastError();
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
throw_winsock_error_("error: Create Socket failed", last_error);
|
throw_winsock_error_("error: Create Socket failed", last_error);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int option_value = TX_BUFFER_SIZE;
|
||||||
|
if (setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, (char*)&option_value, sizeof(option_value)) < 0)
|
||||||
|
{
|
||||||
|
int last_error = ::WSAGetLastError();
|
||||||
|
close();
|
||||||
|
throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +128,8 @@ public:
|
|||||||
socklen_t tolen = sizeof(struct sockaddr);
|
socklen_t tolen = sizeof(struct sockaddr);
|
||||||
if (sendto(socket_, data, static_cast<int>(n_bytes), 0, (struct sockaddr *)&addr_, tolen) == -1)
|
if (sendto(socket_, data, static_cast<int>(n_bytes), 0, (struct sockaddr *)&addr_, tolen) == -1)
|
||||||
{
|
{
|
||||||
throw_spdlog_ex("sendto(2) failed", errno);
|
|
||||||
close();
|
close();
|
||||||
|
throw_spdlog_ex("sendto(2) failed", errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -21,8 +21,10 @@
|
|||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
class udp_client
|
class udp_client
|
||||||
{
|
{
|
||||||
|
const int TX_BUFFER_SIZE = 10240;
|
||||||
int socket_ = -1;
|
int socket_ = -1;
|
||||||
struct sockaddr_in sockAddr_;
|
struct sockaddr_in sockAddr_;
|
||||||
public:
|
public:
|
||||||
@ -33,7 +35,13 @@ public:
|
|||||||
if (socket_ < 0)
|
if (socket_ < 0)
|
||||||
{
|
{
|
||||||
throw_spdlog_ex("error: Create Socket Failed!");
|
throw_spdlog_ex("error: Create Socket Failed!");
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
int option_value = TX_BUFFER_SIZE;
|
||||||
|
if (setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, (char*)&option_value, sizeof(option_value)) < 0)
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
sockAddr_.sin_family = AF_INET;
|
sockAddr_.sin_family = AF_INET;
|
||||||
@ -76,8 +84,8 @@ public:
|
|||||||
socklen_t tolen = sizeof(struct sockaddr);
|
socklen_t tolen = sizeof(struct sockaddr);
|
||||||
if (( toslen = sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == -1)
|
if (( toslen = sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == -1)
|
||||||
{
|
{
|
||||||
throw_spdlog_ex("sendto(2) failed", errno);
|
|
||||||
close();
|
close();
|
||||||
|
throw_spdlog_ex("sendto(2) failed", errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
explicit udp_sink(udp_sink_config sink_config)
|
explicit udp_sink(udp_sink_config sink_config)
|
||||||
: config_{std::move(sink_config)}
|
: config_{std::move(sink_config)}
|
||||||
{
|
{
|
||||||
|
client_.init(config_.server_host, config_.server_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
~udp_sink() override = default;
|
~udp_sink() override = default;
|
||||||
|
Loading…
Reference in New Issue
Block a user