NetworkSocketAPI

Dependencies:   DnsQuery

Dependents:   HelloWizFi250Interface

Fork of NetworkSocketAPI by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
Christopher Haster
Date:
Mon Feb 22 20:51:09 2016 -0600
Branch:
api-changes
Parent:
37:50b481a8e784
Child:
39:47138420ea42
Commit message:
Added isConnected method to Socket/SocketInterface

Changed in this revision

Socket.cpp Show annotated file Show diff for this revision Revisions of this file
Socket.h Show annotated file Show diff for this revision Revisions of this file
SocketInterface.cpp Show annotated file Show diff for this revision Revisions of this file
SocketInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/Socket.cpp	Tue Feb 23 17:35:56 2016 +0000
+++ b/Socket.cpp	Mon Feb 22 20:51:09 2016 -0600
@@ -71,6 +71,15 @@
     return _port;
 }
 
+bool Socket::isConnected()
+{
+    if (!_socket) {
+        return false;
+    }
+
+    return _socket->isConnected();
+}
+
 int32_t Socket::open(const char *url, uint16_t port)
 {
     if (_socket) {
--- a/Socket.h	Tue Feb 23 17:35:56 2016 +0000
+++ b/Socket.h	Mon Feb 22 20:51:09 2016 -0600
@@ -53,6 +53,11 @@
      */
     uint16_t getPort() const;
 
+    /** Returns status of socket
+     *  @return true if connected
+     */
+    bool isConnected();
+
 
     /** Open a connection to the underlying address
      *  @param url Optional URL or IP address to connect to
--- a/SocketInterface.cpp	Tue Feb 23 17:35:56 2016 +0000
+++ b/SocketInterface.cpp	Mon Feb 22 20:51:09 2016 -0600
@@ -15,7 +15,14 @@
  */
 
 #include "SocketInterface.h"
- 
+
+// By default setIPAddress/setPort has no special behaviour 
 void SocketInterface::setIPAddress(const char *ip) {}
 void SocketInterface::setPort(uint16_t port) {}
 
+// By default isConnected is always true if the socket
+// was created successfully
+bool SocketInterface::isConnected() {
+    return true;
+}
+
--- a/SocketInterface.h	Tue Feb 23 17:35:56 2016 +0000
+++ b/SocketInterface.h	Mon Feb 22 20:51:09 2016 -0600
@@ -46,6 +46,11 @@
      */
     virtual void setPort(uint16_t port);
 
+    /** Status of the socket
+     *  @return True if connected
+     */
+    virtual bool isConnected();
+
     /** Open a connection to the underlying address
      *  @param ip IP address to connect to
      *  @param port Port to connect to