PIThread more accurate end, PIEthernet tcpserver client no reinit
This commit is contained in:
@@ -139,6 +139,7 @@ PIEthernet::PIEthernet(int sock_, PIString ip_port): PIIODevice("", ReadWrite) {
|
|||||||
addr_s.set(ip_port);
|
addr_s.set(ip_port);
|
||||||
sock = sock_;
|
sock = sock_;
|
||||||
opened_ = connected_ = true;
|
opened_ = connected_ = true;
|
||||||
|
is_server_client = true;
|
||||||
init();
|
init();
|
||||||
setParameters(PIEthernet::ReuseAddress | PIEthernet::MulticastLoop);
|
setParameters(PIEthernet::ReuseAddress | PIEthernet::MulticastLoop);
|
||||||
setType(TCP_Client, false);
|
setType(TCP_Client, false);
|
||||||
@@ -168,7 +169,7 @@ void PIEthernet::construct() {
|
|||||||
setTTL(64);
|
setTTL(64);
|
||||||
setMulticastTTL(1);
|
setMulticastTTL(1);
|
||||||
server_thread_.setData(this);
|
server_thread_.setData(this);
|
||||||
server_thread_.setName("__S__server_thread"_a);
|
server_thread_.setName("_S.tcpserver"_a);
|
||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
setThreadedReadBufferSize(512);
|
setThreadedReadBufferSize(512);
|
||||||
#else
|
#else
|
||||||
@@ -179,7 +180,7 @@ void PIEthernet::construct() {
|
|||||||
|
|
||||||
|
|
||||||
bool PIEthernet::init() {
|
bool PIEthernet::init() {
|
||||||
if (isOpened()) return true;
|
if (isOpened() || is_server_client) return true;
|
||||||
if (sock != -1) return true;
|
if (sock != -1) return true;
|
||||||
// piCout << "init " << type();
|
// piCout << "init " << type();
|
||||||
PRIVATE->event.destroy();
|
PRIVATE->event.destroy();
|
||||||
|
|||||||
@@ -483,6 +483,7 @@ protected:
|
|||||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||||
int sock, sock_s;
|
int sock, sock_s;
|
||||||
std::atomic_bool connected_, connecting_, listen_threaded, server_bounded;
|
std::atomic_bool connected_, connecting_, listen_threaded, server_bounded;
|
||||||
|
bool is_server_client = false;
|
||||||
mutable PINetworkAddress addr_r, addr_s, addr_lr;
|
mutable PINetworkAddress addr_r, addr_s, addr_lr;
|
||||||
Type eth_type;
|
Type eth_type;
|
||||||
PIThread server_thread_;
|
PIThread server_thread_;
|
||||||
|
|||||||
@@ -919,6 +919,10 @@ void PIThread::_runThread() {
|
|||||||
|
|
||||||
|
|
||||||
void PIThread::_endThread() {
|
void PIThread::_endThread() {
|
||||||
|
PIScopeExitCall ec([this] {
|
||||||
|
terminating = running_ = false;
|
||||||
|
tid_ = -1;
|
||||||
|
});
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
||||||
stopped();
|
stopped();
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
||||||
@@ -927,8 +931,6 @@ void PIThread::_endThread() {
|
|||||||
end();
|
end();
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
||||||
if (lockRun) thread_mutex.unlock();
|
if (lockRun) thread_mutex.unlock();
|
||||||
terminating = running_ = false;
|
|
||||||
tid_ = -1;
|
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "exit";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "exit";
|
||||||
// cout << "thread " << t << " exiting ... " << endl;
|
// cout << "thread " << t << " exiting ... " << endl;
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "pthread_exit" << (__privateinitializer__.p)->thread;
|
// PICout(PICoutManipulators::DefaultControls) << "pthread_exit" << (__privateinitializer__.p)->thread;
|
||||||
@@ -943,7 +945,7 @@ void PIThread::_endThread() {
|
|||||||
#elif defined(FREERTOS)
|
#elif defined(FREERTOS)
|
||||||
PRIVATE->thread = 0;
|
PRIVATE->thread = 0;
|
||||||
#else
|
#else
|
||||||
pthread_detach(PRIVATE->thread);
|
// pthread_detach(PRIVATE->thread);
|
||||||
PRIVATE->thread = 0;
|
PRIVATE->thread = 0;
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user