changeset 511:5bab839611f2

Sockets: set dummy to Condition::None
author David Demelier <markand@malikania.fr>
date Thu, 25 Feb 2016 21:01:02 +0100
parents f1749ac790d0
children 0002b8da93dc
files modules/sockets/sockets.h modules/sockets/test/main.cpp
diffstat 2 files changed, 20 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/modules/sockets/sockets.h	Mon Feb 22 20:21:21 2016 +0100
+++ b/modules/sockets/sockets.h	Thu Feb 25 21:01:02 2016 +0100
@@ -867,15 +867,11 @@
 		return Address(&ss, length);
 	}
 
-
-
-
-
 	void connect(const sockaddr *address, socklen_t length, Condition *cond = nullptr)
 	{
 		assert(m_handle != Invalid);
 
-		Condition dummy;
+		Condition dummy = Condition::None;
 
 		reset(cond);
 		m_proto.connect(*this, address, length, cond ? *cond : dummy);
@@ -886,38 +882,23 @@
 		connect(address.address(), address.length(), cond);
 	}
 
-
-
-
-
-
-
-
-
-
-
 	void connect(Condition *cond = nullptr)
 	{
 		assert(m_handle != Invalid);
 
-		Condition dummy;
+		Condition dummy = Condition::None;
 
 		reset(cond);
 		m_proto.connect(*this, cond ? *cond : dummy);
 	}
 
-
-
-
-
-
 	void accept(Socket<Address, Protocol> &client, Address *address = nullptr, Condition *cond = nullptr)
 	{
 		assert(m_handle != Invalid);
 
 		reset(cond);
 
-		Condition dummy;
+		Condition dummy = Condition::None;
 		sockaddr_storage storage;
 		socklen_t length = sizeof (storage);
 
@@ -932,35 +913,17 @@
 	{
 		assert(m_handle != Invalid);
 
-		Condition dummy;
+		Condition dummy = Condition::None;
 
 		reset(cond);
 		m_proto.accept(*this, cond ? *cond : dummy);
 	}
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 	unsigned recv(void *data, unsigned length, Condition *cond = nullptr)
 	{
 		assert(m_handle != Invalid);
 
-		Condition dummy;
+		Condition dummy = Condition::None;
 
 		reset(cond);
 
@@ -980,18 +943,11 @@
 		return result;
 	}
 
-
-
-
-
-
-
-
 	unsigned send(const void *data, unsigned length, Condition *cond = nullptr)
 	{
 		assert(m_handle != Invalid);
 
-		Condition dummy;
+		Condition dummy = Condition::None;
 
 		reset(cond);
 
@@ -1003,20 +959,11 @@
 		return send(data.c_str(), data.length(), cond);
 	}
 
-
-
-
-
-
-
-
-
-
 	unsigned sendto(const void *data, unsigned length, const sockaddr *address, socklen_t addrlen, Condition *cond = nullptr)
 	{
 		assert(m_handle != Invalid);
 
-		Condition dummy;
+		Condition dummy = Condition::None;
 
 		reset(cond);
 
@@ -1033,18 +980,11 @@
 		return sendto(data.c_str(), data.length(), address.address(), address.length(), cond);
 	}
 
-
-
-
-
-
-
-
 	unsigned recvfrom(void *data, unsigned length, sockaddr *address, socklen_t *addrlen, Condition *cond = nullptr)
 	{
 		assert(m_handle != Invalid);
 
-		Condition dummy;
+		Condition dummy = Condition::None;
 
 		reset(cond);
 
@@ -1075,12 +1015,6 @@
 		return result;
 	}
 
-
-
-
-
-
-
 	/**
 	 * Close the socket.
 	 *
@@ -2020,16 +1954,14 @@
 		}
 	}
 
-	template <typename Address, typename Protocol>
-	void doConnect(Socket<Address, Protocol> &sc, Condition &cond)
+	void doConnect(Condition &cond)
 	{
 		wrap("connect", cond, [&] () -> int {
 			return SSL_connect(m_ssl.get());
 		});
 	}
 
-	template <typename Address, typename Protocol>
-	void doAccept(Socket<Address, Protocol> &sc, Condition &cond)
+	void doAccept(Condition &cond)
 	{
 		wrap("accept", cond, [&] () -> int {
 			return SSL_accept(m_ssl.get());
@@ -2133,7 +2065,7 @@
 		/* 2. If the connection is complete (e.g. non-blocking), try handshake */
 		if (cond == Condition::None) {
 			m_tcpconnected = true;
-			doConnect(sc, cond);
+			doConnect(cond);
 		}
 	}
 
@@ -2147,7 +2079,7 @@
 		}
 
 		if (m_tcpconnected)
-			doConnect(sc, cond);
+			doConnect(cond);
 	}
 
 	template <typename Address>
@@ -2168,19 +2100,18 @@
 			SSL_set_fd(proto.m_ssl.get(), client.handle());
 
 			/* 3. Try accept process on the **new** client */
-			proto.doAccept(client, cond);
+			proto.doAccept(cond);
 		}
 	}
 
 	template <typename Address, typename Protocol>
 	inline void accept(Socket<Address, Protocol> &sc, Condition &cond)
 	{
-		doAccept(sc, cond);
+		doAccept(cond);
 	}
 
-
 	template <typename Address>
-	unsigned recv(Socket<Address, Tls> &sc, void *data, unsigned len, Condition &cond)
+	unsigned recv(Socket<Address, Tls> &, void *data, unsigned len, Condition &cond)
 	{
 		int nbread = 0;
 
@@ -2192,7 +2123,7 @@
 	}
 
 	template <typename Address>
-	unsigned send(Socket<Address, Tls> &sc, const void *data, unsigned len, Condition &cond)
+	unsigned send(Socket<Address, Tls> &, const void *data, unsigned len, Condition &cond)
 	{
 		int nbsent = 0;
 
--- a/modules/sockets/test/main.cpp	Mon Feb 22 20:21:21 2016 +0100
+++ b/modules/sockets/test/main.cpp	Thu Feb 25 21:01:02 2016 +0100
@@ -674,15 +674,18 @@
 			m_server.accept(client);
 
 			ASSERT_EQ("hello", client.recv(32));
+
+			std::this_thread::sleep_for(500ms);
 		} catch (const net::Error &ex) {
 			FAIL() << ex.function() << ": " << ex.what();
 		}
 	});
 
-	std::this_thread::sleep_for(250ms);
+	std::this_thread::sleep_for(500ms);
 
 	m_tclient = std::thread([this] () {
 		try {
+			puts("OLOL");
 			m_client.connect(Ipv4("127.0.0.1", 16000));
 			m_client.send("hello");
 		} catch (const net::Error &ex) {