µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
file-descriptors-manager.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2015-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13#ifndef CMSIS_PLUS_POSIX_IO_FILE_DESCRIPTORS_MANAGER_H_
14#define CMSIS_PLUS_POSIX_IO_FILE_DESCRIPTORS_MANAGER_H_
15
16// ----------------------------------------------------------------------------
17
18#if defined(__cplusplus)
19
20// ----------------------------------------------------------------------------
21
22#if defined(OS_USE_OS_APP_CONFIG_H)
23#include <cmsis-plus/os-app-config.h>
24#endif
25
27
28#include <cstddef>
29#include <cassert>
30
31// ----------------------------------------------------------------------------
32
33#pragma GCC diagnostic push
34#if defined(__clang__)
35#pragma clang diagnostic ignored "-Wc++98-compat"
36#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
37#endif
38
39// ----------------------------------------------------------------------------
40
41namespace os
42{
43 namespace posix
44 {
45
46 // ------------------------------------------------------------------------
47
48 class io;
49 class socket;
50
51 // ========================================================================
52
59 {
60 // ----------------------------------------------------------------------
61
67 public:
68
69 file_descriptors_manager (std::size_t size);
70
75 // The rule of five.
79 operator= (const file_descriptors_manager&) = delete;
81 operator= (file_descriptors_manager&&) = delete;
82
88
93 // ----------------------------------------------------------------------
99 public:
100
101 static size_t
102 size (void);
103
104 static bool
105 valid (int fildes);
106
107#pragma GCC diagnostic push
108#if defined(__clang__)
109#elif defined(__GNUC__)
110#pragma GCC diagnostic ignored "-Wredundant-tags"
111#endif
112
113 static class io*
114 io (int fildes);
115
116 static class socket*
117 socket (int fildes);
118
119#pragma GCC diagnostic pop
120
121 static int
122 allocate (class io* io);
123
124 static int
125 assign (file_descriptor_t fildes, class io* io);
126
127 static int
129
130 static size_t
131 used (void);
132
137 // ----------------------------------------------------------------------
138 private:
139
144 // Reserve 0, 1, 2 (stdin, stdout, stderr).
145 static constexpr std::size_t reserved__ = 3;
146
147 static std::size_t size__;
148
149 static class io** descriptors_array__;
150
154 };
155
156 // ==========================================================================
157 } /* namespace posix */
158} /* namespace os */
159
160// ===== Inline & template implementations ====================================
161
162namespace os
163{
164 namespace posix
165 {
166 // ========================================================================
167
168 inline size_t
170 {
171 return size__;
172 }
173
174 // ==========================================================================
175 } /* namespace posix */
176} /* namespace os */
177
178#pragma GCC diagnostic pop
179
180// ----------------------------------------------------------------------------
181
182#endif /* __cplusplus */
183
184// ----------------------------------------------------------------------------
185
186#endif /* CMSIS_PLUS_POSIX_IO_FILE_DESCRIPTORS_MANAGER_H_ */
File descriptors manager static class.
static int deallocate(file_descriptor_t fildes)
static int assign(file_descriptor_t fildes, class io *io)
Base I/O class.
Definition io.h:87
Network socket.
int socket(int domain, int type, int protocol)
int file_descriptor_t
Definition types.h:43
System namespace.