NetworkSocketAPI

Dependencies:   DnsQuery

Dependents:   HelloWizFi250Interface

Fork of NetworkSocketAPI by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
geky
Date:
Tue Apr 05 23:47:04 2016 +0000
Parent:
86:7ca9776b9cc0
Child:
88:6cfd38609828
Commit message:
Refactored enums

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
Socket.h Show annotated file Show diff for this revision Revisions of this file
SocketAddress.h Show annotated file Show diff for this revision Revisions of this file
TCPServer.cpp Show annotated file Show diff for this revision Revisions of this file
TCPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
UDPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/NetworkInterface.h	Tue Apr 05 23:39:54 2016 +0000
+++ b/NetworkInterface.h	Tue Apr 05 23:47:04 2016 +0000
@@ -27,7 +27,7 @@
  *  @enum ns_error_t
  *  @brief enum of standardized error codes
  */
-enum ns_error_t {
+enum nsapi_error_t {
     NSAPI_ERROR_WOULD_BLOCK   = -3001,     /*!< no data is not available but call is non-blocking */
     NSAPI_ERROR_UNSUPPORTED   = -3002,     /*!< unsupported configuration */
     NSAPI_ERROR_NO_CONNECTION = -3003,     /*!< not connected to a network */
@@ -39,7 +39,7 @@
     NSAPI_ERROR_AUTH_FAILURE  = -3009,     /*!< connection to access point faield */
     NSAPI_ERROR_DEVICE_ERROR  = -3010,     /*!< failure interfacing with the network procesor */
 };
-
+   
 /**
  *  @enum ns_opt_t
  *  @brief enum of available options
@@ -47,6 +47,14 @@
 enum ns_opt_t {
 };
 
+/** Enum of socket protocols
+/enum protocol_t
+*/
+enum nsapi_protocol_t {
+   NSAPI_TCP, /*!< Socket is of TCP type */
+   NSAPI_UDP, /*!< Socket is of UDP type */
+};
+
 /** NetworkInterface class
  *  Common interface that is shared between all hardware that
  *  can connect to a network over IP.
@@ -86,19 +94,11 @@
     friend class TCPSocket;
     friend class TCPServer;
 
-    /** Enum of socket protocols
-    /enum protocol_t
-    */
-    enum protocol_t {
-        TCP, /*!< Socket is of TCP type */
-        UDP, /*!< Socket is of UDP type */
-    };
-
     /** Create a socket
     /param proto    The type of socket to open, TCP or UDP
     /return         The alocated socket or null on failure
     */
-    virtual void *socket_create(protocol_t proto) = 0;
+    virtual void *socket_create(nsapi_protocol_t proto) = 0;
 
     /** Destroy a socket
     /param socket   Previously allocated socket
--- a/Socket.cpp	Tue Apr 05 23:39:54 2016 +0000
+++ b/Socket.cpp	Tue Apr 05 23:47:04 2016 +0000
@@ -16,7 +16,7 @@
 
 #include "Socket.h"
 
-Socket::Socket(NetworkInterface *iface, NetworkInterface::protocol_t proto)
+Socket::Socket(NetworkInterface *iface, nsapi_protocol_t proto)
     : _iface(iface)
     , _blocking(true)
     , _timeout(0)
--- a/Socket.h	Tue Apr 05 23:39:54 2016 +0000
+++ b/Socket.h	Tue Apr 05 23:47:04 2016 +0000
@@ -60,7 +60,7 @@
     int close(bool shutdown=true);
 
 protected:
-    Socket(NetworkInterface *iface, NetworkInterface::protocol_t proto);
+    Socket(NetworkInterface *iface, nsapi_protocol_t proto);
 
     static void thunk(void *);
 
--- a/SocketAddress.h	Tue Apr 05 23:39:54 2016 +0000
+++ b/SocketAddress.h	Tue Apr 05 23:47:04 2016 +0000
@@ -19,6 +19,14 @@
 
 #include <stdint.h>
 
+/** Maximum size of IP address
+*/
+#define NSAPI_IP_SIZE 16
+
+/** Maximum size of MAC address
+*/
+#define NSAPI_MAC_SIZE 18
+
 // Predeclared classes
 class NetworkInterface;
 
@@ -27,10 +35,6 @@
  */
 class SocketAddress {
 public:
-    /** Maximum size of IP address
-    */
-    static const int IP_SIZE = 16;
-
     /** SocketAddress construction using DNS resolution
     /param iface    NetworkInterface to use for DNS resolution
     /param addr     Null-terminated hostname that will be resolved
@@ -72,7 +76,7 @@
     uint16_t get_port(void) const;
 
 private:
-    char _ip_address[IP_SIZE];
+    char _ip_address[NSAPI_IP_SIZE];
     uint16_t _port;
 };
 
--- a/TCPServer.cpp	Tue Apr 05 23:39:54 2016 +0000
+++ b/TCPServer.cpp	Tue Apr 05 23:47:04 2016 +0000
@@ -18,7 +18,7 @@
 #include "Timer.h"
 
 TCPServer::TCPServer(NetworkInterface *iface)
-    : Socket(iface, NetworkInterface::TCP)
+    : Socket(iface, NSAPI_TCP)
 {
 }
 
--- a/TCPSocket.cpp	Tue Apr 05 23:39:54 2016 +0000
+++ b/TCPSocket.cpp	Tue Apr 05 23:47:04 2016 +0000
@@ -18,7 +18,7 @@
 #include "Timer.h"
 
 TCPSocket::TCPSocket(NetworkInterface *iface)
-    : Socket(iface, NetworkInterface::TCP)
+    : Socket(iface, NSAPI_TCP)
 {
 }
 
--- a/UDPSocket.cpp	Tue Apr 05 23:39:54 2016 +0000
+++ b/UDPSocket.cpp	Tue Apr 05 23:47:04 2016 +0000
@@ -18,7 +18,7 @@
 #include "Timer.h"
 
 UDPSocket::UDPSocket(NetworkInterface *iface)
-    : Socket(iface, NetworkInterface::UDP)
+    : Socket(iface, NSAPI_UDP)
 {
 }