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 91:cad29ce6a01c, committed 2016-04-19
- Comitter:
- Christopher Haster
- Date:
- Tue Apr 19 18:23:12 2016 -0500
- Parent:
- 90:0a988e4abb72
- Child:
- 92:dd5f19874adf
- Commit message:
- Remove shutdown parameter from close call
Pros
- Simplifies interface
- Easier base implementation
Cons
- May need shutdown functionality, in this case shutdown
can be added as another function in the future
Changed in this revision
--- a/NetworkInterface.h Tue Apr 19 18:22:15 2016 -0500 +++ b/NetworkInterface.h Tue Apr 19 18:23:12 2016 -0500 @@ -201,9 +201,8 @@ /** Close the socket * @param handle Socket handle - * @param shutdown free the left-over data in message queues */ - virtual int socket_close(void *handle, bool shutdown) = 0; + virtual int socket_close(void *handle) = 0; /** Register a callback on when a new connection is ready * @param handle Socket handle
--- a/Socket.cpp Tue Apr 19 18:22:15 2016 -0500 +++ b/Socket.cpp Tue Apr 19 18:23:12 2016 -0500 @@ -27,7 +27,7 @@ Socket::~Socket() { if (_socket) { - close(false); + close(); } } @@ -37,13 +37,13 @@ _socket = _iface->socket_create(proto); } -int Socket::close(bool shutdown) +int Socket::close() { if (!_socket) { return 0; } - int err = _iface->socket_close(_socket, shutdown); + int err = _iface->socket_close(_socket); if (!err) { void *socket = _socket; _socket = 0;
--- a/Socket.h Tue Apr 19 18:22:15 2016 -0500 +++ b/Socket.h Tue Apr 19 18:23:12 2016 -0500 @@ -60,9 +60,8 @@ int get_option(int optname, void *optval, unsigned *optlen); /** Close the socket - * @param shutdown free the left-over data in message queues */ - int close(bool shutdown=true); + int close(); protected: Socket();