From 4ae10c905c665714ec184986e297e34de5ea3919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Mon, 20 Apr 2015 10:18:45 +0000 Subject: [PATCH] PIPeer important fix! git-svn-id: svn://db.shs.com.ru/pip@113 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/io/piethernet.cpp | 9 +++++---- src/io/piethernet.h | 2 +- src/io/pipeer.cpp | 1 + src/thread/pimutex.h | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/io/piethernet.cpp b/src/io/piethernet.cpp index 2851bef4..c0dfd495 100755 --- a/src/io/piethernet.cpp +++ b/src/io/piethernet.cpp @@ -272,7 +272,7 @@ bool PIEthernet::closeDevice() { void PIEthernet::closeSocket(int & sd) { if (sd != -1) - ethClosesocket(sd); + ethClosesocket(sd, type() != PIEthernet::UDP); sd = -1; } @@ -1035,13 +1035,14 @@ int PIEthernet::ethSendto(int sock, const void * buf, int size, int flags, socka } -void PIEthernet::ethClosesocket(int sock) { +void PIEthernet::ethClosesocket(int sock, bool shutdown) { if (sock < 0) return; + if (shutdown) ::shutdown(sock, #ifdef WINDOWS - shutdown(sock, SD_BOTH); + SD_BOTH); closesocket(sock); #else - shutdown(sock, SHUT_RDWR); + SHUT_RDWR); ::close(sock); #endif } diff --git a/src/io/piethernet.h b/src/io/piethernet.h index 970fb471..45884272 100755 --- a/src/io/piethernet.h +++ b/src/io/piethernet.h @@ -414,7 +414,7 @@ private: inline static int ethRecv(int sock, void * buf, int size, int flags = 0); inline static int ethRecvfrom(int sock, void * buf, int size, int flags, sockaddr * addr); inline static int ethSendto(int sock, const void * buf, int size, int flags, sockaddr * addr, int addr_len); - inline static void ethClosesocket(int sock); + inline static void ethClosesocket(int sock, bool shutdown); inline static int ethSetsockopt(int sock, int level, int optname, const void * optval, int optlen); inline static int ethSetsockoptInt(int sock, int level, int optname, int value = 1); inline static int ethSetsockoptBool(int sock, int level, int optname, bool value = true); diff --git a/src/io/pipeer.cpp b/src/io/pipeer.cpp index 2357328f..6ef8ecea 100755 --- a/src/io/pipeer.cpp +++ b/src/io/pipeer.cpp @@ -246,6 +246,7 @@ void PIPeer::initMBcasts(PIStringList al) { eth_lo.setDebug(false); eth_lo.setName("__S__PIPeer_eth_loopback"); eth_lo.setParameters(0); + eth_lo.init(); cint = prev_ifaces.getByAddress("127.0.0.1"); for (int p = _PIPEER_LOOPBACK_PORT_S; p <= _PIPEER_LOOPBACK_PORT_E; ++p) { eth_lo.setReadAddress("127.0.0.1", p); diff --git a/src/thread/pimutex.h b/src/thread/pimutex.h index 8827c793..f540ef3d 100755 --- a/src/thread/pimutex.h +++ b/src/thread/pimutex.h @@ -59,7 +59,7 @@ private: pthread_mutex_t #endif mutex; - bool locked; + volatile bool locked; }; @@ -72,7 +72,7 @@ public: ~PIMutexLocker() {if (cond) mutex->unlock();} private: PIMutex * mutex; - bool cond; + volatile bool cond; }; #endif // PIMUTEX_H