1616// limitations under the License.
1717
1818#pragma once
19- #ifndef NET_TCP_SOCKET_HPP
20- #define NET_TCP_SOCKET_HPP
19+ #ifndef NET_SOCKET_HPP
20+ #define NET_SOCKET_HPP
2121
22- #include " common .hpp"
22+ #include < net/ip4/addr .hpp>
2323
2424namespace net {
25- namespace tcp {
2625
2726/* *
2827 * An IP address and port
2928 */
3029class Socket {
3130public:
31+
32+ using Address = ip4::Addr;
33+ using port_t = uint16_t ;
34+
35+ struct pair_hash {
36+ std::size_t operator () (const Socket& s) const {
37+ auto h1 = std::hash<Address>{}(s.address ());
38+ auto h2 = std::hash<port_t >{}(s.port ());
39+ return h1 ^ h2;
40+ }
41+ };
42+
3243 /* *
3344 * Constructor
3445 *
3546 * Intialize an empty socket <0.0.0.0:0>
3647 */
3748 constexpr Socket () noexcept
38- : address_{}
39- , port_{}
49+ : address_{}, port_{}
4050 {}
4151
4252 /* *
@@ -51,8 +61,7 @@ class Socket {
5161 * The port associated with the process
5262 */
5363 constexpr Socket (const Address address, const port_t port) noexcept
54- : address_{address}
55- , port_{port}
64+ : address_{address}, port_{port}
5665 {}
5766
5867 /* *
@@ -138,12 +147,37 @@ class Socket {
138147 */
139148 constexpr bool operator >(const Socket& other) const noexcept
140149 { return not (*this < other); }
150+
141151private:
142152 Address address_;
143153 port_t port_;
154+
144155}; // < class Socket
145156
146- } // < namespace tcp
157+ class Quadruple {
158+
159+ public:
160+ Quadruple () noexcept
161+ : source_{}, destination_{}
162+ {}
163+
164+ Quadruple (const Socket::Address src_address, const Socket::port_t src_port,
165+ const Socket::Address dst_address, const Socket::port_t dst_port) noexcept
166+ : source_{src_address, src_port}, destination_{dst_address, dst_port}
167+ {}
168+
169+ const Socket& source () const noexcept
170+ { return source_; }
171+
172+ const Socket& destination () const noexcept
173+ { return destination_; }
174+
175+ private:
176+ Socket source_;
177+ Socket destination_;
178+
179+ }; // < class Quadruple
180+
147181} // < namespace net
148182
149- #endif // < NET_TCP_SOCKET_HPP
183+ #endif // < NET_SOCKET_HPP
0 commit comments