mn_basic_stream_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_BASIC_STREAM_IP_SOCKET_H__
19 #define __MINILIB_BASIC_STREAM_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 {
33  public:
36 
40 
43 
44 
53  bool connect(endpoint_type remote_ep);
60  bool listen(int backLog = 8);
61 
68  self_type* accept();
69 
74  int recive(char* buffer, int size, socket_flags socketFlags = socket_flags::none)
75  { return recive(buffer, 0, size, socketFlags); }
80  int recive(char* buffer, int offset, int size, socket_flags socketFlags);
81 
90  int send_bytes(const void* buffer, int size, socket_flags socketFlags = socket_flags::none);
91 
101  int send_bytes(const void* buffer, int offset, int size, socket_flags socketFlags = socket_flags::none);
102 
103 
104 
105  protected:
107  : base_type(hndl, endp) { }
109  : base_type(socket_type::dgram, protocol) { }
110 
111  };
112 
113  #if MN_THREAD_CONFIG_NET_IPADDRESS6_ENABLE == MN_THREAD_CONFIG_YES
119  public:
122 
126 
129 
138  bool connect(endpoint_type remote_ep);
145  bool listen(int backLog = 8);
146 
153  self_type* accept();
154 
159  int recive(char* buffer, int size, socket_flags socketFlags = socket_flags::none)
160  { return recive(buffer, 0, size, socketFlags); }
165  int recive(char* buffer, int offset, int size, socket_flags socketFlags);
166 
175  int send_bytes(const void* buffer, int size, socket_flags socketFlags = socket_flags::none);
176 
186  int send_bytes(const void* buffer, int offset, int size, socket_flags socketFlags = socket_flags::none);
187 
188 
189  protected:
191  : base_type(hndl, endp) { }
193  : base_type(socket_type::dgram, protocol) { }
194  };
195  #endif // MN_THREAD_CONFIG_NET_IPADDRESS6_ENABLE
196  }
197 }
198 
199 #endif // __MINILIB_BASIC_STREAM_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
This class provides an interface to a tcp IPv6 socket.
Definition: mn_basic_stream_ip_socket.hpp:118
basic_stream_ip6_socket self_type
Definition: mn_basic_stream_ip_socket.hpp:120
bool listen(int backLog=8)
Puts the socket into listening state.
Definition: mn_basic_stream_ip_socket.cpp:189
bool connect(endpoint_type remote_ep)
Establishes a connection to the stream server at the given address.
Definition: mn_basic_stream_ip_socket.cpp:165
basic_stream_ip6_socket(handle_type &hndl, endpoint_type *endp=nullptr)
Definition: mn_basic_stream_ip_socket.hpp:190
basic_stream_ip6_socket(const protocol_type &protocol)
Definition: mn_basic_stream_ip_socket.hpp:192
self_type * accept()
Gets the next completed connection from the socket's completed connection queue.
Definition: mn_basic_stream_ip_socket.cpp:197
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_stream_ip_socket.hpp:159
typename base_type::endpoint_type endpoint_type
Definition: mn_basic_stream_ip_socket.hpp:123
basic_stream_ip6_socket()
Definition: mn_basic_stream_ip_socket.hpp:127
int send_bytes(const void *buffer, int size, socket_flags socketFlags=socket_flags::none)
Sends the contents of the given buffer.
Definition: mn_basic_stream_ip_socket.cpp:150
This class provides an interface to a tcp IPv4 socket.
Definition: mn_basic_stream_ip_socket.hpp:32
basic_stream_ip_socket self_type
Definition: mn_basic_stream_ip_socket.hpp:34
int send_bytes(const void *buffer, int size, socket_flags socketFlags=socket_flags::none)
Sends the contents of the given buffer.
Definition: mn_basic_stream_ip_socket.cpp:57
basic_stream_ip_socket()
Definition: mn_basic_stream_ip_socket.hpp:41
bool connect(endpoint_type remote_ep)
Establishes a connection to the stream server at the given address.
Definition: mn_basic_stream_ip_socket.cpp:73
bool listen(int backLog=8)
Puts the socket into listening state.
Definition: mn_basic_stream_ip_socket.cpp:94
typename base_type::endpoint_type endpoint_type
Definition: mn_basic_stream_ip_socket.hpp:37
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_stream_ip_socket.hpp:74
self_type * accept()
Gets the next completed connection from the socket's completed connection queue.
Definition: mn_basic_stream_ip_socket.cpp:102
basic_stream_ip_socket(const protocol_type &protocol)
Definition: mn_basic_stream_ip_socket.hpp:108
basic_stream_ip_socket(handle_type &hndl, endpoint_type *endp=nullptr)
Definition: mn_basic_stream_ip_socket.hpp:106
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
@ stream
Socket type for stream (tcp)
@ dgram
Socket type for datagram (udp for example)
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