-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsocket.h
More file actions
78 lines (68 loc) · 2.04 KB
/
Copy pathsocket.h
File metadata and controls
78 lines (68 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
////////////////////////////////////////////////////////////////////////////////
// Distributed under the Boost Software License, Version 1.0. //
// (See accompanying file LICENSE or copy at //
// https://www.boost.org/LICENSE_1_0.txt) //
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <cstddef>
#include <optional>
#include "core/data_buffer.h"
namespace iris
{
/**
* Interface for a socket. This is an object that can read and write bytes
* from/to another socket object (possibly on a separate machine).
*/
class Socket
{
public:
// default
virtual ~Socket() = default;
/**
* Try and read count bytes if they are available (this should be a
* non-blocking call).
*
* Note that if not all requested bytes are available it is down to the
* implementation whether this is treated as error or just the bytes
* read are returned.
*
* @param count
* Amount of bytes to read.
*
* @returns
* DataBuffer of bytes if read succeeded, otherwise empty optional.
*/
virtual std::optional<DataBuffer> try_read(std::size_t count) = 0;
/**
* Read count bytes (this should be a blocking call).
*
* Note that if not all requested bytes are available it is down to the
* implementation whether this is treated as error or just the bytes
* read are returned.
*
* @param count
* Amount of bytes to read.
*
* @returns
* DataBuffer of bytes read.
*/
virtual DataBuffer read(std::size_t count) = 0;
/**
* Write DataBuffer to socket.
*
* @param buffer
* Bytes to write.
*/
virtual void write(const DataBuffer &buffer) = 0;
/**
* Write bytes to socket.
*
* @param data
* Pointer to bytes to write.
*
* @param size
* Amount of bytes to write.
*/
virtual void write(const std::byte *data, std::size_t size) = 0;
};
}