minor derivative to reduce compiler warnings and tag read-only parameters as const.

Dependents:   EthernetInterface

Fork of Socket by mbed official

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Sun Apr 09 20:57:44 2017 +0000
Parent:
20:5abbc0e39fb1
Child:
22:95f0918446a9
Commit message:
Enhanced error returns to be unique by type of error, rather than just -1.

Changed in this revision

TCPSocketConnection.cpp Show annotated file Show diff for this revision Revisions of this file
TCPSocketConnection.h Show annotated file Show diff for this revision Revisions of this file
--- a/TCPSocketConnection.cpp	Tue Jul 07 14:03:07 2015 +0000
+++ b/TCPSocketConnection.cpp	Sun Apr 09 20:57:44 2017 +0000
@@ -30,11 +30,11 @@
         return -1;
     
     if (set_address(host, port) != 0)
-        return -1;
+        return -2;
     
     if (lwip_connect(_sock_fd, (const struct sockaddr *) &_remoteHost, sizeof(_remoteHost)) < 0) {
         close();
-        return -1;
+        return -3;
     }
     _is_connected = true;
     
@@ -52,7 +52,7 @@
     if (!_blocking) {
         TimeInterval timeout(_timeout);
         if (wait_writable(timeout) != 0)
-            return -1;
+            return -2;
     }
     
     int n = lwip_send(_sock_fd, data, length, 0);
@@ -83,7 +83,7 @@
             _is_connected = false;
             return writtenLen;
         } else {
-            return -1; //Connnection error
+            return -2; //Connnection error
         }
     }
     return writtenLen;
@@ -96,7 +96,7 @@
     if (!_blocking) {
         TimeInterval timeout(_timeout);
         if (wait_readable(timeout) != 0)
-            return -1;
+            return -2;
     }
     
     int n = lwip_recv(_sock_fd, data, length, 0);
@@ -126,7 +126,7 @@
             _is_connected = false;
             return readLen;
         } else {
-            return -1; //Connnection error
+            return -2; //Connnection error
         }
     }
     return readLen;
--- a/TCPSocketConnection.h	Tue Jul 07 14:03:07 2015 +0000
+++ b/TCPSocketConnection.h	Sun Apr 09 20:57:44 2017 +0000
@@ -36,7 +36,11 @@
     /** Connects this TCP socket to the server
     \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
     \param port The host's port to connect to.
-    \return 0 on success, -1 on failure.
+    \return 
+        * 0 on success, 
+        * -1 on failure to init.
+        * -2 on failure to set the address
+        * -3 on failure to connect
     */
     int connect(const char* host, const int port);
     
@@ -48,28 +52,36 @@
     /** Send data to the remote host.
     \param data The buffer to send to the host.
     \param length The length of the buffer to send.
-    \return the number of written bytes on success (>=0) or -1 on failure
+    \return the number of written bytes on success (>=0) 
+        * -1 if not connected
+        * -2 on timeout
      */
     int send(const char* data, int length);
     
     /** Send all the data to the remote host.
     \param data The buffer to send to the host.
     \param length The length of the buffer to send.
-    \return the number of written bytes on success (>=0) or -1 on failure
+    \return the number of written bytes on success (>=0) or 
+        * -1 if not connected
+        * -2 on send failure - connection error
     */
     int send_all(const char* data, int length);
     
     /** Receive data from the remote host.
     \param data The buffer in which to store the data received from the host.
     \param length The maximum length of the buffer.
-    \return the number of received bytes on success (>=0) or -1 on failure
+    \return the number of received bytes on success (>=0) or 
+        * -1 if not connected
+        * -2 on timeout
      */
     int receive(char* data, int length);
     
     /** Receive all the data from the remote host.
     \param data The buffer in which to store the data received from the host.
     \param length The maximum length of the buffer.
-    \return the number of received bytes on success (>=0) or -1 on failure
+    \return the number of received bytes on success (>=0) or  
+        * -1 if not connected
+        * -2 on send failure - connection error
     */
     int receive_all(char* data, int length);