diff --git a/src/core/piinit.cpp b/src/core/piinit.cpp index 15f77e72..db53988a 100644 --- a/src/core/piinit.cpp +++ b/src/core/piinit.cpp @@ -236,7 +236,11 @@ PIInit::PIInit() { # ifdef ANDROID PIStringAscii("Android"); # else +# ifdef FREE_BSD + PIStringAscii("FreeBSD"); +# else uns.sysname; +# endif # endif # endif # endif diff --git a/src/core/piobject.cpp b/src/core/piobject.cpp index 5087bf11..fe6b3a19 100755 --- a/src/core/piobject.cpp +++ b/src/core/piobject.cpp @@ -274,7 +274,7 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig, PIObject * des i--; } } - ((PIObject*)dest)->updateConnectors(); + dest->updateConnectors(); } @@ -288,7 +288,7 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig, PIObject * des i--; } } - ((PIObject*)dest)->updateConnectors(); + dest->updateConnectors(); } @@ -300,7 +300,9 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig) { PIObject * dest = cc.dest_o; src->connections.remove(i); i--; +#ifndef ANDROID PIMutexLocker _mld(dest->mutex_connect, src != dest); +#endif dest->updateConnectors(); } } @@ -313,7 +315,9 @@ void PIObject::piDisconnect(PIObject * src) { PIVector cv = src->connectors.toVector(); piForeach (PIObject * o, cv) { if (o == src) continue; +#ifndef ANDROID PIMutexLocker _mld(o->mutex_connect, src != o); +#endif PIVector & oc(o->connections); for (int i = 0; i < oc.size_s(); ++i) { //piCout << " check" << (void*)(oc[i].dest_o) << "==" << (void*)(src); diff --git a/src/core/pistring.h b/src/core/pistring.h index 2497f482..8e7019fe 100755 --- a/src/core/pistring.h +++ b/src/core/pistring.h @@ -115,7 +115,7 @@ public: //~PIString() {piMonitor.strings--; piMonitor.containers++;} - PIString & operator =(const PIString & o) {clear(); *this += o; return *this;} + PIString & operator =(const PIString & o) {if (this == &o) return *this; clear(); *this += o; return *this;} /*! \brief Return c-string representation of string * \details Converts content of string to c-string and return diff --git a/src/io/piethernet.cpp b/src/io/piethernet.cpp index aa85dff9..74bf3dac 100755 --- a/src/io/piethernet.cpp +++ b/src/io/piethernet.cpp @@ -268,7 +268,7 @@ bool PIEthernet::closeDevice() { while (!clients_.isEmpty()) delete clients_.back(); if (connected_) disconnected(false); - connected_ = false; + connected_ = connecting_ = false; return true; } @@ -520,11 +520,11 @@ int PIEthernet::read(void * read_to, int max_size) { //qDebug() << "readed" << rs; if (rs <= 0) { lerr = ethErrorCore(); - //piCoutObj << "readed error" << lerr << errorString().data(); + //piCoutObj << "readed error" << lerr << errorString().data() << parameters()[DisonnectOnTimeout]; #ifdef WINDOWS - if (lerr == WSAEWOULDBLOCK || /*lerr == NO_ERROR ||*/ lerr == WSAETIMEDOUT) { + if ((lerr == WSAEWOULDBLOCK || lerr == WSAETIMEDOUT) && !parameters()[DisonnectOnTimeout]) { #else - if (lerr == EAGAIN || lerr == EWOULDBLOCK) { + if ((lerr == EWOULDBLOCK || lerr == EAGAIN) && !parameters()[DisonnectOnTimeout]) { #endif //piCoutObj << errorString(); piMSleep(10); @@ -532,10 +532,10 @@ int PIEthernet::read(void * read_to, int max_size) { } if (connected_) { init(); + connected_ = false; disconnected(rs < 0); } - connected_ = false; - if (parameters()[PIEthernet::KeepConnection]) + if (parameters()[KeepConnection]) connect(); //piCoutObj << "eth" << ip_ << "disconnected"; } diff --git a/src/io/piethernet.h b/src/io/piethernet.h index ed2afa8d..cbadf942 100755 --- a/src/io/piethernet.h +++ b/src/io/piethernet.h @@ -52,7 +52,8 @@ public: SeparateSockets /** If this parameter is set, %PIEthernet will initialize two different sockets, for receive and send, instead of single one. Disabled by default */ = 0x4, MulticastLoop /** Enable receiving multicast packets from same host. Enabled by default */ = 0x8, - KeepConnection /** Automatic reconnect TCP connection on disconnect. Enabled by default */ = 0x10 + KeepConnection /** Automatic reconnect TCP connection on disconnect. Enabled by default */ = 0x10, + DisonnectOnTimeout /** Disconnect TCP connection on read timeout expired. Disabled by default */ = 0x20 }; //! Contructs %PIEthernet with type "type", read address "ip_port" and parameters "params" diff --git a/src/thread/pimutex.cpp b/src/thread/pimutex.cpp index bbbf58ce..77955824 100755 --- a/src/thread/pimutex.cpp +++ b/src/thread/pimutex.cpp @@ -43,7 +43,10 @@ PIMutex::PIMutex() { mutex = CreateMutex(0, false, 0); #else pthread_mutexattr_t attr; + memset(&attr, 0, sizeof(attr)); pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); + memset(&mutex, 0, sizeof(mutex)); pthread_mutex_init(&mutex, &attr); pthread_mutexattr_destroy(&attr); #endif diff --git a/src/thread/pithread.cpp b/src/thread/pithread.cpp index 1faf3bc6..c41e2d12 100755 --- a/src/thread/pithread.cpp +++ b/src/thread/pithread.cpp @@ -103,7 +103,7 @@ PIThread::~PIThread() { if (!running_ || thread == 0) return; #ifndef WINDOWS # ifdef ANDROID - pthread_kill(thread, SIGSTOP); + pthread_kill(thread, SIGTERM); # else pthread_cancel(thread); # endif