NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
Revision 30:3cc78f5db99d, committed 2016-02-22
- Comitter:
- geky
- Date:
- Mon Feb 22 21:03:38 2016 +0000
- Branch:
- api-changes
- Parent:
- 29:7bcec3189a93
- Child:
- 31:7f15b95f2a1d
- Commit message:
- Standardized formatting
Changed in this revision
--- a/NetworkInterface.cpp Mon Feb 22 20:58:50 2016 +0000 +++ b/NetworkInterface.cpp Mon Feb 22 21:03:38 2016 +0000 @@ -17,37 +17,45 @@ #include "NetworkInterface.h" #include <string.h> -NetworkInterface::NetworkInterface() { +NetworkInterface::NetworkInterface() +{ memset(_ip_address, 0, SOCK_IP_SIZE); memset(_network_mask, 0, SOCK_IP_SIZE); memset(_gateway, 0, SOCK_IP_SIZE); } -void NetworkInterface::setIPAddress(const char *ip) { +void NetworkInterface::setIPAddress(const char *ip) +{ strcpy(_ip_address, ip); } -void NetworkInterface::setNetworkMask(const char *mask) { +void NetworkInterface::setNetworkMask(const char *mask) +{ strcpy(_network_mask, mask); } -void NetworkInterface::setGateway(const char *gateway) { +void NetworkInterface::setGateway(const char *gateway) +{ strcpy(_gateway, gateway); } -const char *NetworkInterface::getIPAddress() { +const char *NetworkInterface::getIPAddress() +{ return _ip_address; } -const char *NetworkInterface::getNetworkMask() { +const char *NetworkInterface::getNetworkMask() +{ return _network_mask; } -const char *NetworkInterface::getGateway() { +const char *NetworkInterface::getGateway() +{ return _gateway; } -bool NetworkInterface::isConnected() { +bool NetworkInterface::isConnected() +{ return getIPAddress() != 0; }
--- a/NetworkInterface.h Mon Feb 22 20:58:50 2016 +0000 +++ b/NetworkInterface.h Mon Feb 22 21:03:38 2016 +0000 @@ -86,7 +86,7 @@ * @return The allocated socket */ virtual SocketInterface *createSocket(socket_protocol_t proto) = 0; - + /** Internally destroy a socket * @param socket An allocated SocketInterface * @returns 0 on success
--- a/Socket.cpp Mon Feb 22 20:58:50 2016 +0000 +++ b/Socket.cpp Mon Feb 22 21:03:38 2016 +0000 @@ -18,21 +18,24 @@ #include <string.h> Socket::Socket(NetworkInterface *iface, socket_protocol_t proto) - : _iface(iface) - , _proto(proto) - , _socket(0) { + : _iface(iface) + , _proto(proto) + , _socket(0) +{ memset(_ip_address, 0, SOCK_IP_SIZE); _port = 0; } -Socket::~Socket() { +Socket::~Socket() +{ if (_socket) { _iface->destroySocket(_socket); } } -SocketInterface *Socket::_get_socket() { +SocketInterface *Socket::_get_socket() +{ if (!_socket) { _socket = _iface->createSocket(_proto); @@ -48,7 +51,8 @@ return _socket; } -int32_t Socket::setURL(const char *url, uint16_t port) { +int32_t Socket::setURL(const char *url, uint16_t port) +{ SocketInterface *s = _get_socket(); if (!s) return -2; @@ -62,7 +66,8 @@ return 0; } -void Socket::setIPAddress(const char *ip, uint16_t port) { +void Socket::setIPAddress(const char *ip, uint16_t port) +{ strcpy(_ip_address, ip); if (_socket) { @@ -74,7 +79,8 @@ } } -void Socket::setPort(uint16_t port) { +void Socket::setPort(uint16_t port) +{ _port = port; if (_socket) { @@ -82,23 +88,27 @@ } } -const char *Socket::getIPAddress() const { +const char *Socket::getIPAddress() const +{ return _ip_address; } -uint16_t Socket::getPort() const { +uint16_t Socket::getPort() const +{ return _port; } -int32_t Socket::send(const void *data, uint32_t len, uint32_t timeout_ms) { +int32_t Socket::send(const void *data, uint32_t len, uint32_t timeout_ms) +{ SocketInterface *s = _get_socket(); - if (!s) return -2; - return s->send(data, len, timeout_ms); + if (!s) return -2; + return s->send(data, len, timeout_ms); } -int32_t Socket::recv(void *data, uint32_t len, uint32_t timeout_ms) { +int32_t Socket::recv(void *data, uint32_t len, uint32_t timeout_ms) +{ SocketInterface *s = _get_socket(); - if (!s) return -2; - return s->recv(data, len, timeout_ms); + if (!s) return -2; + return s->recv(data, len, timeout_ms); }
--- a/TCPSocket.cpp Mon Feb 22 20:58:50 2016 +0000 +++ b/TCPSocket.cpp Mon Feb 22 21:03:38 2016 +0000 @@ -17,16 +17,19 @@ #include "TCPSocket.h" TCPSocket::TCPSocket(NetworkInterface *iface) - : Socket(iface, SOCK_TCP) { + : Socket(iface, SOCK_TCP) +{ } -int32_t TCPSocket::open() { +int32_t TCPSocket::open() +{ SocketInterface *s = _get_socket(); if (!s) return -2; return s->close(); } -int32_t TCPSocket::close() { +int32_t TCPSocket::close() +{ SocketInterface *s = _get_socket(); if (!s) return -2; return s->close();
--- a/UDPSocket.cpp Mon Feb 22 20:58:50 2016 +0000 +++ b/UDPSocket.cpp Mon Feb 22 21:03:38 2016 +0000 @@ -17,6 +17,7 @@ #include "UDPSocket.h" UDPSocket::UDPSocket(NetworkInterface *iface) - : Socket(iface, SOCK_UDP) { + : Socket(iface, SOCK_UDP) +{ }
--- a/WiFiInterface.h Mon Feb 22 20:58:50 2016 +0000 +++ b/WiFiInterface.h Mon Feb 22 21:03:38 2016 +0000 @@ -43,10 +43,10 @@ * @return 0 on success */ virtual int32_t connect( - const char *ssid, - const char *pass, - wifi_security_t security = WI_NONE, - uint32_t timeout_ms = 15000) = 0; + const char *ssid, + const char *pass, + wifi_security_t security = WI_NONE, + uint32_t timeout_ms = 15000) = 0; /** Stop the interface * @return 0 on success