Skip to content

Commit 8cc4860

Browse files
committed
enh(UDPHandler): use const arguments where reasonable.
1 parent 642a8b9 commit 8cc4860

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

Net/include/Poco/Net/UDPHandler.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
156156
{
157157
if (!_stop)
158158
{
159-
for (auto& buf: _buffers)
159+
for (const auto& buf: _buffers)
160160
{
161161
for (auto* list: buf.second)
162162
{
@@ -200,29 +200,29 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
200200
return _done;
201201
}
202202

203-
void setBusy(char*& pBuf)
203+
void setBusy(char* pBuf)
204204
/// Flags the buffer as busy (usually done before buffer
205205
/// is passed to the reader.
206206
{
207207
setStatus(pBuf, BUF_STATUS_BUSY);
208208
}
209209

210-
void setIdle(char*& pBuf)
210+
void setIdle(char* pBuf)
211211
/// Flags the buffer as idle, ie. not used by reader or
212212
/// waiting to be processed, so ready to be reused for
213213
/// reading.
214214
{
215215
setStatus(pBuf, BUF_STATUS_IDLE);
216216
}
217217

218-
AtomicCounter::ValueType setData(char*& pBuf, MsgSizeT sz)
218+
AtomicCounter::ValueType setData(char* pBuf, MsgSizeT sz)
219219
/// Flags the buffer as containing data.
220220
{
221221
setStatus(pBuf, sz);
222222
return ++_dataBacklog;
223223
}
224224

225-
AtomicCounter::ValueType setError(char*& pBuf, const std::string& err)
225+
AtomicCounter::ValueType setError(char* pBuf, const std::string& err)
226226
/// Sets the error into the buffer.
227227
{
228228
std::size_t availLen = S - sizeof(MsgSizeT);
@@ -237,18 +237,18 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
237237
return --_errorBacklog;
238238
}
239239

240-
bool hasData(char*& pBuf)
240+
bool hasData(const char* pBuf)
241241
/// Returns true if buffer contains data.
242242
{
243243
typename DFMutex::ScopedLock l(_dfMutex);
244244
return payloadSize(pBuf) > 0;
245245
}
246246

247-
bool isError(char*& pBuf)
247+
bool isError(const char* pBuf)
248248
/// Returns true if buffer contains error.
249249
{
250250
typename DFMutex::ScopedLock l(_dfMutex);
251-
return *reinterpret_cast<MsgSizeT*>(pBuf) == BUF_STATUS_ERROR;
251+
return *reinterpret_cast<const MsgSizeT*>(pBuf) == BUF_STATUS_ERROR;
252252
}
253253

254254
static Poco::UInt16 offset()
@@ -257,19 +257,19 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
257257
return sizeof(MsgSizeT) + sizeof(poco_socklen_t) + SocketAddress::MAX_ADDRESS_LENGTH;
258258
}
259259

260-
static MsgSizeT payloadSize(char* buf)
260+
static MsgSizeT payloadSize(const char* buf)
261261
{
262-
return *reinterpret_cast<MsgSizeT*>(buf);
262+
return *reinterpret_cast<const MsgSizeT*>(buf);
263263
}
264264

265-
static SocketAddress address(char* buf)
265+
static SocketAddress address(const char* buf)
266266
{
267-
poco_socklen_t* len = reinterpret_cast<poco_socklen_t*>(buf + sizeof(MsgSizeT));
268-
struct sockaddr* pSA = reinterpret_cast<struct sockaddr*>(buf + sizeof(MsgSizeT) + sizeof(poco_socklen_t));
267+
const auto* len = reinterpret_cast<const poco_socklen_t*>(buf + sizeof(MsgSizeT));
268+
const auto* pSA = reinterpret_cast<const struct sockaddr*>(buf + sizeof(MsgSizeT) + sizeof(poco_socklen_t));
269269
return SocketAddress(pSA, *len);
270270
}
271271

272-
static char* payload(char* buf)
272+
static const char* payload(const char* buf)
273273
/// Returns pointer to payload.
274274
///
275275
/// Total message size is S.
@@ -283,7 +283,7 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
283283
return buf + offset();
284284
}
285285

286-
static Poco::StringTokenizer payload(char* buf, char delimiter)
286+
static Poco::StringTokenizer payload(const char* buf, char delimiter)
287287
/// Returns tokenized payload.
288288
/// Used when multiple logical messages are contained in a
289289
/// single physical message. Messages must be ASCII, as well as
@@ -292,7 +292,7 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
292292
return Poco::StringTokenizer(payload(buf), std::string(1, delimiter), StringTokenizer::TOK_IGNORE_EMPTY);
293293
}
294294

295-
static char* error(char* buf)
295+
static const char* error(const char* buf)
296296
/// Returns pointer to the error message payload.
297297
///
298298
/// Total message size is S.
@@ -339,12 +339,12 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
339339
using BufArray = std::array<char, S>;
340340
using MemPool = Poco::FastMemoryPool<BufArray>;
341341

342-
void setStatusImpl(char*& pBuf, MsgSizeT status)
342+
void setStatusImpl(char* pBuf, MsgSizeT status)
343343
{
344344
*reinterpret_cast<MsgSizeT*>(pBuf) = status;
345345
}
346346

347-
void setStatus(char*& pBuf, MsgSizeT status)
347+
void setStatus(char* pBuf, MsgSizeT status)
348348
{
349349
typename DFMutex::ScopedLock l(_dfMutex);
350350
setStatusImpl(pBuf, status);

0 commit comments

Comments
 (0)