µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
net-stack.cpp
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#if defined(OS_USE_OS_APP_CONFIG_H)
13#include <cmsis-plus/os-app-config.h>
14#endif
15
18
19// ----------------------------------------------------------------------------
20
21#if defined(__clang__)
22#pragma clang diagnostic ignored "-Wc++98-compat"
23#endif
24
25// ----------------------------------------------------------------------------
26
27namespace os
28{
29 namespace posix
30 {
31 // ------------------------------------------------------------------------
32
37#pragma GCC diagnostic push
38#if defined(__clang__)
39#pragma clang diagnostic ignored "-Wexit-time-destructors"
40#pragma clang diagnostic ignored "-Wglobal-constructors"
41#endif
42
43 net_stack::net_list net_stack::net_list__;
44
45#pragma GCC diagnostic pop
46
51 // ------------------------------------------------------------------------
52#pragma GCC diagnostic push
53#if defined(__clang__)
54#elif defined(__GNUC__)
55#pragma GCC diagnostic ignored "-Wunused-parameter"
56#endif
57// TODO: remove after fixing implementation.
58#pragma GCC diagnostic ignored "-Wnonnull"
59#pragma GCC diagnostic ignored "-Wnull-dereference"
60
61 class socket*
62 socket (int domain, int type, int protocol)
63 {
64 errno = 0;
65
66 // TODO: implement a way to identify the net stack.
67 net_stack* ns = nullptr;
68 class socket* sock = ns->socket (domain, type, protocol);
69 if (sock == nullptr)
70 {
71 return nullptr;
72 }
73 sock->alloc_file_descriptor ();
74 return sock;
75 }
76
77#pragma GCC diagnostic pop
78
79 // ========================================================================
80
81 net_stack::net_stack (net_stack_impl& impl, const char* name)
82 : name_ (name), //
83 impl_ (impl)
84 {
85#if defined(OS_TRACE_POSIX_IO_NET_STACK)
86 trace::printf ("net_stack::%s(\"%s\")=%p\n", __func__, name_, this);
87#endif
88 deferred_sockets_list_.clear ();
89 }
90
92 {
93#if defined(OS_TRACE_POSIX_IO_NET_STACK)
94 trace::printf ("net_stack::%s(\"%s\") %p\n", __func__, name_, this);
95#endif
96 }
97
98#pragma GCC diagnostic push
99#if defined(__clang__)
100#elif defined(__GNUC__)
101#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
102#endif
103 class socket*
104 net_stack::socket (int domain, int type, int protocol)
105 {
106 errno = 0;
107
108 return impl ().do_socket (domain, type, protocol);
109 }
110#pragma GCC diagnostic pop
111
112 // ========================================================================
113
115 : interface_ (interface)
116 {
117#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
118 trace::printf ("net_stack_impl::%s()=%p\n", __func__, this);
119#endif
120 }
121
123 {
124#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
125 trace::printf ("net_stack_impl::%s() @%p\n", __func__, this);
126#endif
127 }
128
129 // ========================================================================
130 } /* namespace posix */
131} /* namespace os */
132
133// ----------------------------------------------------------------------------
io * alloc_file_descriptor(void)
Definition io.cpp:189
Network interface class.
virtual class socket * do_socket(int domain, int type, int protocol)=0
net_stack_impl(net_interface &interface)
Network stack class.
Definition net-stack.h:81
net_stack(net_stack_impl &impl, const char *name)
Definition net-stack.cpp:81
net_stack_impl & impl(void) const
Definition net-stack.h:456
virtual class socket * socket(int domain, int type, int protocol)
Network socket.
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
int socket(int domain, int type, int protocol)
System namespace.