mn_basic_raw_ip_socket.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2018 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 #ifndef __MINILIB_NET_BASIC_RAW_IP_SOCKET_H__
19 #define __MINILIB_NET_BASIC_RAW_IP_SOCKET_H__
20 
21 #include "../mn_config.hpp"
22 #include "mn_basic_socket.hpp"
23 #include "mn_basic_ip4_socket.hpp"
24 #include "mn_basic_ip6_socket.hpp"
25 
26 namespace mn {
27  namespace net {
28 
34  public:
37 
41 
45 
54  bool connect(endpoint_type remote_ep);
61  bool listen(int backLog = 8);
68  self_type* accept();
69 
78  int send_bytes(const void* buffer, int size, socket_flags socketFlags = socket_flags::none); //
79 
89  int send_bytes(const void* buffer, int offset, int size, socket_flags socketFlags = socket_flags::none); //
90 
91 
101  int send_to(char* buffer, int size, endpoint_type& ep, const socket_flags& socketFlags = socket_flags::none)
102  { return send_to(buffer, 0, size, socketFlags, ep); } //
103 
104 
115  int send_to(char* buffer, int offset, int size, const socket_flags& socketFlags, endpoint_type& ep); //
116 
121  int recive(char* buffer, int size, socket_flags socketFlags = socket_flags::none); //
126  int recive(char* buffer, int offset, int size, socket_flags socketFlags); //
127 
137  int recive_from(char* buffer, int size, endpoint_type* ep, const socket_flags& socketFlags = socket_flags::none)
138  { return recive_from(buffer, 0, size, socketFlags, ep); } //
139 
149  int recive_from(char* buffer, int offset, int size, const socket_flags& socketFlags, endpoint_type* ep); //
150 
151 
152 
157  virtual basic_ip_socket* get_copy() { return new self_type(*this); }
158 
164  void set_broadcast(bool flag) {
166  }
167 
172  bool get_broadcast() {
174  }
175  protected:
177  : base_type(hndl, endp) { }
179  : base_type(socket_type::dgram, protocol) { }
180  };
181 
182 
183 #if MN_THREAD_CONFIG_NET_IPADDRESS6_ENABLE == MN_THREAD_CONFIG_YES
184 
190  public:
193 
197 
201 
210  bool connect(endpoint_type remote_ep);
217  bool listen(int backLog = 8);
224  self_type* accept();
225 
234  int send_bytes(const void* buffer, int size, socket_flags socketFlags = socket_flags::none); //
235 
245  int send_bytes(const void* buffer, int offset, int size, socket_flags socketFlags = socket_flags::none); //
246 
247 
257  int send_to(char* buffer, int size, endpoint_type& ep, const socket_flags& socketFlags = socket_flags::none);
258 
259 
270  int send_to(char* buffer, int offset, int size, const socket_flags& socketFlags, endpoint_type& ep); //
271 
276  int recive(char* buffer, int size, socket_flags socketFlags = socket_flags::none); //
281  int recive(char* buffer, int offset, int size, socket_flags socketFlags); //
282 
292  int recive_from(char* buffer, int size, endpoint_type* ep, const socket_flags& socketFlags = socket_flags::none); //
293 
303  int recive_from(char* buffer, int offset, int size, const socket_flags& socketFlags, endpoint_type* ep); //
304 
305 
306 
311  virtual basic_ip_socket* get_copy() { return new self_type(*this); }
312 
318  void set_broadcast(bool flag) {
320  }
321 
326  bool get_broadcast() {
328  }
329  protected:
331  : base_type(hndl, endp) { }
333  : base_type(socket_type::dgram, protocol) { }
334  };
335 #endif // MN_THREAD_CONFIG_NET_IPADDRESS6_ENABLE
336  }
337 }
338 
339 #endif // __MINILIB_NET_BASIC_RAW_IP_SOCKET_H__
A buffer class that allocates a buffer of a given type and size.
Definition: mn_buffer.hpp:37
This class represents an internet (IP) version 6 host address.
Definition: mn_basic_ip4_address.hpp:38
Definition: mn_basic_ip4_endpoint.hpp:36
This class represents an internet (IP) version 4 host socket.
Definition: mn_basic_ip4_socket.hpp:31
basic_ip4_socket(handle_type &hndl, endpoint_type *endp=nullptr) noexcept
Construct the wrapper class from a given lwip socket handle and the endpoint.
Definition: mn_basic_ip4_socket.cpp:27
basic_ip4_endpoint endpoint_type
Definition: mn_basic_ip4_socket.hpp:34
basic_ip4_address ipaddress_type
Definition: mn_basic_ip4_socket.hpp:35
typename basic_ip_socket::handle_type handle_type
Definition: mn_basic_ip4_socket.hpp:33
This class represents an internet (IP) version 6 host address.
Definition: mn_basic_ip6_address.hpp:49
This class represents an IPv6 endpoint/socket address.
Definition: mn_basic_ip6_endpoint.hpp:41
This class represents an internet (IP) version 6 host socket.
Definition: mn_basic_ip6_socket.hpp:33
basic_ip6_socket(handle_type &hndl, basic_ip6_endpoint *endp=nullptr) noexcept
Construct the wrapper class from a given lwip socket handle and the endpoint.
Definition: mn_basic_ip6_socket.cpp:29
basic_ip6_address ipaddress_type
Definition: mn_basic_ip6_socket.hpp:37
basic_ip6_endpoint endpoint_type
Definition: mn_basic_ip6_socket.hpp:36
typename basic_ip_socket::handle_type handle_type
Definition: mn_basic_ip6_socket.hpp:35
Wrapper class around lwip implementation of a socket.
Definition: mn_basic_socket.hpp:54
int set_options(const socket_option_level &opt, const socket_option_name &name, int value)
Sets the socket option specified by level and option to the given integer value.
Definition: mn_basic_socket.cpp:126
bool get_option_bool(const socket_option_level &opt, const socket_option_name &name)
Get a booles value of a given option.
Definition: mn_basic_socket.cpp:167
This class provides an interface to a raw IPv4 socket.
Definition: mn_basic_raw_ip_socket.hpp:33
basic_raw_ip4_socket self_type
Definition: mn_basic_raw_ip_socket.hpp:35
int recive_from(char *buffer, int size, endpoint_type *ep, const socket_flags &socketFlags=socket_flags::none)
recive a buffer of data
Definition: mn_basic_raw_ip_socket.hpp:137
basic_raw_ip4_socket & operator=(const basic_raw_ip4_socket &other)
Definition: mn_basic_raw_ip_socket.cpp:41
basic_raw_ip4_socket(handle_type &hndl, endpoint_type *endp=nullptr)
Definition: mn_basic_raw_ip_socket.hpp:176
int recive(char *buffer, int size, socket_flags socketFlags=socket_flags::none)
Receives data from the socket and stores it in buffer. Up to length bytes are received.
Definition: mn_basic_raw_ip_socket.cpp:195
typename base_type::endpoint_type endpoint_type
Definition: mn_basic_raw_ip_socket.hpp:38
bool listen(int backLog=8)
Puts the socket into listening state.
Definition: mn_basic_raw_ip_socket.cpp:92
basic_raw_ip4_socket(const protocol_type &protocol)
Definition: mn_basic_raw_ip_socket.hpp:178
virtual basic_ip_socket * get_copy()
Get a copy of this socket.
Definition: mn_basic_raw_ip_socket.hpp:157
void set_broadcast(bool flag)
Sets the value of the SO_BROADCAST socket option.
Definition: mn_basic_raw_ip_socket.hpp:164
bool connect(endpoint_type remote_ep)
Establishes a connection to the stream server at the given address.
Definition: mn_basic_raw_ip_socket.cpp:50
int send_bytes(const void *buffer, int size, socket_flags socketFlags=socket_flags::none)
Sends the contents of the given buffer.
Definition: mn_basic_raw_ip_socket.cpp:126
bool get_broadcast()
Gets the value of the SO_BROADCAST socket option.
Definition: mn_basic_raw_ip_socket.hpp:172
basic_raw_ip4_socket()
Definition: mn_basic_raw_ip_socket.cpp:29
self_type * accept()
Gets the next completed connection from the socket's completed connection queue.
Definition: mn_basic_raw_ip_socket.cpp:71
int send_to(char *buffer, int size, endpoint_type &ep, const socket_flags &socketFlags=socket_flags::none)
send a buffer of data to the given enpoint
Definition: mn_basic_raw_ip_socket.hpp:101
This class provides an interface to a raw IPv6 socket.
Definition: mn_basic_raw_ip_socket.hpp:189
void set_broadcast(bool flag)
Sets the value of the SO_BROADCAST socket option.
Definition: mn_basic_raw_ip_socket.hpp:318
basic_raw_ip6_socket(handle_type &hndl, endpoint_type *endp=nullptr)
Definition: mn_basic_raw_ip_socket.hpp:330
bool connect(endpoint_type remote_ep)
Establishes a connection to the stream server at the given address.
Definition: mn_basic_raw_ip_socket.cpp:264
basic_raw_ip6_socket & operator=(const basic_raw_ip6_socket &other)
Definition: mn_basic_raw_ip_socket.cpp:215
basic_raw_ip6_socket self_type
Definition: mn_basic_raw_ip_socket.hpp:191
virtual basic_ip_socket * get_copy()
Get a copy of this socket.
Definition: mn_basic_raw_ip_socket.hpp:311
self_type * accept()
Gets the next completed connection from the socket's completed connection queue.
Definition: mn_basic_raw_ip_socket.cpp:296
bool listen(int backLog=8)
Puts the socket into listening state.
Definition: mn_basic_raw_ip_socket.cpp:288
basic_raw_ip6_socket()
Definition: mn_basic_raw_ip_socket.cpp:203
int recive(char *buffer, int size, socket_flags socketFlags=socket_flags::none)
Receives data from the socket and stores it in buffer. Up to length bytes are received.
int send_to(char *buffer, int size, endpoint_type &ep, const socket_flags &socketFlags=socket_flags::none)
send a buffer of data to the given enpoint
Definition: mn_basic_raw_ip_socket.cpp:387
bool get_broadcast()
Gets the value of the SO_BROADCAST socket option.
Definition: mn_basic_raw_ip_socket.hpp:326
int recive_from(char *buffer, int size, endpoint_type *ep, const socket_flags &socketFlags=socket_flags::none)
recive a buffer of data
Definition: mn_basic_raw_ip_socket.cpp:353
int send_bytes(const void *buffer, int size, socket_flags socketFlags=socket_flags::none)
Sends the contents of the given buffer.
Definition: mn_basic_raw_ip_socket.cpp:249
basic_raw_ip6_socket(const protocol_type &protocol)
Definition: mn_basic_raw_ip_socket.hpp:332
protocol_type
Defines socket protoco types for creating.
Definition: mn_net_types.hpp:60
socket_type
Defines socket socket types for creating.
Definition: mn_net_types.hpp:99
@ dgram
Socket type for datagram (udp for example)
@ broadcast
Configures a socket for sending broadcast data.
@ socket
options for socket level
socket_flags
Specifies socket send and receive behaviors.
Definition: mn_net_types.hpp:118
@ none
Use no flags for this call.
Definition: mn_allocator_typetraits.hpp:25