PIEthernet TCP improvements

git-svn-id: svn://db.shs.com.ru/pip@131 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-05-18 07:12:04 +00:00
parent a4fadea95f
commit bfcdb80186
7 changed files with 23 additions and 11 deletions

View File

@@ -236,7 +236,11 @@ PIInit::PIInit() {
# ifdef ANDROID # ifdef ANDROID
PIStringAscii("Android"); PIStringAscii("Android");
# else # else
# ifdef FREE_BSD
PIStringAscii("FreeBSD");
# else
uns.sysname; uns.sysname;
# endif
# endif # endif
# endif # endif
# endif # endif

View File

@@ -274,7 +274,7 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig, PIObject * des
i--; i--;
} }
} }
((PIObject*)dest)->updateConnectors(); dest->updateConnectors();
} }
@@ -288,7 +288,7 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig, PIObject * des
i--; i--;
} }
} }
((PIObject*)dest)->updateConnectors(); dest->updateConnectors();
} }
@@ -300,7 +300,9 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig) {
PIObject * dest = cc.dest_o; PIObject * dest = cc.dest_o;
src->connections.remove(i); src->connections.remove(i);
i--; i--;
#ifndef ANDROID
PIMutexLocker _mld(dest->mutex_connect, src != dest); PIMutexLocker _mld(dest->mutex_connect, src != dest);
#endif
dest->updateConnectors(); dest->updateConnectors();
} }
} }
@@ -313,7 +315,9 @@ void PIObject::piDisconnect(PIObject * src) {
PIVector<PIObject * > cv = src->connectors.toVector(); PIVector<PIObject * > cv = src->connectors.toVector();
piForeach (PIObject * o, cv) { piForeach (PIObject * o, cv) {
if (o == src) continue; if (o == src) continue;
#ifndef ANDROID
PIMutexLocker _mld(o->mutex_connect, src != o); PIMutexLocker _mld(o->mutex_connect, src != o);
#endif
PIVector<Connection> & oc(o->connections); PIVector<Connection> & oc(o->connections);
for (int i = 0; i < oc.size_s(); ++i) { for (int i = 0; i < oc.size_s(); ++i) {
//piCout << " check" << (void*)(oc[i].dest_o) << "==" << (void*)(src); //piCout << " check" << (void*)(oc[i].dest_o) << "==" << (void*)(src);

View File

@@ -115,7 +115,7 @@ public:
//~PIString() {piMonitor.strings--; piMonitor.containers++;} //~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 /*! \brief Return c-string representation of string
* \details Converts content of string to c-string and return * \details Converts content of string to c-string and return

View File

@@ -268,7 +268,7 @@ bool PIEthernet::closeDevice() {
while (!clients_.isEmpty()) while (!clients_.isEmpty())
delete clients_.back(); delete clients_.back();
if (connected_) disconnected(false); if (connected_) disconnected(false);
connected_ = false; connected_ = connecting_ = false;
return true; return true;
} }
@@ -520,11 +520,11 @@ int PIEthernet::read(void * read_to, int max_size) {
//qDebug() << "readed" << rs; //qDebug() << "readed" << rs;
if (rs <= 0) { if (rs <= 0) {
lerr = ethErrorCore(); lerr = ethErrorCore();
//piCoutObj << "readed error" << lerr << errorString().data(); //piCoutObj << "readed error" << lerr << errorString().data() << parameters()[DisonnectOnTimeout];
#ifdef WINDOWS #ifdef WINDOWS
if (lerr == WSAEWOULDBLOCK || /*lerr == NO_ERROR ||*/ lerr == WSAETIMEDOUT) { if ((lerr == WSAEWOULDBLOCK || lerr == WSAETIMEDOUT) && !parameters()[DisonnectOnTimeout]) {
#else #else
if (lerr == EAGAIN || lerr == EWOULDBLOCK) { if ((lerr == EWOULDBLOCK || lerr == EAGAIN) && !parameters()[DisonnectOnTimeout]) {
#endif #endif
//piCoutObj << errorString(); //piCoutObj << errorString();
piMSleep(10); piMSleep(10);
@@ -532,10 +532,10 @@ int PIEthernet::read(void * read_to, int max_size) {
} }
if (connected_) { if (connected_) {
init(); init();
connected_ = false;
disconnected(rs < 0); disconnected(rs < 0);
} }
connected_ = false; if (parameters()[KeepConnection])
if (parameters()[PIEthernet::KeepConnection])
connect(); connect();
//piCoutObj << "eth" << ip_ << "disconnected"; //piCoutObj << "eth" << ip_ << "disconnected";
} }

View File

@@ -52,7 +52,8 @@ public:
SeparateSockets /** If this parameter is set, %PIEthernet will initialize two different sockets, SeparateSockets /** If this parameter is set, %PIEthernet will initialize two different sockets,
for receive and send, instead of single one. Disabled by default */ = 0x4, for receive and send, instead of single one. Disabled by default */ = 0x4,
MulticastLoop /** Enable receiving multicast packets from same host. Enabled by default */ = 0x8, 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" //! Contructs %PIEthernet with type "type", read address "ip_port" and parameters "params"

View File

@@ -43,7 +43,10 @@ PIMutex::PIMutex() {
mutex = CreateMutex(0, false, 0); mutex = CreateMutex(0, false, 0);
#else #else
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
memset(&attr, 0, sizeof(attr));
pthread_mutexattr_init(&attr); pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
memset(&mutex, 0, sizeof(mutex));
pthread_mutex_init(&mutex, &attr); pthread_mutex_init(&mutex, &attr);
pthread_mutexattr_destroy(&attr); pthread_mutexattr_destroy(&attr);
#endif #endif

View File

@@ -103,7 +103,7 @@ PIThread::~PIThread() {
if (!running_ || thread == 0) return; if (!running_ || thread == 0) return;
#ifndef WINDOWS #ifndef WINDOWS
# ifdef ANDROID # ifdef ANDROID
pthread_kill(thread, SIGSTOP); pthread_kill(thread, SIGTERM);
# else # else
pthread_cancel(thread); pthread_cancel(thread);
# endif # endif