Implementation of the NetworkSocketAPI for LWIP
Dependencies: lwip-eth lwip-sys lwip
Dependents: HelloLWIPInterface HelloLWIPInterfaceNonBlocking LWIPInterfaceTests SimpleHTTPExample ... more
Diff: LWIPInterface.h
- Revision:
- 13:57d9e1721826
- Parent:
- 12:899403b675fe
- Child:
- 15:0d8d1dafe064
--- a/LWIPInterface.h Tue Apr 05 19:20:42 2016 +0000 +++ b/LWIPInterface.h Tue Apr 05 15:29:20 2016 -0500 @@ -14,8 +14,7 @@ * limitations under the License. */ -#if 0 -//#ifndef LWIP_INTERFACE_H +#ifndef LWIP_INTERFACE_H #define LWIP_INTERFACE_H #include "EthernetInterface.h" @@ -29,56 +28,37 @@ class LWIPInterface : public EthernetInterface { public: - virtual ~NetworkInterface() {}; + /** Start the interface + * @return 0 on success, negative on failure + */ + virtual int connect(); + + /** Stop the interface + * @return 0 on success, negative on failure + */ + virtual int disconnect(); /** Get the internally stored IP address /return IP address of the interface or null if not yet connected */ - virtual const char *get_ip_address() = 0; + virtual const char *get_ip_address(); /** Get the internally stored MAC address /return MAC address of the interface */ - virtual const char *get_mac_address() = 0; - - /** Get the current status of the interface - /return true if connected - */ - virtual bool is_connected() { - return get_ip_address() != NULL; - } - - /** Looks up the specified host's IP address - /param name Hostname to lookup - /param dest Destination for IP address, must have space for SocketAddress::IP_SIZE - /return 0 on success, negative on failure - */ - virtual int gethostbyname(const char *name, char *dest); + virtual const char *get_mac_address(); protected: - friend class Socket; - friend class UDPSocket; - friend class TCPSocket; - friend class TCPServer; - - /** Enum of socket protocols - /enum protocol_t - */ - enum protocol_t { - TCP, /*!< Socket is of TCP type */ - UDP, /*!< Socket is of UDP type */ - }; - /** Create a socket /param proto The type of socket to open, TCP or UDP /return The alocated socket or null on failure */ - virtual void *socket_create(protocol_t proto) = 0; + virtual void *socket_create(protocol_t proto); /** Destroy a socket /param socket Previously allocated socket */ - virtual void socket_destroy(void *handle) = 0; + virtual void socket_destroy(void *handle); /** Set socket options \param handle Socket handle @@ -87,7 +67,7 @@ \param optlen Length of the option value \return 0 on success, negative on failure */ - virtual int socket_set_option(void *handle, int optname, const void *optval, unsigned int optlen) = 0; + virtual int socket_set_option(void *handle, int optname, const void *optval, unsigned int optlen); /** Get socket options \param handle Socket handle @@ -96,14 +76,14 @@ \param optlen Length of the option value \return 0 on success, negative on failure */ - virtual int socket_get_option(void *handle, int optname, void *optval, unsigned int *optlen) = 0; + virtual int socket_get_option(void *handle, int optname, void *optval, unsigned int *optlen); /** Bind a server socket to a specific port \param handle Socket handle \param port The port to listen for incoming connections on \return 0 on success, negative on failure. */ - virtual int socket_bind(void *handle, int port) = 0; + virtual int socket_bind(void *handle, int port); /** Start listening for incoming connections \param handle Socket handle @@ -111,20 +91,20 @@ one time [Default: 1] \return 0 on success, negative on failure */ - virtual int socket_listen(void *handle, int backlog) = 0; + virtual int socket_listen(void *handle, int backlog); /** Connects this TCP socket to the server \param handle Socket handle \param address SocketAddress to connect to \return 0 on success, negative on failure */ - virtual int socket_connect(void *handle, const SocketAddress &address) = 0; + virtual int socket_connect(void *handle, const SocketAddress &address); /** Check if the socket is connected \param handle Socket handle \return true if connected, false otherwise */ - virtual bool socket_is_connected(void *handle) = 0; + virtual bool socket_is_connected(void *handle); /** Accept a new connection. \param handle Socket handle @@ -133,7 +113,7 @@ \note This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT */ - virtual int socket_accept(void *handle, void **connection) = 0; + virtual int socket_accept(void *handle, void **connection); /** Send data to the remote host \param handle Socket handle @@ -143,7 +123,7 @@ \note This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT */ - virtual int socket_send(void *handle, const void *data, unsigned size) = 0; + virtual int socket_send(void *handle, const void *data, unsigned size); /** Receive data from the remote host \param handle Socket handle @@ -153,7 +133,7 @@ \note This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT */ - virtual int socket_recv(void *handle, void *data, unsigned size) = 0; + virtual int socket_recv(void *handle, void *data, unsigned size); /** Send a packet to a remote endpoint \param handle Socket handle @@ -164,7 +144,7 @@ \note This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT */ - virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size) = 0; + virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size); /** Receive a packet from a remote endpoint \param handle Socket handle @@ -177,13 +157,13 @@ \note This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT */ - virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size) = 0; + virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size); /** 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, bool shutdown); /** Register a callback on when a new connection is ready \param handle Socket handle @@ -191,7 +171,7 @@ interrupt context. \param id Argument to pass to callback */ - virtual void socket_attach_accept(void *handle, void (*callback)(void *), void *id) = 0; + virtual void socket_attach_accept(void *handle, void (*callback)(void *), void *id); /** Register a callback on when send is ready \param handle Socket handle @@ -199,7 +179,7 @@ interrupt context. \param id Argument to pass to callback */ - virtual void socket_attach_send(void *handle, void (*callback)(void *), void *id) = 0; + virtual void socket_attach_send(void *handle, void (*callback)(void *), void *id); /** Register a callback on when recv is ready \param handle Socket handle @@ -207,7 +187,7 @@ interrupt context. \param id Argument to pass to callback */ - virtual void socket_attach_recv(void *handle, void (*callback)(void *), void *id) = 0; + virtual void socket_attach_recv(void *handle, void (*callback)(void *), void *id); }; #endif