PIEthernet more accuracy construct
PIThread windows fix
This commit is contained in:
@@ -677,15 +677,28 @@ public:
|
||||
//! \~\brief
|
||||
//! \~english Destructor that executes the function if it exists
|
||||
//! \~russian Деструктор, который выполняет функцию, если она существует
|
||||
~PIScopeExitCall() {
|
||||
if (func) func();
|
||||
}
|
||||
~PIScopeExitCall() { call(); }
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Method for canceling the function
|
||||
//! \~russian Метод для отмены функции
|
||||
void cancel() { func = nullptr; }
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Method for call the function
|
||||
//! \~russian Метод для вызова функции
|
||||
void call() {
|
||||
if (func) func();
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Method for call and canceling the function
|
||||
//! \~russian Метод для вызова и отмены функции
|
||||
void callAndCancel() {
|
||||
call();
|
||||
cancel();
|
||||
}
|
||||
|
||||
private:
|
||||
NO_COPY_CLASS(PIScopeExitCall)
|
||||
|
||||
|
||||
@@ -119,7 +119,8 @@ PRIVATE_DEFINITION_END(PIEthernet)
|
||||
|
||||
PIEthernet::PIEthernet(): PIIODevice("", ReadWrite) {
|
||||
construct();
|
||||
setType(UDP);
|
||||
eth_type = UDP;
|
||||
setProperty("type", (int)UDP);
|
||||
setParameters(PIEthernet::ReuseAddress | PIEthernet::MulticastLoop | PIEthernet::KeepConnection);
|
||||
}
|
||||
|
||||
@@ -128,7 +129,8 @@ PIEthernet::PIEthernet(PIEthernet::Type type_, const PIString & ip_port, const P
|
||||
: PIIODevice(ip_port, ReadWrite) {
|
||||
construct();
|
||||
addr_r.set(ip_port);
|
||||
setType(type_);
|
||||
eth_type = type_;
|
||||
setProperty("type", (int)type_);
|
||||
setParameters(params_);
|
||||
if (type_ != UDP) init();
|
||||
}
|
||||
@@ -140,9 +142,10 @@ PIEthernet::PIEthernet(int sock_, PIString ip_port): PIIODevice("", ReadWrite) {
|
||||
sock = sock_;
|
||||
opened_ = connected_ = true;
|
||||
is_server_client = true;
|
||||
eth_type = TCP_Client;
|
||||
setProperty("type", (int)TCP_Client);
|
||||
init();
|
||||
setParameters(PIEthernet::ReuseAddress | PIEthernet::MulticastLoop);
|
||||
setType(TCP_Client, false);
|
||||
setPath(ip_port);
|
||||
ethNonblocking(sock);
|
||||
PRIVATE->event.create();
|
||||
@@ -162,8 +165,6 @@ PIEthernet::~PIEthernet() {
|
||||
void PIEthernet::construct() {
|
||||
// piCout << " PIEthernet" << uint(this);
|
||||
setOption(BlockingWrite);
|
||||
connected_ = connecting_ = listen_threaded = server_bounded = false;
|
||||
sock = sock_s = -1;
|
||||
setReadTimeout(10_s);
|
||||
setWriteTimeout(10_s);
|
||||
setTTL(64);
|
||||
@@ -179,9 +180,9 @@ void PIEthernet::construct() {
|
||||
}
|
||||
|
||||
|
||||
bool PIEthernet::init() {
|
||||
if (isOpened() || is_server_client) return true;
|
||||
if (sock != -1) return true;
|
||||
void PIEthernet::init() {
|
||||
if (isOpened() || is_server_client) return;
|
||||
if (sock != -1) return;
|
||||
// piCout << "init " << type();
|
||||
PRIVATE->event.destroy();
|
||||
if (sock_s == sock) sock_s = -1;
|
||||
@@ -204,13 +205,12 @@ bool PIEthernet::init() {
|
||||
sock_s = sock;
|
||||
if (sock == -1 || sock_s == -1) {
|
||||
piCoutObj << "Can`t create socket," << ethErrorString();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
applyParameters();
|
||||
applyTimeouts();
|
||||
applyOptInt(IPPROTO_IP, IP_TTL, TTL());
|
||||
// piCoutObj << "inited" << path();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -472,7 +472,7 @@ protected:
|
||||
virtual void received(const void * data, int size) { ; }
|
||||
|
||||
void construct();
|
||||
bool init();
|
||||
void init();
|
||||
bool openDevice() override;
|
||||
bool closeDevice() override;
|
||||
void closeSocket(int & sd);
|
||||
@@ -481,8 +481,8 @@ protected:
|
||||
void applyOptInt(int level, int opt, int val);
|
||||
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
int sock, sock_s;
|
||||
std::atomic_bool connected_, connecting_, listen_threaded, server_bounded;
|
||||
int sock = -1, sock_s = -1;
|
||||
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;
|
||||
Type eth_type;
|
||||
|
||||
@@ -937,6 +937,7 @@ void PIThread::_endThread() {
|
||||
UNREGISTER_THREAD(this);
|
||||
PIINTROSPECTION_THREAD_STOP(this);
|
||||
#if defined(WINDOWS)
|
||||
ec.callAndCancel();
|
||||
# ifdef CC_GCC
|
||||
_endthreadex(0);
|
||||
# else
|
||||
|
||||
Reference in New Issue
Block a user