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

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

View File

@@ -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<PIObject * > cv = src->connectors.toVector();
piForeach (PIObject * o, cv) {
if (o == src) continue;
#ifndef ANDROID
PIMutexLocker _mld(o->mutex_connect, src != o);
#endif
PIVector<Connection> & oc(o->connections);
for (int i = 0; i < oc.size_s(); ++i) {
//piCout << " check" << (void*)(oc[i].dest_o) << "==" << (void*)(src);

View File

@@ -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

View File

@@ -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";
}

View File

@@ -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"

View File

@@ -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

View File

@@ -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