From b62c972b30d7a863bdae3553ebc8b47124f9327b Mon Sep 17 00:00:00 2001 From: "HARMEL, Bernard" Date: Mon, 4 Dec 2023 09:42:24 +0100 Subject: [PATCH] code cleanup --- lib/include/bofstd/bofcircularbuffer.h | 8 --- lib/include/bofstd/bofsocket.h | 3 +- lib/include/bofstd/bofsystem.h | 18 +++++++ lib/src/bofhttprequest.cpp | 2 +- lib/src/bofrawcircularbuffer.cpp | 4 -- lib/src/bofsocket.cpp | 72 +++++++++++++++++++------- 6 files changed, 73 insertions(+), 34 deletions(-) diff --git a/lib/include/bofstd/bofcircularbuffer.h b/lib/include/bofstd/bofcircularbuffer.h index 7cdc093..dc473ee 100644 --- a/lib/include/bofstd/bofcircularbuffer.h +++ b/lib/include/bofstd/bofcircularbuffer.h @@ -212,10 +212,6 @@ BofCircularBuffer::BofCircularBuffer(const BOF_CIRCULAR_BUFFER_PARAM & { mErrorCode_E = BOF_ERR_EINVAL; } - if (mpLock_U8 == nullptr) - { - printf("jj"); - } } template @@ -367,10 +363,6 @@ template BOFERR BofCircularBuffer::Push(const DataType *_pData, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pIndexOf_U32, DataType **_ppStorage_X) { BOFERR Rts_E = BOF_ERR_EINVAL; - if (mpLock_U8 == nullptr) - { - printf("jj"); - } if (_pData) { diff --git a/lib/include/bofstd/bofsocket.h b/lib/include/bofstd/bofsocket.h index f53308b..b81c31b 100644 --- a/lib/include/bofstd/bofsocket.h +++ b/lib/include/bofstd/bofsocket.h @@ -184,7 +184,8 @@ class BOFSTD_EXPORT BofSocket : public BofComChannel BOFERR DisableNagle(); - BOFERR SetSocketBufferSize(uint32_t _RcvBufferSize_U32, uint32_t _SndBufferSize_U32); + static BOFERR S_SetSocketBufferSize(BOFSOCKET _Socket, uint32_t &_rRcvBufferSize_U32, uint32_t &_rSndBufferSize_U32); + BOFERR SetSocketBufferSize(uint32_t &_rRcvBufferSize_U32, uint32_t &_rSndBufferSize_U32); BOFERR SetDstIpAddress(BOF_SOCKET_ADDRESS &_rDstIpAddress_X); diff --git a/lib/include/bofstd/bofsystem.h b/lib/include/bofstd/bofsystem.h index 8e1e9f7..38892f0 100644 --- a/lib/include/bofstd/bofsystem.h +++ b/lib/include/bofstd/bofsystem.h @@ -173,6 +173,10 @@ struct BOF_BUFFER } void Reset() { + if (pData_U8) + { + //printf("WARNING: Resetting an 'active' BOF_BUFFER\n"); + } ReleaseStorage(); std::lock_guard Lock(Mtx); Deleter_E = BOF_BUFFER_DELETER_NONE; @@ -306,7 +310,21 @@ struct BOF_BUFFER } return pRts_U8; } + bool Memset(const uint8_t _Val_U8, uint64_t _Size_U64, uint64_t _Offset_U64) + { + bool Rts_B = false; + std::lock_guard Lock(Mtx); + if (IsValid()) + { + if ((_Offset_U64 < Capacity_U64) && ((_Size_U64 + _Offset_U64) < Capacity_U64)) + { + memset(&pData_U8[_Offset_U64], _Val_U8, _Size_U64); + Rts_B = true; + } + } + return Rts_B; + } bool IsValid() { bool Rts_B = false; diff --git a/lib/src/bofhttprequest.cpp b/lib/src/bofhttprequest.cpp index 8fdcf15..20ec1f5 100644 --- a/lib/src/bofhttprequest.cpp +++ b/lib/src/bofhttprequest.cpp @@ -40,7 +40,7 @@ static BOF::BofEnum S_BofHttpRequestTypeEnumConverter( {BOF_HTTP_REQUEST_OPTIONS,"OPTIONS"}, {BOF_HTTP_REQUEST_CONNECT,"CONNECT"}, {BOF_HTTP_REQUEST_TRACE, "TRACE"}, - {BOF_HTTP_REQUEST_DBG_ECHO, "DBGECHO89ABCDEF"}, //No _ and must be (LWS_PRE-1) long for lws optim + {BOF_HTTP_REQUEST_DBG_ECHO, "DBG_ECHO"}, }, BOF_HTTP_REQUEST_UNKNOWN); diff --git a/lib/src/bofrawcircularbuffer.cpp b/lib/src/bofrawcircularbuffer.cpp index 0c74a1b..c9e6a60 100644 --- a/lib/src/bofrawcircularbuffer.cpp +++ b/lib/src/bofrawcircularbuffer.cpp @@ -90,10 +90,6 @@ BofRawCircularBuffer::BofRawCircularBuffer(const BOF_RAW_CIRCULAR_BUFFER_PARAM & } } } - if (mpCrtBufferEnd_U8 == nullptr) - { - printf("jj"); - } } BofRawCircularBuffer::~BofRawCircularBuffer() diff --git a/lib/src/bofsocket.cpp b/lib/src/bofsocket.cpp index b5b81a4..03dc2e7 100644 --- a/lib/src/bofsocket.cpp +++ b/lib/src/bofsocket.cpp @@ -742,65 +742,97 @@ bool BofSocket::IsBlocking() * Remarks * By default Udp socket are limitted to 8 KB */ -BOFERR BofSocket::SetSocketBufferSize(uint32_t _RcvBufferSize_U32, uint32_t _SndBufferSize_U32) +BOFERR BofSocket::S_SetSocketBufferSize(BOFSOCKET _Socket, uint32_t &_rRcvBufferSize_U32, uint32_t &_rSndBufferSize_U32) { BOFERR Rts_E = BOF_ERR_NO_ERROR; uint32_t Val_U32; socklen_t Len_i; int Sts_i; - if (_RcvBufferSize_U32) + if (_rRcvBufferSize_U32) { Len_i = sizeof(uint32_t); - Val_U32 = _RcvBufferSize_U32; + Val_U32 = _rRcvBufferSize_U32; // Sets the maximum socket receive buffer in bytes. The kernel double this // value when it is set using setsockopt(2), and this doubled value is // returned by the /proc/sys/net/core/rmem_default file, and the maximum // allowed value is set by the /proc/sys/net/core/rmem_max file. The minimum // (doubled) value for this option is 256. - Sts_i = setsockopt(mSocket, SOL_SOCKET, SO_RCVBUF, (char *)&Val_U32, Len_i); + Sts_i = setsockopt(_Socket, SOL_SOCKET, SO_RCVBUF, (char *)&Val_U32, Len_i); if (Sts_i) { Rts_E = BOF_ERR_TOO_BIG; } else { - Sts_i = getsockopt(mSocket, SOL_SOCKET, SO_RCVBUF, (char *)&Val_U32, &Len_i); - if ((Sts_i) || (Val_U32 < _RcvBufferSize_U32)) + Sts_i = getsockopt(_Socket, SOL_SOCKET, SO_RCVBUF, (char *)&Val_U32, &Len_i); + if ((Sts_i) || (Val_U32 < _rRcvBufferSize_U32)) { Rts_E = BOF_ERR_OUT_OF_RANGE; } } } - - if ((Rts_E == BOF_ERR_NO_ERROR) && (_SndBufferSize_U32)) + else { Len_i = sizeof(uint32_t); - Val_U32 = _SndBufferSize_U32; - - // Sets the maximum socket send buffer in bytes. The kernel double this - // value when it is set using setsockopt(2), and this doubled value is - // returned by the /proc/sys/net/core/wmem_default file, and the maximum - // allowed value is set by the /proc/sys/net/core/wmem_max file. The minimum - // (doubled) value for this option is 2048. - Sts_i = setsockopt(mSocket, SOL_SOCKET, SO_SNDBUF, (char *)&Val_U32, Len_i); + Sts_i = getsockopt(_Socket, SOL_SOCKET, SO_RCVBUF, (char *)&Val_U32, &Len_i); if (Sts_i) { - Rts_E = BOF_ERR_TOO_BIG; + Rts_E = BOF_ERR_OPERATION_FAILED; } else { - Sts_i = getsockopt(mSocket, SOL_SOCKET, SO_SNDBUF, (char *)&Val_U32, &Len_i); - if ((Sts_i) || (Val_U32 < _SndBufferSize_U32)) + _rRcvBufferSize_U32 = Val_U32; + } + } + if (Rts_E == BOF_ERR_NO_ERROR) + { + if (_rSndBufferSize_U32) + { + Len_i = sizeof(uint32_t); + Val_U32 = _rSndBufferSize_U32; + + // Sets the maximum socket send buffer in bytes. The kernel double this + // value when it is set using setsockopt(2), and this doubled value is + // returned by the /proc/sys/net/core/wmem_default file, and the maximum + // allowed value is set by the /proc/sys/net/core/wmem_max file. The minimum + // (doubled) value for this option is 2048. + Sts_i = setsockopt(_Socket, SOL_SOCKET, SO_SNDBUF, (char *)&Val_U32, Len_i); + if (Sts_i) { - Rts_E = BOF_ERR_OUT_OF_RANGE; + Rts_E = BOF_ERR_TOO_BIG; + } + else + { + Sts_i = getsockopt(_Socket, SOL_SOCKET, SO_SNDBUF, (char *)&Val_U32, &Len_i); + if ((Sts_i) || (Val_U32 < _rSndBufferSize_U32)) + { + Rts_E = BOF_ERR_OUT_OF_RANGE; + } + } + } + else + { + Len_i = sizeof(uint32_t); + Sts_i = getsockopt(_Socket, SOL_SOCKET, SO_SNDBUF, (char *)&Val_U32, &Len_i); + if (Sts_i) + { + Rts_E = BOF_ERR_OPERATION_FAILED; + } + else + { + _rSndBufferSize_U32 = Val_U32; } } } return Rts_E; } +BOFERR BofSocket::SetSocketBufferSize(uint32_t &_rRcvBufferSize_U32, uint32_t &_rSndBufferSize_U32) +{ + return BofSocket::S_SetSocketBufferSize(mSocket, _rRcvBufferSize_U32, _rSndBufferSize_U32); +} BOFERR BofSocket::DisableNagle() {