version 4.7.0

add PIEthernet socket options setReadBufferSize() and setWriteBufferSize()
add PIByteArray::dataAs
This commit is contained in:
2025-02-06 11:13:43 +03:00
parent d01baffb0b
commit 8e96750046
4 changed files with 57 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
project(PIP)
set(PIP_MAJOR 4)
set(PIP_MINOR 6)
set(PIP_MINOR 7)
set(PIP_REVISION 0)
set(PIP_SUFFIX )
set(PIP_COMPANY SHS)

View File

@@ -163,6 +163,30 @@ PIEthernet::~PIEthernet() {
}
void PIEthernet::setReadTimeout(PISystemTime tm) {
setProperty("readTimeout", tm);
applyTimeouts();
}
void PIEthernet::setWriteTimeout(PISystemTime tm) {
setProperty("writeTimeout", tm);
applyTimeouts();
}
void PIEthernet::setReadBufferSize(int bytes) {
rcv_buf = bytes;
applyBuffers();
}
void PIEthernet::setWriteBufferSize(int bytes) {
snd_buf = bytes;
applyBuffers();
}
void PIEthernet::construct() {
// piCout << " PIEthernet" << uint(this);
setOption(BlockingWrite);
@@ -211,6 +235,7 @@ void PIEthernet::init() {
}
applyParameters();
applyTimeouts();
applyBuffers();
applyOptInt(IPPROTO_IP, IP_TTL, TTL());
// piCoutObj << "inited" << path();
}
@@ -296,6 +321,7 @@ bool PIEthernet::openDevice() {
while (!mcast_queue.isEmpty())
joinMulticastGroup(mcast_queue.dequeue());
applyTimeouts();
applyBuffers();
applyOptInt(IPPROTO_IP, IP_TTL, TTL());
addr_lr.clear();
return true;
@@ -338,9 +364,22 @@ void PIEthernet::applyTimeouts() {
}
void PIEthernet::applyBuffers() {
if (sock < 0) return;
if (rcv_buf > 0) ethSetsockoptInt(sock, SOL_SOCKET, SO_RCVBUF, rcv_buf);
if (snd_buf > 0) {
if (sock_s != sock) {
ethSetsockoptInt(sock_s, SOL_SOCKET, SO_SNDBUF, snd_buf);
} else {
ethSetsockoptInt(sock, SOL_SOCKET, SO_SNDBUF, snd_buf);
}
}
}
void PIEthernet::applyTimeout(int fd, int opt, PISystemTime tm) {
if (fd == 0) return;
// piCoutObj << "setReadIsBlocking" << yes;
// piCoutObj << "setReadIsBlocking" << yes;
#ifdef WINDOWS
DWORD _tm = tm.toMilliseconds();
#else

View File

@@ -180,10 +180,17 @@ public:
PISystemTime writeTimeout() const { return property("writeTimeout").toSystemTime(); }
//! Set timeout for read
void setReadTimeout(PISystemTime tm) { setProperty("readTimeout", tm); }
void setReadTimeout(PISystemTime tm);
//! Set timeout for write
void setWriteTimeout(PISystemTime tm) { setProperty("writeTimeout", tm); }
void setWriteTimeout(PISystemTime tm);
//! Set socket receive buffer size
void setReadBufferSize(int bytes);
//! Set socket send buffer size
void setWriteBufferSize(int bytes);
//! Returns TTL (Time To Live)
@@ -477,11 +484,12 @@ protected:
bool closeDevice() override;
void closeSocket(int & sd);
void applyTimeouts();
void applyBuffers();
void applyTimeout(int fd, int opt, PISystemTime tm);
void applyOptInt(int level, int opt, int val);
PRIVATE_DECLARATION(PIP_EXPORT)
int sock = -1, sock_s = -1;
int sock = -1, sock_s = -1, rcv_buf = 0, snd_buf = 0;
std::atomic_bool connected_ = {false}, connecting_ = {false}, listen_threaded = {false}, server_bounded = {false};
bool is_server_client = false;
mutable PINetworkAddress addr_r, addr_s, addr_lr;

View File

@@ -492,6 +492,11 @@ public:
//! По умолчанию указывает на начало массива.
inline const uchar * data(size_t index = 0) const { return d.data(index); }
template<typename T>
inline T dataAs(size_t index = 0) {
return *(T *)d.data(index);
}
//! \~english Clear array, remove all elements.
//! \~russian Очищает массив, удаляет все элементы.
//! \~\details