diff C++/SocketTcp.h @ 316:4c0af1143fc4

Add wait operation (no tests yet)
author David Demelier <markand@malikania.fr>
date Tue, 03 Mar 2015 18:48:54 +0100
parents c9356cb38c86
children 68ae6d7dea1f
line wrap: on
line diff
--- a/C++/SocketTcp.h	Mon Mar 02 14:00:48 2015 +0100
+++ b/C++/SocketTcp.h	Tue Mar 03 18:48:54 2015 +0100
@@ -47,14 +47,34 @@
 		return result;
 	}
 
+	inline std::string waitRecv(unsigned count, int timeout)
+	{
+		std::string result;
+
+		result.resize(count);
+		auto n = waitRecv(const_cast<char *>(result.data()), count, timeout);
+		result.resize(n);
+
+		return result;
+	}
+
 	inline unsigned send(const std::string &data)
 	{
 		return send(data.c_str(), data.size());
 	}
 
+	inline unsigned waitSend(const std::string &data, int timeout)
+	{
+		return waitSend(data.c_str(), data.size(), timeout);
+	}
+
 	virtual unsigned recv(void *data, unsigned length) = 0;
 
+	virtual unsigned waitRecv(void *data, unsigned length, int timeout) = 0;
+
 	virtual unsigned send(const void *data, unsigned length) = 0;
+
+	virtual unsigned waitSend(const void *data, unsigned length, int timeout) = 0;
 };
 
 /**
@@ -71,11 +91,21 @@
 
 	SocketTcp accept(SocketAddress &info);
 
+	SocketTcp waitAccept(int timeout);
+
+	SocketTcp waitAccept(SocketAddress &info, int timeout);
+
 	void connect(const SocketAddress &address);
 
+	void waitConnect(const SocketAddress &address, int timeout);
+
 	unsigned recv(void *data, unsigned length) override;
 
+	unsigned waitRecv(void *data, unsigned length, int timeout) override;
+
 	unsigned send(const void *data, unsigned length) override;
+
+	unsigned waitSend(const void *data, unsigned length, int timeout) override;
 };
 
 #endif // !_SOCKET_TCP_NG_3_H_