Skip to content

Commit

Permalink
Fix builds against latest spdlog
Browse files Browse the repository at this point in the history
  • Loading branch information
CJLove committed Aug 23, 2021
1 parent af46de6 commit 2abd414
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 11 deletions.
19 changes: 19 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/spdlog_console",
"${workspaceFolder}/spdlog_file",
"${workspaceFolder}/spdlog_udp"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++14",
"configurationProvider": "vector-of-bool.cmake-tools",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}
1 change: 1 addition & 0 deletions .vscode/checks.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"C_Cpp.default.configurationProvider": "go2sh.cmake-integration"
"C_Cpp.default.configurationProvider": "go2sh.cmake-integration",
"clangtidy.buildPath": "${workspaceFolder}/build",
"clangtidy.sourcePath": "${workspaceFolder}/spdlog_udp",
"clangtidy.checksPath": "${workspaceFolder}/.vscode",
}
1 change: 1 addition & 0 deletions spdlog_console/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <spdlog/sinks/stdout_sinks.h>
#include <thread>
#include <chrono>
#include <condition_variable>
#include <iostream>
#include <unistd.h>

Expand Down
1 change: 1 addition & 0 deletions spdlog_file/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <spdlog/sinks/rotating_file_sink.h>
#include <thread>
#include <chrono>
#include <condition_variable>
#include <iostream>
#include <memory>
#include <unistd.h>
Expand Down
4 changes: 2 additions & 2 deletions spdlog_udp/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(int argc, char **argv)
{
int logLevel = spdlog::level::trace;
std::string ipAddr {"127.0.0.1"};
int port = 9000;
uint16_t port = 9000;
int c;
while ((c = getopt(argc, argv, "l:i:p:?")) != EOF)
{
Expand All @@ -101,7 +101,7 @@ int main(int argc, char **argv)
ipAddr = optarg;
break;
case 's':
port = std::stoi(optarg);
port = static_cast<uint16_t>(std::stoi(optarg));
break;
case '?':
usage();
Expand Down
8 changes: 4 additions & 4 deletions spdlog_udp/udp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class udp_client
struct sockaddr_in sockAddr_;
public:

bool init(const std::string &host, int port)
bool init(const std::string &host, uint16_t port)
{
socket_ = socket(PF_INET, SOCK_DGRAM, 0);
if (socket_ < 0)
Expand All @@ -40,7 +40,7 @@ class udp_client
sockAddr_.sin_port = htons(port);
inet_aton(host.c_str(), &sockAddr_.sin_addr);

memset(sockAddr_.sin_zero, 0x00, 8);
memset(sockAddr_.sin_zero, 0x00, sizeof(sockAddr_.sin_zero));
return true;
}

Expand Down Expand Up @@ -72,8 +72,8 @@ class udp_client
// On error close the connection and throw.
void send(const char *data, size_t n_bytes)
{
size_t toslen = 0;
size_t tolen = sizeof(struct sockaddr);
ssize_t toslen = 0;
socklen_t tolen = sizeof(struct sockaddr);
if (( toslen = sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == -1)
{
throw_spdlog_ex("write(2) failed", errno);
Expand Down
7 changes: 5 additions & 2 deletions spdlog_udp/udp_client_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <spdlog/common.h>
#include <spdlog/details/os.h>

#ifdef _WIN32
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
Expand Down Expand Up @@ -65,7 +66,7 @@ class udp_client
return socket_ != INVALID_SOCKET;
}

bool init(const std::string &host, int port)
bool init(const std::string &host, uint16_t port)
{
// initialize winsock if needed
if (!winsock_initialized_())
Expand Down Expand Up @@ -111,4 +112,6 @@ class udp_client
}
};
} // namespace details
} // namespace spdlog
} // namespace spdlog

#endif
4 changes: 2 additions & 2 deletions spdlog_udp/udp_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace sinks {
struct udp_sink_config
{
std::string server_host;
int server_port;
uint16_t server_port;

udp_sink_config(std::string host, int port)
udp_sink_config(std::string host, uint16_t port)
: server_host{std::move(host)}
, server_port{port}
{}
Expand Down

0 comments on commit 2abd414

Please sign in to comment.