@@ -64,7 +64,7 @@ class Sock
64
64
* Get the value of the contained socket.
65
65
* @return socket or INVALID_SOCKET if empty
66
66
*/
67
- virtual SOCKET Get () const ;
67
+ [[nodiscard]] virtual SOCKET Get () const ;
68
68
69
69
/* *
70
70
* Get the value of the contained socket and drop ownership. It will not be closed by the
@@ -82,26 +82,29 @@ class Sock
82
82
* send(2) wrapper. Equivalent to `send(this->Get(), data, len, flags);`. Code that uses this
83
83
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
84
84
*/
85
- virtual ssize_t Send (const void * data, size_t len, int flags) const ;
85
+ [[nodiscard]] virtual ssize_t Send (const void * data, size_t len, int flags) const ;
86
86
87
87
/* *
88
88
* recv(2) wrapper. Equivalent to `recv(this->Get(), buf, len, flags);`. Code that uses this
89
89
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
90
90
*/
91
- virtual ssize_t Recv (void * buf, size_t len, int flags) const ;
91
+ [[nodiscard]] virtual ssize_t Recv (void * buf, size_t len, int flags) const ;
92
92
93
93
/* *
94
94
* connect(2) wrapper. Equivalent to `connect(this->Get(), addr, addrlen)`. Code that uses this
95
95
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
96
96
*/
97
- virtual int Connect (const sockaddr* addr, socklen_t addr_len) const ;
97
+ [[nodiscard]] virtual int Connect (const sockaddr* addr, socklen_t addr_len) const ;
98
98
99
99
/* *
100
100
* getsockopt(2) wrapper. Equivalent to
101
101
* `getsockopt(this->Get(), level, opt_name, opt_val, opt_len)`. Code that uses this
102
102
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
103
103
*/
104
- virtual int GetSockOpt (int level, int opt_name, void * opt_val, socklen_t * opt_len) const ;
104
+ [[nodiscard]] virtual int GetSockOpt (int level,
105
+ int opt_name,
106
+ void * opt_val,
107
+ socklen_t * opt_len) const ;
105
108
106
109
using Event = uint8_t ;
107
110
@@ -124,9 +127,9 @@ class Sock
124
127
* value of `true` and `occurred` being set to 0.
125
128
* @return true on success and false otherwise
126
129
*/
127
- virtual bool Wait (std::chrono::milliseconds timeout,
128
- Event requested,
129
- Event* occurred = nullptr ) const ;
130
+ [[nodiscard]] virtual bool Wait (std::chrono::milliseconds timeout,
131
+ Event requested,
132
+ Event* occurred = nullptr ) const ;
130
133
131
134
/* Higher level, convenience, methods. These may throw. */
132
135
@@ -154,17 +157,17 @@ class Sock
154
157
* @throws std::runtime_error if the operation cannot be completed. In this case some bytes may
155
158
* have been consumed from the socket.
156
159
*/
157
- virtual std::string RecvUntilTerminator (uint8_t terminator,
158
- std::chrono::milliseconds timeout,
159
- CThreadInterrupt& interrupt,
160
- size_t max_data) const ;
160
+ [[nodiscard]] virtual std::string RecvUntilTerminator (uint8_t terminator,
161
+ std::chrono::milliseconds timeout,
162
+ CThreadInterrupt& interrupt,
163
+ size_t max_data) const ;
161
164
162
165
/* *
163
166
* Check if still connected.
164
167
* @param[out] errmsg The error string, if the socket has been disconnected.
165
168
* @return true if connected
166
169
*/
167
- virtual bool IsConnected (std::string& errmsg) const ;
170
+ [[nodiscard]] virtual bool IsConnected (std::string& errmsg) const ;
168
171
169
172
protected:
170
173
/* *
0 commit comments