Base class for IP Based Networking Libraries

Dependencies:   DnsQuery

Dependents:   TempTower BSDInterfaceTests HelloBSDInterface ESP8266InterfaceTests ... more

For a complete getting started guide see the wiki...

Network Socket API

The Network Socket API provides a common interface for using sockets on network devices. The API provides a simple class-based interface that should be familiar to users experienced with other socket APIs. Additionally, the API provides a simple interface for implementing network devices, making it easy to connect hardware agnostic programs to new devices.

Network Interfaces

The NetworkInterface provides an abstract class for network devices that support sockets. Devices should provide a DeviceInterface class that inherits this interface and adds implementation specific methods for using the device. A NetworkInterface must be provided to a Socket constructor to open a socket on the interface. Currently two subclasses are defined for common devices, EthernetInterface and WiFiInterface.

Sockets

The Socket class is used for managing network sockets. Once opened, the socket provides a pipe through which data can sent and recieved to a specific endpoint. The socket class can be instantiated as either a TCPSocket or a UDPSocket which defines the protocol used for the connection.

Revision:
65:ca337f9ebdab
Parent:
58:1caa187fa5af
Child:
66:c84a4c76cb94
--- a/Socket.cpp	Wed Mar 09 05:52:30 2016 +0000
+++ b/Socket.cpp	Fri Apr 01 16:29:45 2016 +0000
@@ -69,12 +69,13 @@
     if (!_socket) {
         return 0;
     }
-
-    int32_t err = _socket->close();
+    
+    SocketInterface *socket = _socket;
+    _socket = 0;
 
+    int32_t err = socket->close();
     if (!err) {
-        _iface->destroySocket(_socket);
-        _socket = 0;
+        _iface->destroySocket(socket);
     }
 
     return err;
@@ -90,11 +91,11 @@
 
 int32_t Socket::recv(void *data, uint32_t size, bool blocking)
 {
-    if (!_socket) {
-        return NS_ERROR_NO_CONNECTION;
-    }
-
     while (true) {
+        if (!_socket) {
+            return NS_ERROR_NO_CONNECTION;
+        }
+        
         int32_t recv = _socket->recv(data, size);
 
         if (recv != 0 || !blocking) {