My fork

Dependencies:   WncControllerK64F

Fork of WNCInterface by Jan Korycan

Revision:
7:fded23f50479
Parent:
1:e511ea8d39d5
Child:
9:9f0578ff157a
diff -r 7cda15f762fe -r fded23f50479 Socket/Socket.cpp
--- a/Socket/Socket.cpp	Wed Sep 28 00:17:57 2016 +0000
+++ b/Socket/Socket.cpp	Thu Oct 06 21:17:18 2016 +0000
@@ -48,7 +48,10 @@
 int Socket::init(int timeout) {
 
     _timeout = timeout;
-    return (WNCInterface::_pwnc->getWncNetworkingStats(&WNCInterface::myNetStats))? 0:-1;
+    M_LOCK;
+    int ret = WNCInterface::_pwnc->getWncNetworkingStats(&WNCInterface::myNetStats)? 0:-1;
+    M_ULOCK;
+    return ret;
 }
 
 //
@@ -67,7 +70,7 @@
   rslt = std::sscanf(url, "%3u.%3u.%3u.%3u",
             (unsigned int*)&address[0], (unsigned int*)&address[1],
             (unsigned int*)&address[2], (unsigned int*)&address[3]);
-    
+  M_LOCK;  
   if (rslt == 4) 
     rslt = WNCInterface::_pwnc->setIpAddr(0,url);
   else 
@@ -77,6 +80,7 @@
     _sock_type = type;             //resolved the URL indicate socket 0 is open
     rslt = WNCInterface::_pwnc->openSocket(0, port, (_sock_type==SOCK_STREAM)? 1:0, _timeout);
     } 
+  M_ULOCK;
   return rslt;
 } 
 
@@ -92,8 +96,10 @@
 
   if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
       FATAL_WNC_ERROR(fail);
- 
-  return !WNCInterface::_pwnc->closeSocket(0);
+  M_LOCK;
+  int ret = !WNCInterface::_pwnc->closeSocket(0);
+  M_ULOCK;
+  return ret;
 }
 
 void Socket::set_blocking(bool blocking, unsigned int timeout) {
@@ -102,9 +108,10 @@
 
     if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
         FATAL_WNC_ERROR(void);
- 
+    M_LOCK;
     WNCInterface::_pwnc->setReadRetryWait(0, 0);
     WNCInterface::_pwnc->setReadRetries(0, 0);
+    M_ULOCK;
 }