NetworkSocketAPI

Dependencies:   DnsQuery

Dependents:   HelloWizFi250Interface

Fork of NetworkSocketAPI by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
Christopher Haster
Date:
Wed Feb 24 23:05:54 2016 -0600
Branch:
api-changes
Parent:
44:aef3f416e4b0
Child:
46:ac37605ca91d
Commit message:
Added inexaustive list of standardized error codes

Changed in this revision

NetworkInterface.h Show annotated file Show diff for this revision Revisions of this file
Socket.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/NetworkInterface.h	Wed Feb 24 22:18:51 2016 -0600
+++ b/NetworkInterface.h	Wed Feb 24 23:05:54 2016 -0600
@@ -26,6 +26,19 @@
 #define NS_IP_SIZE 16
 #define NS_MAC_SIZE 18
 
+/** Inexhaustive enum of standardized error codes
+ */
+enum ns_error_t {
+    NS_ERROR_TIMEOUT       = -3001,
+    NS_ERROR_NO_CONNECTION = -3002,
+    NS_ERROR_NO_SOCKET     = -3003,
+    NS_ERROR_NO_ADDRESS    = -3004,
+    NS_ERROR_NO_MEMORY     = -3005,
+    NS_ERROR_DNS_FAILURE   = -3006,
+    NS_ERROR_DHCP_FAILURE  = -3007,
+    NS_ERROR_CRED_FAILURE  = -3008
+};
+
 
 /** NetworkInterface class
  *  Common interface that is shared between all hardware that
--- a/Socket.cpp	Wed Feb 24 22:18:51 2016 -0600
+++ b/Socket.cpp	Wed Feb 24 23:05:54 2016 -0600
@@ -35,10 +35,6 @@
 
 int32_t Socket::setURL(const char *url)
 {
-    if (!_iface) {
-        return -4;
-    }
-
     int32_t err = _iface->getHostByName(url, _ip_address);
     if (err) {
         return err;
@@ -101,10 +97,6 @@
         return err;
     }
 
-    if (!_iface) {
-        return -4;
-    }
-
     if (address) {
         err = setURL(address);
         if (err) {
@@ -117,12 +109,12 @@
     }
 
     if (!getIPAddress() || !getPort()) {
-        return -3;
+        return NS_ERROR_NO_ADDRESS;
     }
 
     _socket = _iface->createSocket(_proto);
     if (!_socket) {
-        return -2;
+        return NS_ERROR_NO_SOCKET;
     }
 
     err = _socket->open(_ip_address, _port);
@@ -152,7 +144,7 @@
 int32_t Socket::send(const void *data, uint32_t len)
 {
     if (!_socket) {
-        return -2;
+        return NS_ERROR_NO_CONNECTION;
     }
     return _socket->send(data, len);
 }
@@ -160,7 +152,7 @@
 int32_t Socket::recv(void *data, uint32_t len)
 {
     if (!_socket) {
-        return -2;
+        return NS_ERROR_NO_CONNECTION;
     }
     return _socket->recv(data, len);
 }