mn_basic_ip4_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_IP4_SOCKET_H__
19 #define __MINILIB_NET_BASIC_IP4_SOCKET_H__
20 
21 #include "../mn_config.hpp"
22 #include "mn_basic_socket.hpp"
24 
25 namespace mn {
26  namespace net {
32  public:
36 
42  basic_ip4_socket(handle_type& hndl, endpoint_type* endp = nullptr) noexcept;
48  basic_ip4_socket(const socket_type& type, const protocol_type& protocol = protocol_type::unspec) noexcept;
52  basic_ip4_socket(const basic_ip4_socket& other) noexcept;
59  basic_ip4_socket& operator=(const basic_ip4_socket& other) noexcept;
60 
69  bool bind(endpoint_type local_ep, bool reuseAddress = false, bool reusePort = false);
80  bool bind(const unsigned int& port, bool reusePort = false);
91  bool bind(ipaddress_type ip, const unsigned int& port, bool reuseAddress = false, bool reusePort = false);
92 
100  endpoint_type* get_endpoint(bool local);
105  endpoint_type* get_local() { return get_endpoint(true); }
110  endpoint_type* get_remote() { return get_endpoint(false); }
111 
118  bool get_peername(endpoint_type& endpoint);
126  bool get_peername(ipaddress_type& ipPeerAddress, uint16_t& iPeerPort);
131  virtual basic_ip_socket* get_copy() { return new basic_ip4_socket(*this); }
132 
133 
134  virtual void swap(basic_ip4_socket& rhs) noexcept {
136  mn::swap(m_pEndPoint, rhs.m_pEndPoint);
137  }
138  protected:
143  };
144  }
145 }
146 
147 #endif // __MINILIB_NET_BASIC_IP4_SOCKET_H__
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
virtual basic_ip_socket * get_copy()
Get a copy of this socket.
Definition: mn_basic_ip4_socket.hpp:131
endpoint_type * get_remote()
Get the remote endpoint.
Definition: mn_basic_ip4_socket.hpp:110
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
bool get_peername(endpoint_type &endpoint)
Get the remote endpoint.
Definition: mn_basic_ip4_socket.cpp:148
endpoint_type * get_local()
Get the local endpoint.
Definition: mn_basic_ip4_socket.hpp:105
virtual void swap(basic_ip4_socket &rhs) noexcept
Definition: mn_basic_ip4_socket.hpp:134
basic_ip4_endpoint endpoint_type
Definition: mn_basic_ip4_socket.hpp:34
basic_ip4_address ipaddress_type
Definition: mn_basic_ip4_socket.hpp:35
endpoint_type * get_endpoint(bool local)
Get the local or remote ip endpoint.
Definition: mn_basic_ip4_socket.cpp:60
endpoint_type * m_pEndPoint
A saved / cached copy of the endpoint on binde the socket.
Definition: mn_basic_ip4_socket.hpp:142
bool bind(endpoint_type local_ep, bool reuseAddress=false, bool reusePort=false)
Bind the socket on the given endpoint (ip and port)
Definition: mn_basic_ip4_socket.cpp:83
typename basic_ip_socket::handle_type handle_type
Definition: mn_basic_ip4_socket.hpp:33
Wrapper class around lwip implementation of a socket.
Definition: mn_basic_socket.hpp:54
virtual void swap(basic_ip_socket &rhs) noexcept
Definition: mn_basic_socket.hpp:136
int handle_type
Definition: mn_basic_socket.hpp:56
struct mn::memory::detail::ptr_difference type
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
Definition: mn_allocator_typetraits.hpp:25
void swap(TAssignable &a, TAssignable &b)
Definition: mn_algorithm.hpp:312