A new object oriented network api that can be used to replace the one provided by the EthernetInterface library.

Dependents:   NetRelais TCP_Client_Example TCP_Server_Example UDP_Server_Example ... more

Object oriented network interface for the mbed platform

Currently implemented:

  • Address
  • Endpoint
  • UDP Socket
  • TCP Socket
  • Databuffer
  • Select API

It depends on the EthernetInterface for the lwip network stack.

Please do not hesitate to contact me with any remarks, improvements or questions.

The API is also available for unix at GitHub: LibNosa

Examples

Revision:
8:cdee0f2b6ff0
Parent:
4:d854fa394f85
--- a/tcp/socket.cpp	Wed Jul 18 19:43:12 2012 +0000
+++ b/tcp/socket.cpp	Thu Sep 27 09:31:40 2012 +0000
@@ -35,7 +35,7 @@
     }
     
     // Open socket
-    this->_socket = ::socket(AF_INET, SOCK_STREAM, 0);
+    this->_socket = lwip_socket(AF_INET, SOCK_STREAM, 0);
     if (this->_socket < 0) {
         return -2;
     }
@@ -89,7 +89,7 @@
     endpoint.toNative(&native_endpoint);
     
     // Attempt to connect with remote endpoint.
-    int result = ::connect(this->_socket,
+    int result = lwip_connect(this->_socket,
         (const struct sockaddr *)&native_endpoint, sizeof(native_endpoint));
     
     // Check result
@@ -114,7 +114,7 @@
     }
     
     // Attempt to shutdown the connection.
-    int result = ::shutdown(this->_socket, SHUT_RDWR);
+    int result = lwip_shutdown(this->_socket, SHUT_RDWR);
     if (result < 0) {
         return -2;
     }
@@ -133,7 +133,7 @@
     }
     
     // Put socket into listening mode.
-    int result = ::listen(this->_socket, max_pending);
+    int result = lwip_listen(this->_socket, max_pending);
     if (result < 0) {
         return -2;
     }
@@ -162,7 +162,7 @@
     std::memset(&native_endpoint, 0, sizeof(native_endpoint));
     
     // Accept new (pending) connections.
-    int socket = ::accept(this->_socket,
+    int socket = lwip_accept(this->_socket,
         (struct sockaddr*)&native_endpoint, (u32_t *)&native_endpoint_size);
     
     // Did we succeed?
@@ -186,7 +186,7 @@
 int
 Socket::write(Buffer &buffer)
 {
-    return this->write(buffer.pointer(), buffer.length());
+    return this->write(buffer.data(), buffer.length());
 }
 
 int
@@ -206,7 +206,7 @@
     this->_status = Socket::Sending;
     
     // Try to send the specified amount of bytes.
-    int bytes_written = ::send(this->_socket, data, size, 0);
+    int bytes_written = lwip_send(this->_socket, data, size, 0);
     
     // Update status
     this->_status = (bytes_written == 0)
@@ -220,9 +220,9 @@
 int
 Socket::read(Buffer &buffer)
 {
-    int result = this->read(buffer.pointer(), buffer.size());
+    int result = this->read(buffer.data(), buffer.size());
     if (result >= 0) {
-        buffer.setLength(result);
+        buffer.length(result);
     }
     
     return result;
@@ -245,7 +245,7 @@
     this->_status = Socket::Receiving;
     
     // Try to read data from the socket.
-    int bytes_read = ::recv(this->_socket, data, max_size, 0);
+    int bytes_read = lwip_recv(this->_socket, data, max_size, 0);
     
     // Update status
     this->_status = (bytes_read == 0)