From b1f59a9ef1e66df08e22968b5bdaae69674ae48e Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 27 Feb 2019 11:13:24 +0200
Subject: [PATCH] Fix for sending raw arrays

---
 net/include/ftl/net/socket.hpp | 16 +++++++++-------
 net/src/listener.cpp           |  2 ++
 net/test/socket_unit.cpp       |  2 +-
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/net/include/ftl/net/socket.hpp b/net/include/ftl/net/socket.hpp
index 96786e4fb..6b0fc7a31 100644
--- a/net/include/ftl/net/socket.hpp
+++ b/net/include/ftl/net/socket.hpp
@@ -39,6 +39,8 @@ struct caller : virtual_caller {
 	std::function<void(const T&)> f_;
 };
 
+typedef std::tuple<const char*,size_t> array;
+
 /**
  * A single socket connection object, to be constructed using the connect()
  * function and not to be created directly.
@@ -140,8 +142,8 @@ class Socket {
 	template <typename... ARGS>
 	int _send(const std::string &t, ARGS... args);
 	
-	template <typename T, typename... ARGS>
-	int _send(const T *t, int s, ARGS... args);
+	template <typename... ARGS>
+	int _send(const array &b, ARGS... args);
 	
 	template <typename T, typename... ARGS>
 	int _send(const std::vector<T> &t, ARGS... args);
@@ -228,11 +230,11 @@ int Socket::_send(const std::string &t, ARGS... args) {
 	return t.size()+_send(args...);
 }
 
-template <typename T, typename... ARGS>
-int Socket::_send(const T *t, int s, ARGS... args) {
-	send_vec_.push_back({const_cast<char*>(t),(size_t)s});
-	header_w_->size += s;
-	return s+_send(args...);
+template <typename... ARGS>
+int Socket::_send(const ftl::net::array &b, ARGS... args) {
+	send_vec_.push_back({const_cast<char*>(std::get<0>(b)),std::get<1>(b)});
+	header_w_->size += std::get<1>(b);
+	return std::get<1>(b)+_send(args...);
 }
 
 template <typename T, typename... ARGS>
diff --git a/net/src/listener.cpp b/net/src/listener.cpp
index 6fd975d1b..0338db14a 100644
--- a/net/src/listener.cpp
+++ b/net/src/listener.cpp
@@ -83,6 +83,8 @@ int tcpListen(URI &uri) {
 		return INVALID_SOCKET;
 	}
 	
+	LOG(INFO) << "Listening on " << uri.getBaseURI();
+	
 	return ssock;
 }
 
diff --git a/net/test/socket_unit.cpp b/net/test/socket_unit.cpp
index 19cd3a0d4..a71bdac2b 100644
--- a/net/test/socket_unit.cpp
+++ b/net/test/socket_unit.cpp
@@ -248,7 +248,7 @@ TEST_CASE("Socket::send()", "[io]") {
 	}
 	
 	SECTION("send const char* array") {
-		s.send(100,"hello world",10);
+		s.send(100,ftl::net::array{"hello world",10});
 		
 		REQUIRE( get_service(0) == 100 );
 		REQUIRE( get_size(0) == 10 );
-- 
GitLab