NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
Diff: Socket.cpp
- Branch:
- api-changes
- Revision:
- 30:3cc78f5db99d
- Parent:
- 29:7bcec3189a93
- Child:
- 31:7f15b95f2a1d
--- 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); }