summaryrefslogtreecommitdiff
path: root/src/io/io_helpers.h
blob: 94e37f4bb17fc2439f1a3330e7a54332c01e3944 (plain)
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
#pragma once

#include <forstio/async/async.h>
#include <forstio/core/common.h>

#include <cstdint>
#include <optional>

namespace saw {
/*
 * Helper classes for the specific driver implementations
 */

/*
 * Since I don't want to repeat these implementations for tls on unix systems
 * and gnutls doesn't let me write or read into buffers I have to have this kind
 * of strange abstraction. This may also be reusable for windows/macOS though.
 */
class input_stream;

class read_task_and_step_helper {
public:
	struct read_io_task {
		void *buffer;
		size_t min_length;
		size_t max_length;
		size_t already_read = 0;
	};
	std::optional<read_io_task> read_task;
	own<conveyor_feeder<size_t>> read_done = nullptr;

	own<conveyor_feeder<void>> on_read_disconnect = nullptr;

public:
	void read_step(input_stream &reader);
};

class output_stream;

class write_task_and_step_helper {
public:
	struct write_io_task {
		const void *buffer;
		size_t length;
		size_t already_written = 0;
	};
	std::optional<write_io_task> write_task;
	own<conveyor_feeder<size_t>> write_done = nullptr;

public:
	void write_step(output_stream &writer);
};
} // namespace saw