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.
Diff: Socket.h
- Revision:
- 115:950b19eb0f02
- Parent:
- 109:5d8bd5752386
- Child:
- 118:96627c4b83d5
--- a/Socket.h Wed Apr 20 11:07:19 2016 -0500 +++ b/Socket.h Wed Apr 20 19:05:03 2016 -0500 @@ -86,7 +86,10 @@ * blocking operations such as send/recv/accept return * NSAPI_ERROR_WOULD_BLOCK if they can not continue. * - * @param blocking True for blocking mode, false for non-blocking mode. + * set_blocking(false) is equivalent to set_timeout(-1) + * set_blocking(true) is equivalent to set_timeout(0) + * + * @param blocking true for blocking mode, false for non-blocking mode. */ void set_blocking(bool blocking); @@ -94,11 +97,14 @@ * * Initially all sockets have unbounded timeouts. NSAPI_ERROR_WOULD_BLOCK * is returned if a blocking operation takes longer than the specified - * timeout. A timeout of 0 removes a timeout from the socket. + * timeout. A timeout of -1 removes the timeout from the socket. + * + * set_timeout(-1) is equivalent to set_blocking(false) + * set_timeout(0) is equivalent to set_blocking(true) * * @param timeout Timeout in milliseconds */ - void set_timeout(unsigned int timeout); + void set_timeout(int timeout); /* Set stack-specific socket options * @@ -166,8 +172,7 @@ NetworkStack *_iface; void *_socket; - bool _blocking; - unsigned _timeout; + int _timeout; FunctionPointer _callback; };