Compare commits

1 Commits

Author SHA1 Message Date
8e96750046 version 4.7.0
add PIEthernet socket options setReadBufferSize() and setWriteBufferSize()
add PIByteArray::dataAs
2025-02-06 11:13:43 +03:00
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 cmake_policy(SET CMP0017 NEW) # need include() with .cmake
project(PIP) project(PIP)
set(PIP_MAJOR 4) set(PIP_MAJOR 4)
set(PIP_MINOR 6) set(PIP_MINOR 7)
set(PIP_REVISION 0) set(PIP_REVISION 0)
set(PIP_SUFFIX ) set(PIP_SUFFIX )
set(PIP_COMPANY SHS) 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() { void PIEthernet::construct() {
// piCout << " PIEthernet" << uint(this); // piCout << " PIEthernet" << uint(this);
setOption(BlockingWrite); setOption(BlockingWrite);
@@ -211,6 +235,7 @@ void PIEthernet::init() {
} }
applyParameters(); applyParameters();
applyTimeouts(); applyTimeouts();
applyBuffers();
applyOptInt(IPPROTO_IP, IP_TTL, TTL()); applyOptInt(IPPROTO_IP, IP_TTL, TTL());
// piCoutObj << "inited" << path(); // piCoutObj << "inited" << path();
} }
@@ -296,6 +321,7 @@ bool PIEthernet::openDevice() {
while (!mcast_queue.isEmpty()) while (!mcast_queue.isEmpty())
joinMulticastGroup(mcast_queue.dequeue()); joinMulticastGroup(mcast_queue.dequeue());
applyTimeouts(); applyTimeouts();
applyBuffers();
applyOptInt(IPPROTO_IP, IP_TTL, TTL()); applyOptInt(IPPROTO_IP, IP_TTL, TTL());
addr_lr.clear(); addr_lr.clear();
return true; 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) { void PIEthernet::applyTimeout(int fd, int opt, PISystemTime tm) {
if (fd == 0) return; if (fd == 0) return;
// piCoutObj << "setReadIsBlocking" << yes; // piCoutObj << "setReadIsBlocking" << yes;
#ifdef WINDOWS #ifdef WINDOWS
DWORD _tm = tm.toMilliseconds(); DWORD _tm = tm.toMilliseconds();
#else #else

View File

@@ -180,10 +180,17 @@ public:
PISystemTime writeTimeout() const { return property("writeTimeout").toSystemTime(); } PISystemTime writeTimeout() const { return property("writeTimeout").toSystemTime(); }
//! Set timeout for read //! Set timeout for read
void setReadTimeout(PISystemTime tm) { setProperty("readTimeout", tm); } void setReadTimeout(PISystemTime tm);
//! Set timeout for write //! 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) //! Returns TTL (Time To Live)
@@ -477,11 +484,12 @@ protected:
bool closeDevice() override; bool closeDevice() override;
void closeSocket(int & sd); void closeSocket(int & sd);
void applyTimeouts(); void applyTimeouts();
void applyBuffers();
void applyTimeout(int fd, int opt, PISystemTime tm); void applyTimeout(int fd, int opt, PISystemTime tm);
void applyOptInt(int level, int opt, int val); void applyOptInt(int level, int opt, int val);
PRIVATE_DECLARATION(PIP_EXPORT) 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}; std::atomic_bool connected_ = {false}, connecting_ = {false}, listen_threaded = {false}, server_bounded = {false};
bool is_server_client = false; bool is_server_client = false;
mutable PINetworkAddress addr_r, addr_s, addr_lr; 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); } 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. //! \~english Clear array, remove all elements.
//! \~russian Очищает массив, удаляет все элементы. //! \~russian Очищает массив, удаляет все элементы.
//! \~\details //! \~\details