µ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 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
30
31// ----------------------------------------------------------------------------
32
33#if defined(__clang__)
34#pragma clang diagnostic ignored "-Wc++98-compat"
35#endif
36
37// ----------------------------------------------------------------------------
38
39namespace os
40{
41 namespace posix
42 {
43 // ------------------------------------------------------------------------
44
49#pragma GCC diagnostic push
50#if defined(__clang__)
51#pragma clang diagnostic ignored "-Wexit-time-destructors"
52#pragma clang diagnostic ignored "-Wglobal-constructors"
53#endif
54
55 net_stack::net_list net_stack::net_list__;
56
57#pragma GCC diagnostic pop
58
63 // ------------------------------------------------------------------------
64#pragma GCC diagnostic push
65#pragma GCC diagnostic ignored "-Wunused-parameter"
66// TODO: remove after fixing implementation.
67#pragma GCC diagnostic ignored "-Wnonnull"
68
69 class socket*
70 socket (int domain, int type, int protocol)
71 {
72 errno = 0;
73
74 // TODO: implement a way to identify the net stack.
75 net_stack* ns = nullptr;
76 class socket* sock = ns->socket (domain, type, protocol);
77 if (sock == nullptr)
78 {
79 return nullptr;
80 }
81 sock->alloc_file_descriptor ();
82 return sock;
83 }
84
85#pragma GCC diagnostic pop
86
87 // ========================================================================
88
89 net_stack::net_stack (net_stack_impl& impl, const char* name) :
90 name_ (name), //
91 impl_ (impl)
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 deferred_sockets_list_.clear ();
97 }
98
100 {
101#if defined(OS_TRACE_POSIX_IO_NET_STACK)
102 trace::printf ("net_stack::%s(\"%s\") %p\n", __func__, name_, this);
103#endif
104 }
105
106 class socket*
107 net_stack::socket (int domain, int type, int protocol)
108 {
109 errno = 0;
110
111 return impl ().do_socket (domain, type, protocol);
112 }
113
114 // ========================================================================
115
117 interface_ (interface)
118 {
119#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
120 trace::printf ("net_stack_impl::%s()=%p\n", __func__, this);
121#endif
122 }
123
125 {
126#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
127 trace::printf ("net_stack_impl::%s() @%p\n", __func__, this);
128#endif
129 }
130
131 // ==========================================================================
132 } /* namespace posix */
133} /* namespace os */
134
135// ----------------------------------------------------------------------------
io * alloc_file_descriptor(void)
Definition io.cpp:201
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:92
net_stack(net_stack_impl &impl, const char *name)
Definition net-stack.cpp:89
net_stack_impl & impl(void) const
Definition net-stack.h:476
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:74
int socket(int domain, int type, int protocol)
System namespace.