PIPeer important fix!

git-svn-id: svn://db.shs.com.ru/pip@113 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-04-20 10:18:45 +00:00
parent 8c6370fda5
commit 4ae10c905c
4 changed files with 9 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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