Added mutex for multiple SPI devices on the same SPI bus

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Revision:
18:7e22775eadb9
Parent:
17:14b6a3a2b622
Child:
34:1ad18123bf11
--- a/Socket/Endpoint.cpp	Wed Oct 02 20:29:31 2013 +0200
+++ b/Socket/Endpoint.cpp	Wed Oct 02 21:57:28 2013 +0000
@@ -78,6 +78,7 @@
 int Endpoint::set_address(const char* host, const int port) {
     reset_address();
 
+    int resolveRetCode;
     char address[5];
     char *p_address = address;
 
@@ -93,15 +94,25 @@
     if (result != 4) {
         //Resolve DNS address or populate hard-coded IP address
         uint32_t address_integer;
-        _cc3000_module->_socket.gethostbyname((uint8_t *)host, strlen(host) , &address_integer);
-
-        uint32_t ip = 0;
-        ip = (ip | (address_integer >> 24));
-        ip = (ip | ((address_integer & 0x00FF0000) >> 8));
-        ip = (ip | ((address_integer & 0x0000FF00) << 8));
-        ip = (ip | ((address_integer & 0x000000FF) << 24));
-        _remote_host.sin_addr.s_addr = ip;
-        inet_ntoa_r(_remote_host.sin_addr, _ipAddress, sizeof(_ipAddress));
+        resolveRetCode = _cc3000_module->_socket.gethostbyname((uint8_t *)host, strlen(host) , &address_integer);
+        
+        if ((resolveRetCode > -1) && ( 0 != address_integer ))
+        {
+            // Resolved address
+            uint32_t ip = 0;
+            ip = (ip | (address_integer >> 24));
+            ip = (ip | ((address_integer & 0x00FF0000) >> 8));
+            ip = (ip | ((address_integer & 0x0000FF00) << 8));
+            ip = (ip | ((address_integer & 0x000000FF) << 24));
+            _remote_host.sin_addr.s_addr = ip;
+            inet_ntoa_r(_remote_host.sin_addr, _ipAddress, sizeof(_ipAddress));
+        }
+        else
+        {
+            // Failed to resolve the address
+            DBG_SOCKET("Failed to resolve the hostname : %s",host);
+            return ( -1 );
+        }
     } else {
         std::memcpy((char*)&_remote_host.sin_addr.s_addr, p_address, 4);
     }