aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils/http_util/socket.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-10-03 14:28:35 -0400
committerJack Lloyd <[email protected]>2017-10-03 14:28:35 -0400
commitc7578d6724340bb0403012b8de5e1f52777050f8 (patch)
tree40f36ce1d6ec961c3f458deabcf2468ee9c35873 /src/lib/utils/http_util/socket.h
parent26517eb98af4c3bb1faf38653ab55ae0956578eb (diff)
parent9f11110307c021560fb920447c45103b8423a7ae (diff)
Merge GH #1232 Only require socket code if http_util is loaded
Diffstat (limited to 'src/lib/utils/http_util/socket.h')
-rw-r--r--src/lib/utils/http_util/socket.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/lib/utils/http_util/socket.h b/src/lib/utils/http_util/socket.h
new file mode 100644
index 000000000..78c29f147
--- /dev/null
+++ b/src/lib/utils/http_util/socket.h
@@ -0,0 +1,62 @@
+/*
+* OS specific utility functions
+* (C) 2015,2016,2017 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#ifndef BOTAN_SOCKET_H_
+#define BOTAN_SOCKET_H_
+
+#include <botan/types.h>
+#include <functional>
+
+namespace Botan {
+
+namespace OS {
+
+/*
+* This header is internal (not installed) and these functions are not
+* intended to be called by applications. However they are given public
+* visibility (using BOTAN_TEST_API macro) for the tests. This also probably
+* allows them to be overridden by the application on ELF systems, but
+* this hasn't been tested.
+*/
+
+
+/**
+* A wrapper around a simple blocking TCP socket
+*/
+class BOTAN_TEST_API Socket
+ {
+ public:
+ /**
+ * The socket will be closed upon destruction
+ */
+ virtual ~Socket() {};
+
+ /**
+ * Write to the socket. Blocks until all bytes sent.
+ * Throws on error.
+ */
+ virtual void write(const uint8_t buf[], size_t len) = 0;
+
+ /**
+ * Reads up to len bytes, returns bytes written to buf.
+ * Returns 0 on EOF. Throws on error.
+ */
+ virtual size_t read(uint8_t buf[], size_t len) = 0;
+ };
+
+/**
+* Open up a socket. Will throw on error. Returns null if sockets are
+* not available on this platform.
+*/
+std::unique_ptr<Socket>
+BOTAN_TEST_API open_socket(const std::string& hostname,
+ const std::string& service);
+
+} // OS
+} // Botan
+
+#endif