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