diff options
author | Jack Lloyd <[email protected]> | 2017-09-03 07:57:41 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-09-03 07:57:41 -0400 |
commit | 20667782f65a9f368c6536c98e22dd49d18175ef (patch) | |
tree | 60e9d38554d07f0013d0c59f7aef5a02d5d9d74f /src/lib/utils/os_utils.h | |
parent | 87f19427dbc3662636a84e56b7c7a8a49f1246df (diff) |
Refactor network code used in http_util
Move the actual socket stuff to os_utils.cpp
Diffstat (limited to 'src/lib/utils/os_utils.h')
-rw-r--r-- | src/lib/utils/os_utils.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/utils/os_utils.h b/src/lib/utils/os_utils.h index cae1192f1..2146e11b3 100644 --- a/src/lib/utils/os_utils.h +++ b/src/lib/utils/os_utils.h @@ -23,6 +23,39 @@ namespace OS { * this hasn't been tested. */ + +/** +* A wrapper around a simple blocking TCP socket +*/ +class BOTAN_DLL 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_DLL open_socket(const std::string& hostname, + const std::string& service); + /** * @return process ID assigned by the operating system. * On Unix and Windows systems, this always returns a result |