µ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++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2015-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#ifndef CMSIS_PLUS_POSIX_IO_FILE_DESCRIPTORS_MANAGER_H_
13#define CMSIS_PLUS_POSIX_IO_FILE_DESCRIPTORS_MANAGER_H_
14
15// ----------------------------------------------------------------------------
16
17#if defined(__cplusplus)
18
19// ----------------------------------------------------------------------------
20
21#if defined(OS_USE_OS_APP_CONFIG_H)
22#include <cmsis-plus/os-app-config.h>
23#endif
24
26
27#include <cstddef>
28#include <cassert>
29
30// ----------------------------------------------------------------------------
31
32#pragma GCC diagnostic push
33#if defined(__clang__)
34#pragma clang diagnostic ignored "-Wc++98-compat"
35#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
36#endif
37
38// ----------------------------------------------------------------------------
39
40namespace os
41{
42 namespace posix
43 {
44
45 // ------------------------------------------------------------------------
46
47 class io;
48 class socket;
49
50 // ========================================================================
51
59 {
60 // ----------------------------------------------------------------------
61
67 public:
68 file_descriptors_manager (std::size_t size);
69
74 // The rule of five.
78 operator= (const file_descriptors_manager&)
79 = delete;
81 operator= (file_descriptors_manager&&)
82 = delete;
83
89
94 // ----------------------------------------------------------------------
100 public:
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:
143 // Reserve 0, 1, 2 (stdin, stdout, stderr).
144 static constexpr std::size_t reserved__ = 3;
145
146 static std::size_t size__;
147
148 static class io** descriptors_array__;
149
153 };
154
155 // ========================================================================
156 } /* namespace posix */
157} /* namespace os */
158
159// ===== Inline & template implementations ====================================
160
161namespace os
162{
163 namespace posix
164 {
165 // ========================================================================
166
167 inline size_t
169 {
170 return size__;
171 }
172
173 // ========================================================================
174 } /* namespace posix */
175} /* namespace os */
176
177#pragma GCC diagnostic pop
178
179// ----------------------------------------------------------------------------
180
181#endif /* __cplusplus */
182
183// ----------------------------------------------------------------------------
184
185#endif /* CMSIS_PLUS_POSIX_IO_FILE_DESCRIPTORS_MANAGER_H_ */
File descriptors manager static class.<cmsis-plus/posix-io/file-descriptors-manager....
static int deallocate(file_descriptor_t fildes)
static int assign(file_descriptor_t fildes, class io *io)
Base I/O class.
Definition io.h:86
Network socket.
int socket(int domain, int type, int protocol)
int file_descriptor_t
Definition types.h:42
System namespace.