Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bha-evs committed Dec 4, 2023
1 parent 0b6bc42 commit b62c972
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 34 deletions.
8 changes: 0 additions & 8 deletions lib/include/bofstd/bofcircularbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ BofCircularBuffer<DataType>::BofCircularBuffer(const BOF_CIRCULAR_BUFFER_PARAM &
{
mErrorCode_E = BOF_ERR_EINVAL;
}
if (mpLock_U8 == nullptr)
{
printf("jj");
}
}

template <typename DataType>
Expand Down Expand Up @@ -367,10 +363,6 @@ template <typename DataType>
BOFERR BofCircularBuffer<DataType>::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)
{
Expand Down
3 changes: 2 additions & 1 deletion lib/include/bofstd/bofsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 18 additions & 0 deletions lib/include/bofstd/bofsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ struct BOF_BUFFER
}
void Reset()
{
if (pData_U8)
{
//printf("WARNING: Resetting an 'active' BOF_BUFFER\n");
}
ReleaseStorage();
std::lock_guard<std::mutex> Lock(Mtx);
Deleter_E = BOF_BUFFER_DELETER_NONE;
Expand Down Expand Up @@ -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<std::mutex> 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;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bofhttprequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static BOF::BofEnum<BOF_HTTP_REQUEST_TYPE> 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);

Expand Down
4 changes: 0 additions & 4 deletions lib/src/bofrawcircularbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ BofRawCircularBuffer::BofRawCircularBuffer(const BOF_RAW_CIRCULAR_BUFFER_PARAM &
}
}
}
if (mpCrtBufferEnd_U8 == nullptr)
{
printf("jj");
}
}

BofRawCircularBuffer::~BofRawCircularBuffer()
Expand Down
72 changes: 52 additions & 20 deletions lib/src/bofsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit b62c972

Please sign in to comment.