From c29947199dac4dd0dc18d4feea91104963074b97 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 5 Jun 2019 17:00:27 +0300
Subject: [PATCH] Attempt to resolve windows warnings

---
 components/common/cpp/src/configuration.cpp        | 1 +
 components/common/cpp/src/loguru.cpp               | 2 ++
 components/common/cpp/src/uri.cpp                  | 2 +-
 components/net/cpp/include/ftl/net/ws_internal.hpp | 2 +-
 components/net/cpp/src/listener.cpp                | 5 +++--
 components/net/cpp/src/ws_internal.cpp             | 6 +++---
 6 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp
index b2e8c23c7..3f1bcd213 100644
--- a/components/common/cpp/src/configuration.cpp
+++ b/components/common/cpp/src/configuration.cpp
@@ -216,6 +216,7 @@ bool ftl::config::update(const std::string &puri, const json_t &value) {
 	if (cfg) {
 		DLOG(1) << "Updating CFG: " << head << "[" << tail << "] = " << value;
 		cfg->set<json_t>(tail, value);
+		return true;
 	} else {
 		DLOG(1) << "Updating: " << head << "[" << tail << "] = " << value;
 		auto &r = resolve(head, false);
diff --git a/components/common/cpp/src/loguru.cpp b/components/common/cpp/src/loguru.cpp
index ccbc864b4..7e2c748ed 100644
--- a/components/common/cpp/src/loguru.cpp
+++ b/components/common/cpp/src/loguru.cpp
@@ -1,4 +1,5 @@
 // Disable all warnings from gcc/clang:
+#ifdef __GNUC__
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpragmas"
 
@@ -15,6 +16,7 @@
 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
 #pragma GCC diagnostic ignored "-Wunused-macros"
 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
+#endif  // __GNUC__
 
 #define LOGURU_REPLACE_GLOG 1
 #include "loguru.hpp"
diff --git a/components/common/cpp/src/uri.cpp b/components/common/cpp/src/uri.cpp
index 2fcbd86d1..0ecedffc6 100644
--- a/components/common/cpp/src/uri.cpp
+++ b/components/common/cpp/src/uri.cpp
@@ -106,7 +106,7 @@ string URI::to_string() const {
 }
 
 string URI::getPathSegment(int n) const {
-	int N = (n < 0) ? m_pathseg.size()+n : n;
+	size_t N = (n < 0) ? m_pathseg.size()+n : n;
 	if (N < 0 || N >= m_pathseg.size()) return "";
 	else return m_pathseg[N];
 }
diff --git a/components/net/cpp/include/ftl/net/ws_internal.hpp b/components/net/cpp/include/ftl/net/ws_internal.hpp
index 5390f1028..94354b990 100644
--- a/components/net/cpp/include/ftl/net/ws_internal.hpp
+++ b/components/net/cpp/include/ftl/net/ws_internal.hpp
@@ -42,7 +42,7 @@ int ws_dispatch(const char *data, size_t len, std::function<void(const wsheader_
  * Websocket header constructor. Fills a buffer with the correct websocket
  * header for a given opcode, mask setting and message length.
  */
-int ws_prepare(wsheader_type::opcode_type, bool useMask, size_t len, char *buffer, size_t maxlen);
+size_t ws_prepare(wsheader_type::opcode_type, bool useMask, size_t len, char *buffer, size_t maxlen);
 
 bool ws_connect(int sockfd, const ftl::URI &uri);
 
diff --git a/components/net/cpp/src/listener.cpp b/components/net/cpp/src/listener.cpp
index 8e0f1267f..01ab5efa7 100644
--- a/components/net/cpp/src/listener.cpp
+++ b/components/net/cpp/src/listener.cpp
@@ -16,6 +16,7 @@
 #include <arpa/inet.h>
 #define INVALID_SOCKET -1
 #define SOCKET_ERROR -1
+#define SOCKET int
 #endif
 
 #ifdef WIN32
@@ -29,8 +30,8 @@ using std::shared_ptr;
 using ftl::net::Peer;
 using ftl::URI;
 
-int tcpListen(URI &uri) {
-	int ssock;
+SOCKET tcpListen(URI &uri) {
+	SOCKET ssock;
 	//std::cerr << "TCP Listen: " << uri.getHost() << " : " << uri.getPort() << std::endl;
 	#ifdef WIN32
 	WSAData wsaData;
diff --git a/components/net/cpp/src/ws_internal.cpp b/components/net/cpp/src/ws_internal.cpp
index 50e9f8b5e..5c0726de2 100644
--- a/components/net/cpp/src/ws_internal.cpp
+++ b/components/net/cpp/src/ws_internal.cpp
@@ -85,10 +85,10 @@ int ftl::net::ws_dispatch(const char *data, size_t len, std::function<void(const
 
 	// Perform dispatch
 	d(ws, &data[ws.header_size], ws.N);
-	return ws.header_size+ws.N;
+	return (int)(ws.header_size+ws.N);
 }
 
-int ftl::net::ws_prepare(wsheader_type::opcode_type op, bool useMask, size_t len, char *data, size_t maxlen) {
+size_t ftl::net::ws_prepare(wsheader_type::opcode_type op, bool useMask, size_t len, char *data, size_t maxlen) {
 	// TODO:
 	// Masking key should (must) be derived from a high quality random
 	// number generator, to mitigate attacks on non-WebSocket friendly
@@ -158,7 +158,7 @@ bool ftl::net::ws_connect(int sockfd, const URI &uri) {
 	http += "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n";
 	http += "Sec-WebSocket-Version: 13\r\n";
 	http += "\r\n";
-	int rc = ::send(sockfd, http.c_str(), http.length(), 0);
+	int rc = (int)::send(sockfd, http.c_str(), http.length(), 0);
 	if (rc != (int)http.length()) {
 		LOG(ERROR) << "Could not send Websocket http request...";
 		std::cout << http;
-- 
GitLab