Fix udp sink on Windows

This commit is contained in:
Chris Love
2021-08-26 06:35:28 -07:00
parent 410e641dff
commit a15f5137ef
3 changed files with 15 additions and 6 deletions

View File

@@ -82,6 +82,15 @@ public:
addr_.sin_family = AF_INET;
addr_.sin_port = htons(port);
InetPton(AF_INET, TEXT(host.c_str()), &addr_.sin_addr.s_addr);
socket_ = socket(PF_INET, SOCK_DGRAM, 0);
if (socket_ == INVALID_SOCKET)
{
int last_error = ::WSAGetLastError();
WSACleanup();
throw_winsock_error_("error: Create Socket failed", last_error);
return false;
}
return true;
}
@@ -104,7 +113,7 @@ public:
void send(const char *data, size_t n_bytes)
{
if ((sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&addr_, sizeof(struct sockaddr))) == -1)
if ((sendto(socket_, data, static_cast<int>(n_bytes), 0, (struct sockaddr *)&addr_, sizeof(struct sockaddr))) == -1)
{
throw_spdlog_ex("sendto(2) failed", errno);
close();

View File

@@ -7,7 +7,7 @@
#include <spdlog/sinks/base_sink.h>
#include <spdlog/details/null_mutex.h>
#ifdef _WIN32
# include <spdlog/details/udp_client_windows.h>
# include <spdlog/details/udp_client-windows.h>
#else
# include <spdlog/details/udp_client.h>
#endif