NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
Revision 2:ce08986b18b5, committed 2015-05-19
- Comitter:
- bridadan
- Date:
- Tue May 19 17:40:28 2015 +0000
- Parent:
- 1:291a9d61e58a
- Child:
- 3:167dd63981b6
- Commit message:
- Added some SocketInterface functions and docs
Changed in this revision
NetworkInterface.h | Show annotated file Show diff for this revision Revisions of this file |
SocketInterface.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/NetworkInterface.h Thu May 14 01:37:53 2015 +0000 +++ b/NetworkInterface.h Tue May 19 17:40:28 2015 +0000 @@ -41,7 +41,7 @@ * * \returns 0 on success, a negative number on failure */ - virtual int init(char* ip, char* mask, char *gateway) = 0; + virtual int init(char *ip, char *mask, char *gateway) = 0; /** * Start the interface, using DHCP if needed. @@ -53,17 +53,6 @@ virtual int connect(unsigned int timeout_ms=15000) = 0; /** - * Start the interface, specifically for wifi based hardware, using DHCP if needed. This only needs to be implemented on wifi hardware. - * - * @param ssid The SSID of the access point - * @param phrase The passphrase, if needed, to connect - * @param gateway The security type of the access point - * - * \returns 0 on success, a negative number on failure - */ - virtual int connect(char* ssid, char* phrase, char* security_type) = 0; - - /** * Stop the interface, bringing down dhcp if necessary. * * \returns 0 on success, a negative number on failure
--- a/SocketInterface.h Thu May 14 01:37:53 2015 +0000 +++ b/SocketInterface.h Tue May 19 17:40:28 2015 +0000 @@ -16,11 +16,58 @@ #ifndef SOCKETINTERFACE_H #define SOCKETINTERFACE_H - + +/** SocketInterface class. + * This is a common interface that is shared between all sockets that connect + * using the NetworkInterface. + */ class SocketInterface { public: + /** + * This enum defines the possible socket protocol families. + */ + enum ProtocolFamily { + AF_INET, /**< IPv4 */ + AF_INET6, /**< IPV6 */ + AF_UNIX /**< Local socket (using a file) */ + }; + + /** + * This enum defines the possible socket types. + */ + enum SockType { + SOCK_STREAM, /**< Stream socket, generally used for TCP */ + SOCK_DGRAM, /**< Datagram socket, generally used for UDP */ + SOCK_SEQPACKET, /**< Reliable sequenced packet service */ + SOCK_RAW /**< Raw protocols atop the network layer */ + }; + /** + * Configure the socket's protocol and type. + * + * @param protocol The protocol to use. + * @param type The type of socket to use. + */ + virtual int config(ProtocolFamily protocol, SockType type) = 0; + + /** + * Set blocking or non-blocking mode of the socket and a timeout on + * blocking socket operations. + * + * @param blocking true for blocking mode, false for non-blocking mode. + * @param timeout timeout in ms [Default: (1500)ms]. + */ + virtual void setBlocking(bool blocking, unsigned int timeout=1500) = 0; + + /* + "options" functions here? Not familiar with this, need to discuss + */ + + /** + * Close the socket + */ + virtual void close(); };