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