Botan 3.6.1
Crypto and TLS for C&
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 <chrono>
13#include <string>
14
15namespace Botan::OS {
16
17/*
18* This header is internal (not installed) and these functions are not
19* intended to be called by applications. However they are given public
20* visibility (using BOTAN_TEST_API macro) for the tests. This also probably
21* allows them to be overridden by the application on ELF systems, but
22* this hasn't been tested.
23*/
24
25/**
26* A wrapper around a simple blocking UDP socket
27*/
29 public:
30 /**
31 * The socket will be closed upon destruction
32 */
33 virtual ~SocketUDP() = default;
34
35 /**
36 * Write to the socket. Returns immediately.
37 * Throws on error.
38 */
39 virtual void write(const uint8_t buf[], size_t len) = 0;
40
41 /**
42 * Reads up to len bytes, returns bytes written to buf.
43 * Returns 0 on EOF. Throws on error.
44 */
45 virtual size_t read(uint8_t buf[], size_t len) = 0;
46};
47
48/**
49* Open up a socket. Will throw on error. Returns null if sockets are
50* not available on this platform.
51*/
52std::unique_ptr<SocketUDP> BOTAN_TEST_API open_socket_udp(std::string_view hostname,
53 std::string_view service,
54 std::chrono::microseconds timeout);
55
56/**
57* Open up a socket. Will throw on error. Returns null if sockets are
58* not available on this platform.
59*/
60std::unique_ptr<SocketUDP> BOTAN_TEST_API open_socket_udp(std::string_view uri, std::chrono::microseconds timeout);
61
62} // namespace Botan::OS
63
64#endif
virtual ~SocketUDP()=default
virtual size_t read(uint8_t buf[], size_t len)=0
virtual void write(const uint8_t buf[], size_t len)=0
#define BOTAN_TEST_API
Definition compiler.h:51
std::unique_ptr< SocketUDP > BOTAN_TEST_API open_socket_udp(std::string_view hostname, std::string_view service, std::chrono::microseconds timeout)