Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

socket_udp.h
Go to the documentation of this file.
1 /*
2 * (C) 2015,2016,2017 Jack Lloyd
3 * (C) 2019 Nuno Goncalves <nunojpg@gmail.com>
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_SOCKET_UDP_H_
9 #define BOTAN_SOCKET_UDP_H_
10
11 #include <botan/types.h>
12 #include <string>
13 #include <chrono>
14
15 namespace Botan {
16
17 namespace OS {
18
19 /*
20 * This header is internal (not installed) and these functions are not
21 * intended to be called by applications. However they are given public
22 * visibility (using BOTAN_TEST_API macro) for the tests. This also probably
23 * allows them to be overridden by the application on ELF systems, but
24 * this hasn't been tested.
25 */
26
27
28 /**
29 * A wrapper around a simple blocking UDP socket
30 */
31 class BOTAN_TEST_API SocketUDP
32 {
33 public:
34 /**
35 * The socket will be closed upon destruction
36 */
37 virtual ~SocketUDP() = default;
38
39 /**
40 * Write to the socket. Returns immediately.
41 * Throws on error.
42 */
43 virtual void write(const uint8_t buf[], size_t len) = 0;
44
45 /**
46 * Reads up to len bytes, returns bytes written to buf.
47 * Returns 0 on EOF. Throws on error.
48 */
49 virtual size_t read(uint8_t buf[], size_t len) = 0;
50 };
51
52 /**
53 * Open up a socket. Will throw on error. Returns null if sockets are
54 * not available on this platform.
55 */
56 std::unique_ptr<SocketUDP>
57 BOTAN_TEST_API open_socket_udp(const std::string& hostname,
58 const std::string& service,
59 std::chrono::microseconds timeout);
60
61 /**
62 * Open up a socket. Will throw on error. Returns null if sockets are
63 * not available on this platform.
64 */
65 std::unique_ptr<SocketUDP>
66 BOTAN_TEST_API open_socket_udp(const std::string& uri,
67 std::chrono::microseconds timeout);
68
69
70 } // OS
71 } // Botan
72
73 #endif
Botan::OS::open_socket_udp
std::unique_ptr< SocketUDP > BOTAN_TEST_API open_socket_udp(const std::string &hostname, const std::string &service, std::chrono::microseconds timeout)
Definition: socket_udp.cpp:316
Botan::OS::SocketUDP
Definition: socket_udp.h:31
BOTAN_TEST_API
#define BOTAN_TEST_API
Definition: compiler.h:45
Botan
Definition: alg_id.cpp:13