11// This file is a part of the IncludeOS unikernel - www.includeos.org
22//
3- // Copyright 2015-2016 Oslo and Akershus University College of Applied Sciences
3+ // Copyright 2015-2017 Oslo and Akershus University College of Applied Sciences
44// and Alfred Bratterud
55//
66// Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,60 +25,125 @@ namespace net {
2525namespace tcp {
2626
2727/* *
28- An IP address and a Port.
29- */
28+ * An IP address and port
29+ */
3030class Socket {
3131public:
32- /* * Intialize an empty socket. */
33- Socket () : address_(), port_(0 )
34- { address_.whole = 0 ; }
32+ /* *
33+ * Constructor
34+ *
35+ * Intialize an empty socket <0.0.0.0:0>
36+ */
37+ Socket () noexcept
38+ : address_{}
39+ , port_{}
40+ {}
3541
36- /* * Create a socket with a Address and Port. */
37- Socket (Address address, port_t port)
38- : address_(address), port_(port)
42+ /* *
43+ * Constructor
44+ *
45+ * Create a socket with an address and port
46+ *
47+ * @param address
48+ * The host's network address
49+ *
50+ * @param port
51+ * The port associated with the process
52+ */
53+ Socket (const Address address, const port_t port) noexcept
54+ : address_{address}
55+ , port_{port}
3956 {}
4057
41- /* * Returns the Socket's address. */
42- const Address address () const
58+ /* *
59+ * Get the socket's network address
60+ *
61+ * @return The socket's network address
62+ */
63+ Address address () const noexcept
4364 { return address_; }
4465
45- /* * Returns the Socket's port. */
46- port_t port () const
66+ /* *
67+ * Get the socket's port value
68+ *
69+ * @return The socket's port value
70+ */
71+ port_t port () const noexcept
4772 { return port_; }
4873
49- /* * Returns a string in the format "Address:Port". */
74+ /* *
75+ * Get a string representation of this class
76+ *
77+ * @return A string representation of this class
78+ */
5079 std::string to_string () const
5180 { return address_.str () + " :" + std::to_string (port_); }
5281
53- bool is_empty () const
54- { return (address_ == 0 and port_ == 0 ); }
55-
56- /* * Standard comparators */
57- bool operator ==(const Socket& s2) const
82+ /* *
83+ * Check if this socket is empty <0.0.0.0:0>
84+ *
85+ * @return true if this socket is empty, false otherwise
86+ */
87+ bool is_empty () const noexcept
88+ { return (address_ == 0 ) and (port_ == 0 ); }
89+
90+ /* *
91+ * Operator to check for equality relationship
92+ *
93+ * @param other
94+ * The socket to check for equality relationship
95+ *
96+ * @return true if the specified socket is equal, false otherwise
97+ */
98+ bool operator ==(const Socket& other) const noexcept
5899 {
59- return address () == s2 .address ()
60- and port () == s2 .port ();
100+ return ( address () == other .address () )
101+ and ( port () == other .port () );
61102 }
62103
63- bool operator <(const Socket& s2) const
104+ /* *
105+ * Operator to check for inequality relationship
106+ *
107+ * @param other
108+ * The socket to check for inequality relationship
109+ *
110+ * @return true if the specified socket is not equal, false otherwise
111+ */
112+ bool operator !=(const Socket& other) const noexcept
113+ { return not (*this == other); }
114+
115+ /* *
116+ * Operator to check for less-than relationship
117+ *
118+ * @param other
119+ * The socket to check for less-than relationship
120+ *
121+ * @return true if this socket is less-than the specified socket,
122+ * false otherwise
123+ */
124+ bool operator <(const Socket& other) const noexcept
64125 {
65- return address () < s2 .address ()
66- or (address () == s2 .address () and port () < s2 .port ());
126+ return ( address () < other .address () )
127+ or (( address () == other .address ()) and ( port () < other .port () ));
67128 }
68129
69- bool operator !=(const Socket& s2) const
70- { return !(*this == s2); }
71-
72- bool operator >(const Socket& s2) const
73- { return !(*this < s2); }
74-
130+ /* *
131+ * Operator to check for greater-than relationship
132+ *
133+ * @param other
134+ * The socket to check for greater-than relationship
135+ *
136+ * @return true if this socket is greater-than the specified socket,
137+ * false otherwise
138+ */
139+ bool operator >(const Socket& other) const noexcept
140+ { return not (*this < other); }
75141private:
76142 Address address_;
77- port_t port_;
78-
79- }; // < class Socket
143+ port_t port_;
144+ }; // < class Socket
80145
81- } // < namespace tcp
82- } // < namespace net
146+ } // < namespace tcp
147+ } // < namespace net
83148
84- #endif // < NET_TCP_SOCKET_HPP
149+ #endif // < NET_TCP_SOCKET_HPP
0 commit comments